diff --git a/app/directives/tc-form-stockart/tc-form-stockart.directive.js b/app/directives/tc-form-stockart/tc-form-stockart.directive.js index 75f25e7e1..2c5daf8f5 100644 --- a/app/directives/tc-form-stockart/tc-form-stockart.directive.js +++ b/app/directives/tc-form-stockart/tc-form-stockart.directive.js @@ -21,12 +21,7 @@ import _ from 'lodash' controller: ['$scope', function($scope) { var stockartId = 0 var emptyStockart = { - description: '', - sourceUrl: '', - fileNumber: '', - isPhotoDescriptionRequired: false, - isPhotoURLRequired: false, - isFileNumberRequired: false + sourceUrl: '' } // Initialize stockart form data @@ -45,9 +40,7 @@ import _ from 'lodash' // If only one stockart fieldset is there, just reset the values // so that ng-repeat doesn't refresh and there is no UI flickering if (Object.keys($scope.formStockarts).length === 1) { - $scope.submissionForm['photoDescription' + index].$setPristine() $scope.submissionForm['photoURL' + index].$setPristine() - $scope.submissionForm['fileNumber' + index].$setPristine() $scope.formStockarts[index] = angular.copy(emptyStockart) } else { @@ -57,36 +50,9 @@ import _ from 'lodash' $scope.isButtonDisabled = function() { return _.some($scope.formStockarts, function(stockart) { - return !stockart.description || !stockart.sourceUrl || !stockart.fileNumber + return !stockart.sourceUrl }) } - - $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 - } - } }] } } diff --git a/app/directives/tc-form-stockart/tc-form-stockart.jade b/app/directives/tc-form-stockart/tc-form-stockart.jade index 7f10fb425..f561d1f15 100644 --- a/app/directives/tc-form-stockart/tc-form-stockart.jade +++ b/app/directives/tc-form-stockart/tc-form-stockart.jade @@ -1,44 +1,17 @@ .fieldset(ng-repeat="(stockartId, stockart) in formStockarts") button.clean.remove-section(type="button", ng-click="deleteStockartFieldset(stockartId)") - tc-input.fieldset__input( - label-text="Photo Description", - asterisk-text="Field can't be empty", - show-asterisk-text="true", - placeholder="A picture of a girl", - input-value="stockart.description", - input-name="photoDescription{{stockartId}}", - 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", - show-asterisk-text="true", placeholder="www.istockphoto.com", input-value="stockart.sourceUrl", input-name="photoURL{{stockartId}}", input-required="formStockarts[stockartId].isPhotoURLRequired", input-pattern="urlRegEx", - maxlength="250", - on-input-change="showMandatoryMessage(inputValue, inputName)" + maxlength="250" ) .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", - show-asterisk-text="true", - placeholder="u2434312", - input-value="stockart.fileNumber", - input-name="fileNumber{{stockartId}}", - 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 diff --git a/app/directives/tc-form-stockart/tc-form-stockart.spec.js b/app/directives/tc-form-stockart/tc-form-stockart.spec.js index d0be7a02c..8b92a6d46 100644 --- a/app/directives/tc-form-stockart/tc-form-stockart.spec.js +++ b/app/directives/tc-form-stockart/tc-form-stockart.spec.js @@ -29,12 +29,7 @@ describe('Topcoder Form Stockart Directive', function() { var initialStockart = isolateScope.formStockarts[0] expect(initialStockart.id).to.equal(0) - expect(initialStockart.description).to.equal('') expect(initialStockart.sourceUrl).to.equal('') - expect(initialStockart.fileNumber).to.equal('') - expect(initialStockart.isPhotoDescriptionRequired).to.equal(false) - expect(initialStockart.isPhotoURLRequired).to.equal(false) - expect(initialStockart.isFileNumberRequired).to.equal(false) }) it('a regular expression', function() { @@ -79,21 +74,21 @@ describe('Topcoder Form Stockart Directive', function() { it('resets the stockart fieldset when it\'s the only one', function() { var stockart = isolateScope.formStockarts[0] - expect(stockart.description).to.equal('') + expect(stockart.sourceUrl).to.equal('') - stockart.description = 'a funny cat picture' + stockart.sourceUrl = 'www.myURL.com' scope.$digest() - expect(stockart.description).to.equal('a funny cat picture') + expect(stockart.sourceUrl).to.equal('www.myURL.com') isolateScope.deleteStockartFieldset(0) scope.$digest() - expect(isolateScope.formStockarts[0].description).to.equal('') + expect(isolateScope.formStockarts[0].sourceUrl).to.equal('') }) }) - describe('isButtonDisabled', function() { + describe.only('isButtonDisabled', function() { var button beforeEach(function() { @@ -108,37 +103,20 @@ describe('Topcoder Form Stockart Directive', function() { expect(button.disabled).to.be.true }) - it('disables the button when 1 field is filled out', function() { - isolateScope.formStockarts[0].description = 'test description' - scope.$digest() - - expect(button.disabled).to.be.true - }) - - it('disables the button when 2 fields are filled out', function() { - isolateScope.formStockarts[0].description = 'test description' - isolateScope.formStockarts[0].sourceUrl = 'url' - scope.$digest() - + it('enables the button when the url field is filled out', function() { expect(button.disabled).to.be.true - }) - it('enables the button when all fields are filled out', function() { - isolateScope.formStockarts[0].description = 'test description' isolateScope.formStockarts[0].sourceUrl = 'url' - isolateScope.formStockarts[0].fileNumber = '123' scope.$digest() expect(button.disabled).to.be.false }) - it('disables the button when any field in any fieldset is empty', function() { + it('disables the button when any url field in any fieldset is empty', function() { expect(button.disabled).to.be.true // Fill out first fieldset - isolateScope.formStockarts[0].description = 'test description' isolateScope.formStockarts[0].sourceUrl = 'url.com' - isolateScope.formStockarts[0].fileNumber = '123' scope.$digest() expect(button.disabled).to.be.false @@ -149,81 +127,16 @@ describe('Topcoder Form Stockart Directive', function() { expect(button.disabled).to.be.true // Fill out second fieldset - isolateScope.formStockarts[1].description = 'test description2' isolateScope.formStockarts[1].sourceUrl = 'url2.com' - isolateScope.formStockarts[1].fileNumber = '1232' scope.$digest() expect(button.disabled).to.be.false - // Empty a field in the first fieldset - isolateScope.formStockarts[0].fileNumber = '' + // Empty the field in the first fieldset + isolateScope.formStockarts[0].sourceUrl = '' scope.$digest() expect(button.disabled).to.be.true }) }) - - describe('showMandatoryMessage', function() { - describe('sets the stockart required properties to false when all fields are', function() { - var stockart - - beforeEach(function() { - stockart = isolateScope.formStockarts[0] - stockart.description = 'test description' - stockart.sourceUrl = 'url.com' - stockart.fileNumber = '123' - scope.$digest() - }) - - afterEach(function() { - stockart = undefined - }) - - it('filled out', function() { - expect(stockart.isPhotoDescriptionRequired).to.be.false - expect(stockart.isPhotoURLRequired).to.be.false - expect(stockart.isFileNumberRequired).to.be.false - }) - - it('empty', function() { - // Reset stockart fields - stockart.description = '' - stockart.sourceUrl = '' - stockart.fileNumber = '' - scope.$digest() - - expect(stockart.isPhotoDescriptionRequired).to.be.false - expect(stockart.isPhotoURLRequired).to.be.false - expect(stockart.isFileNumberRequired).to.be.false - }) - }) - - - describe('sets the stockart required properties to false when all fields are', function() { - var stockart - - beforeEach(function() { - stockart = isolateScope.formStockarts[0] - stockart.description = 'test description' - stockart.sourceUrl = 'url.com' - stockart.fileNumber = '123' - scope.$digest() - }) - - afterEach(function() { - stockart = undefined - }) - - it('sets the stockart required properties to true if any field is blank', function() { - // Reset stockart fields - stockart.description = '' - scope.$digest() - - expect(stockart.isPhotoDescriptionRequired).to.be.true - expect(stockart.isPhotoURLRequired).to.be.true - expect(stockart.isFileNumberRequired).to.be.true - }) - }) - }) }) diff --git a/app/submissions/submit-design-files/submit-design-files.controller.js b/app/submissions/submit-design-files/submit-design-files.controller.js index 9825f3250..31c85a2c1 100644 --- a/app/submissions/submit-design-files/submit-design-files.controller.js +++ b/app/submissions/submit-design-files/submit-design-files.controller.js @@ -131,11 +131,8 @@ import _ from 'lodash' // Process stock art var processedStockarts = _.reduce(vm.formStockarts, function(compiledStockarts, formStockart) { - if (formStockart.description) { + if (formStockart.sourceUrl) { delete formStockart.id - delete formStockart.isPhotoDescriptionRequired - delete formStockart.isPhotoURLRequired - delete formStockart.isFileNumberRequired compiledStockarts.push(formStockart) } diff --git a/app/submissions/submit-design-files/submit-design-files.spec.js b/app/submissions/submit-design-files/submit-design-files.spec.js index 78ce53e30..42766baee 100644 --- a/app/submissions/submit-design-files/submit-design-files.spec.js +++ b/app/submissions/submit-design-files/submit-design-files.spec.js @@ -196,38 +196,14 @@ describe('Submit Design Files Controller', function() { expect(vm.submissionsBody.data.stockArts).to.deep.equal([]) }) - it('removes the required properties and id from each stockart', function() { + it('removes the id from each stockart', function() { vm.formStockarts = [ - { - id: 0, - description: 'first stockart', - sourceUrl: 'url.com', - fileNumber: '123', - isPhotoDescriptionRequired: false, - isPhotoURLRequired: false, - isFileNumberRequired: false - }, - { - id: 1, - description: 'second stockart', - sourceUrl: 'url2.com', - fileNumber: '234', - isPhotoDescriptionRequired: false, - isPhotoURLRequired: false, - isFileNumberRequired: false - } + { id: 0, sourceUrl: 'url.com' }, + { id: 1, sourceUrl: 'url2.com' } ] var processedStockart = [ - { - description: 'first stockart', - sourceUrl: 'url.com', - fileNumber: '123' - }, - { - description: 'second stockart', - sourceUrl: 'url2.com', - fileNumber: '234' - } + { sourceUrl: 'url.com' }, + { sourceUrl: 'url2.com' } ] scope.$digest()