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

Show stockart errors #658

Merged
merged 1 commit into from
Jan 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion app/directives/tc-form-stockart/tc-form-stockart.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@
},
link: function(scope, element, attrs, formController) {
scope.submissionForm = formController;

},
controller: ['$scope', function($scope) {
var stockartId = 0;
var emptyStockart = {
description: '',
sourceUrl: '',
fileNumber: ''
fileNumber: '',
isPhotoDescriptionRequired: false,
isPhotoURLRequired: false,
isFileNumberRequired: false
};

$scope.urlRegEx = new RegExp(/^(http(s?):\/\/)?(www\.)?[a-zA-Z0-9\.\-\_]+(\.[a-zA-Z]{2,3})+(\/[a-zA-Z0-9\_\-\s\.\/\?\%\#\&\=]*)?$/);
Expand Down Expand Up @@ -50,6 +54,33 @@
return !stockart.description || !stockart.sourceUrl || !stockart.fileNumber;
});
}

$scope.showMandatoryMessage = function(inputValue, inputName) {
var id = inputName.slice(-1);

var stockartSection = $scope.formStockarts[id];

var stockartDescription = stockartSection.description;
var stockartSourceUrl = stockartSection.sourceUrl;
var stockartFileNumber = stockartSection.fileNumber;

if (!stockartDescription && !stockartSourceUrl && !stockartFileNumber) {
// All fields empty so required should be false
stockartSection.isPhotoDescriptionRequired = false;
stockartSection.isPhotoURLRequired = false;
stockartSection.isFileNumberRequired = false;
} else if (stockartDescription && stockartSourceUrl && stockartFileNumber) {
// All fields filled out, so required should be false
stockartSection.isPhotoDescriptionRequired = false;
stockartSection.isPhotoURLRequired = false;
stockartSection.isFileNumberRequired = false;
} else {
// Fields are not completely filled out or completely blank so setting required to true
stockartSection.isPhotoDescriptionRequired = true;
stockartSection.isPhotoURLRequired = true;
stockartSection.isFileNumberRequired = true;
}
}
}]
}
}
Expand Down
19 changes: 14 additions & 5 deletions app/directives/tc-form-stockart/tc-form-stockart.jade
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,39 @@

tc-input.fieldset__input(
label-text="Photo Description",
asterisk-text="Field can't be empty",
placeholder="A picture of a girl",
input-value="stockart.description",
input-name="photoDescription{{stockartId}}",
maxlength="100"
input-required="formStockarts[stockartId].isPhotoDescriptionRequired",
maxlength="100",
on-input-change="showMandatoryMessage(inputValue, inputName)"
)

tc-input.fieldset__input(
label-text="Photo URL",
asterisk-text="Field can't be empty",
placeholder="www.istockphoto.com",
input-value="stockart.sourceUrl",
input-name="photoURL{{stockartId}}",
input-required="formStockarts[stockartId].isPhotoURLRequired",
input-pattern="urlRegEx",
maxlength="100"
maxlength="100",
on-input-change="showMandatoryMessage(inputValue, inputName)"
)

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

tc-input.fieldset__input(
label-text="File Number",
asterisk-text="Field can't be empty",
placeholder="u2434312",
input-value="stockart.fileNumber",
input-name="fileNumber{{stockartId}}",
maxlength="50"
input-required="formStockarts[stockartId].isFileNumberRequired",
maxlength="50",
on-input-change="showMandatoryMessage(inputValue, inputName)"
)

button.fieldset__button.tc-btn.tc-btn-s(type="button", ng-click="createAdditionalStockartFieldset()", ng-disabled="isButtonDisabled()") + Add Stock Photo
10 changes: 9 additions & 1 deletion app/directives/tc-input/tc-input.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
templateUrl: 'directives/tc-input/tc-input.html',
scope: {
labelText: '@',
asteriskText: '@',
placeholder: '@',
inputValue: '=',
inputName: '@',
Expand All @@ -17,7 +18,8 @@
inputRequired: '=',
inputDisabled: '=',
maxlength: '@',
updateValueOnBlur: '&?'
updateValueOnBlur: '&?',
onInputChange: '&?'
},
link: function(scope, element, attrs) {
var input = $(element[0]).find('input');
Expand All @@ -33,6 +35,12 @@
scope.$apply();
});
}

if (scope.onInputChange) {
scope.$watch('inputValue', function(newValue, oldValue) {
scope.onInputChange({inputValue: scope.inputValue, inputName: scope.inputName});
});
}
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion app/directives/tc-input/tc-input.jade
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
label.tc-label {{labelText}}

p.tc-label__asterisk(ng-if="inputRequired") #[span *]{{asteriskText}}

input(
name="{{inputName}}",
type="{{inputType}}",
Expand All @@ -8,5 +10,6 @@ input(
ng-pattern="inputPattern",
ng-required="inputRequired",
ng-disabled="inputDisabled",
maxlength="{{maxlength}}"
maxlength="{{maxlength}}",
ng-change="onChange()"
)
2 changes: 1 addition & 1 deletion app/index.jade
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ html
script(src='../bower_components/appirio-tech-ng-ui-components/dist/main.js')
script(src='../bower_components/d3/d3.js')
script(src='../bower_components/jstzdetect/jstz.min.js')
script(src='../bower_components/lodash/lodash.js')
script(src='../bower_components/ng-busy/build/angular-busy.js')
script(src='../bower_components/ng-notifications-bar/dist/ngNotificationsBar.min.js')
script(src='../bower_components/ngDialog/js/ngDialog.js')
script(src='../bower_components/lodash/lodash.js')
script(src='../bower_components/restangular/dist/restangular.js')
script(src='../bower_components/angular-touch/angular-touch.js')
script(src='../bower_components/angular-carousel/dist/angular-carousel.js')
Expand Down
7 changes: 5 additions & 2 deletions app/submissions/submit-file/submit-file.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

function SubmitFileController($scope, $stateParams, $log, UserService, SubmissionsService, challengeToSubmitTo) {
var vm = this;
$log = $log.getInstance("SubmitFileController");
$log = $log.getInstance('SubmitFileController');
var files = {};
var fileUploadProgress = {};
vm.urlRegEx = new RegExp(/^(http(s?):\/\/)?(www\.)?[a-zA-Z0-9\.\-\_]+(\.[a-zA-Z]{2,3})+(\/[a-zA-Z0-9\_\-\s\.\/\?\%\#\&\=]*)?$/);
Expand Down Expand Up @@ -37,7 +37,10 @@
id: 1,
description: '',
sourceUrl: '',
fileNumber: ''
fileNumber: '',
isPhotoDescriptionRequired: false,
isPhotoURLRequired: false,
isFileNumberRequired: false
}
};
vm.submissionForm = {
Expand Down