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

Remove stockart description and file number fields #792

Merged
merged 1 commit into from
May 5, 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
38 changes: 2 additions & 36 deletions app/directives/tc-form-stockart/tc-form-stockart.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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
}
}
}]
}
}
Expand Down
29 changes: 1 addition & 28 deletions app/directives/tc-form-stockart/tc-form-stockart.jade
Original file line number Diff line number Diff line change
@@ -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
105 changes: 9 additions & 96 deletions app/directives/tc-form-stockart/tc-form-stockart.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand All @@ -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
Expand All @@ -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
})
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
34 changes: 5 additions & 29 deletions app/submissions/submit-design-files/submit-design-files.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down