Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 0648d30

Browse files
author
Jenkins Continuous Integration Server
committed
Merge commit 'c7b122112f452762274d9447b65eb218633430be' into HEAD
2 parents 20bf930 + c7b1221 commit 0648d30

File tree

6 files changed

+65
-11
lines changed

6 files changed

+65
-11
lines changed

app/directives/tc-form-stockart/tc-form-stockart.directive.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@
1313
},
1414
link: function(scope, element, attrs, formController) {
1515
scope.submissionForm = formController;
16+
1617
},
1718
controller: ['$scope', function($scope) {
1819
var stockartId = 0;
1920
var emptyStockart = {
2021
description: '',
2122
sourceUrl: '',
22-
fileNumber: ''
23+
fileNumber: '',
24+
isPhotoDescriptionRequired: false,
25+
isPhotoURLRequired: false,
26+
isFileNumberRequired: false
2327
};
2428

2529
$scope.urlRegEx = new RegExp(/^(http(s?):\/\/)?(www\.)?[a-zA-Z0-9\.\-\_]+(\.[a-zA-Z]{2,3})+(\/[a-zA-Z0-9\_\-\s\.\/\?\%\#\&\=]*)?$/);
@@ -50,6 +54,33 @@
5054
return !stockart.description || !stockart.sourceUrl || !stockart.fileNumber;
5155
});
5256
}
57+
58+
$scope.showMandatoryMessage = function(inputValue, inputName) {
59+
var id = inputName.slice(-1);
60+
61+
var stockartSection = $scope.formStockarts[id];
62+
63+
var stockartDescription = stockartSection.description;
64+
var stockartSourceUrl = stockartSection.sourceUrl;
65+
var stockartFileNumber = stockartSection.fileNumber;
66+
67+
if (!stockartDescription && !stockartSourceUrl && !stockartFileNumber) {
68+
// All fields empty so required should be false
69+
stockartSection.isPhotoDescriptionRequired = false;
70+
stockartSection.isPhotoURLRequired = false;
71+
stockartSection.isFileNumberRequired = false;
72+
} else if (stockartDescription && stockartSourceUrl && stockartFileNumber) {
73+
// All fields filled out, so required should be false
74+
stockartSection.isPhotoDescriptionRequired = false;
75+
stockartSection.isPhotoURLRequired = false;
76+
stockartSection.isFileNumberRequired = false;
77+
} else {
78+
// Fields are not completely filled out or completely blank so setting required to true
79+
stockartSection.isPhotoDescriptionRequired = true;
80+
stockartSection.isPhotoURLRequired = true;
81+
stockartSection.isFileNumberRequired = true;
82+
}
83+
}
5384
}]
5485
}
5586
}

app/directives/tc-form-stockart/tc-form-stockart.jade

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,39 @@
33

44
tc-input.fieldset__input(
55
label-text="Photo Description",
6+
asterisk-text="Field can't be empty",
67
placeholder="A picture of a girl",
78
input-value="stockart.description",
89
input-name="photoDescription{{stockartId}}",
9-
maxlength="100"
10+
input-required="formStockarts[stockartId].isPhotoDescriptionRequired",
11+
maxlength="100",
12+
on-input-change="showMandatoryMessage(inputValue, inputName)"
1013
)
1114

1215
tc-input.fieldset__input(
1316
label-text="Photo URL",
17+
asterisk-text="Field can't be empty",
1418
placeholder="www.istockphoto.com",
1519
input-value="stockart.sourceUrl",
1620
input-name="photoURL{{stockartId}}",
21+
input-required="formStockarts[stockartId].isPhotoURLRequired",
1722
input-pattern="urlRegEx",
18-
maxlength="100"
23+
maxlength="100",
24+
on-input-change="showMandatoryMessage(inputValue, inputName)"
1925
)
2026

21-
.tc-error-messages(ng-show="submissionForm['photoURL' + stockartId].$dirty && submissionForm['photoURL' + stockartId].$invalid")
22-
p(ng-show="submissionForm['photoURL' + stockartId].$error.pattern") Please enter a valid url.
27+
.tc-error-messages(ng-show="submissionForm['photoURL' + stockartId].$dirty && submissionForm['photoURL' + stockartId].$invalid && submissionForm['photoURL' + stockartId].$error.pattern")
28+
p Please enter a valid url.
2329

2430
tc-input.fieldset__input(
2531
label-text="File Number",
32+
asterisk-text="Field can't be empty",
2633
placeholder="u2434312",
2734
input-value="stockart.fileNumber",
2835
input-name="fileNumber{{stockartId}}",
29-
maxlength="50"
36+
input-required="formStockarts[stockartId].isFileNumberRequired",
37+
maxlength="50",
38+
on-input-change="showMandatoryMessage(inputValue, inputName)"
3039
)
3140

3241
button.fieldset__button.tc-btn.tc-btn-s(type="button", ng-click="createAdditionalStockartFieldset()", ng-disabled="isButtonDisabled()") + Add Stock Photo

app/directives/tc-input/tc-input.directive.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
templateUrl: 'directives/tc-input/tc-input.html',
1010
scope: {
1111
labelText: '@',
12+
asteriskText: '@',
1213
placeholder: '@',
1314
inputValue: '=',
1415
inputName: '@',
@@ -17,7 +18,8 @@
1718
inputRequired: '=',
1819
inputDisabled: '=',
1920
maxlength: '@',
20-
updateValueOnBlur: '&?'
21+
updateValueOnBlur: '&?',
22+
onInputChange: '&?'
2123
},
2224
link: function(scope, element, attrs) {
2325
var input = $(element[0]).find('input');
@@ -33,6 +35,12 @@
3335
scope.$apply();
3436
});
3537
}
38+
39+
if (scope.onInputChange) {
40+
scope.$watch('inputValue', function(newValue, oldValue) {
41+
scope.onInputChange({inputValue: scope.inputValue, inputName: scope.inputName});
42+
});
43+
}
3644
}
3745
}
3846
}

app/directives/tc-input/tc-input.jade

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
label.tc-label {{labelText}}
22

3+
p.tc-label__asterisk(ng-if="inputRequired") #[span *]{{asteriskText}}
4+
35
input(
46
name="{{inputName}}",
57
type="{{inputType}}",
@@ -8,5 +10,6 @@ input(
810
ng-pattern="inputPattern",
911
ng-required="inputRequired",
1012
ng-disabled="inputDisabled",
11-
maxlength="{{maxlength}}"
13+
maxlength="{{maxlength}}",
14+
ng-change="onChange()"
1215
)

app/index.jade

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,10 @@ html
164164
script(src='../bower_components/appirio-tech-ng-ui-components/dist/main.js')
165165
script(src='../bower_components/d3/d3.js')
166166
script(src='../bower_components/jstzdetect/jstz.min.js')
167+
script(src='../bower_components/lodash/lodash.js')
167168
script(src='../bower_components/ng-busy/build/angular-busy.js')
168169
script(src='../bower_components/ng-notifications-bar/dist/ngNotificationsBar.min.js')
169170
script(src='../bower_components/ngDialog/js/ngDialog.js')
170-
script(src='../bower_components/lodash/lodash.js')
171171
script(src='../bower_components/restangular/dist/restangular.js')
172172
script(src='../bower_components/angular-touch/angular-touch.js')
173173
script(src='../bower_components/angular-carousel/dist/angular-carousel.js')

app/submissions/submit-file/submit-file.controller.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
function SubmitFileController($scope, $stateParams, $log, UserService, SubmissionsService, challengeToSubmitTo) {
99
var vm = this;
10-
$log = $log.getInstance("SubmitFileController");
10+
$log = $log.getInstance('SubmitFileController');
1111
var files = {};
1212
var fileUploadProgress = {};
1313
vm.urlRegEx = new RegExp(/^(http(s?):\/\/)?(www\.)?[a-zA-Z0-9\.\-\_]+(\.[a-zA-Z]{2,3})+(\/[a-zA-Z0-9\_\-\s\.\/\?\%\#\&\=]*)?$/);
@@ -37,7 +37,10 @@
3737
id: 1,
3838
description: '',
3939
sourceUrl: '',
40-
fileNumber: ''
40+
fileNumber: '',
41+
isPhotoDescriptionRequired: false,
42+
isPhotoURLRequired: false,
43+
isFileNumberRequired: false
4144
}
4245
};
4346
vm.submissionForm = {

0 commit comments

Comments
 (0)