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

Commit d414b45

Browse files
committed
Merge pull request #792 from appirio-tech/stockart-field-update
Remove stockart description and file number fields
2 parents 212110a + fe4f84e commit d414b45

File tree

5 files changed

+18
-193
lines changed

5 files changed

+18
-193
lines changed

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

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,7 @@ import _ from 'lodash'
2121
controller: ['$scope', function($scope) {
2222
var stockartId = 0
2323
var emptyStockart = {
24-
description: '',
25-
sourceUrl: '',
26-
fileNumber: '',
27-
isPhotoDescriptionRequired: false,
28-
isPhotoURLRequired: false,
29-
isFileNumberRequired: false
24+
sourceUrl: ''
3025
}
3126

3227
// Initialize stockart form data
@@ -45,9 +40,7 @@ import _ from 'lodash'
4540
// If only one stockart fieldset is there, just reset the values
4641
// so that ng-repeat doesn't refresh and there is no UI flickering
4742
if (Object.keys($scope.formStockarts).length === 1) {
48-
$scope.submissionForm['photoDescription' + index].$setPristine()
4943
$scope.submissionForm['photoURL' + index].$setPristine()
50-
$scope.submissionForm['fileNumber' + index].$setPristine()
5144
$scope.formStockarts[index] = angular.copy(emptyStockart)
5245

5346
} else {
@@ -57,36 +50,9 @@ import _ from 'lodash'
5750

5851
$scope.isButtonDisabled = function() {
5952
return _.some($scope.formStockarts, function(stockart) {
60-
return !stockart.description || !stockart.sourceUrl || !stockart.fileNumber
53+
return !stockart.sourceUrl
6154
})
6255
}
63-
64-
$scope.showMandatoryMessage = function(inputValue, inputName) {
65-
var id = inputName.slice(-1)
66-
67-
var stockartSection = $scope.formStockarts[id]
68-
69-
var stockartDescription = stockartSection.description
70-
var stockartSourceUrl = stockartSection.sourceUrl
71-
var stockartFileNumber = stockartSection.fileNumber
72-
73-
if (!stockartDescription && !stockartSourceUrl && !stockartFileNumber) {
74-
// All fields empty so required should be false
75-
stockartSection.isPhotoDescriptionRequired = false
76-
stockartSection.isPhotoURLRequired = false
77-
stockartSection.isFileNumberRequired = false
78-
} else if (stockartDescription && stockartSourceUrl && stockartFileNumber) {
79-
// All fields filled out, so required should be false
80-
stockartSection.isPhotoDescriptionRequired = false
81-
stockartSection.isPhotoURLRequired = false
82-
stockartSection.isFileNumberRequired = false
83-
} else {
84-
// Fields are not completely filled out or completely blank so setting required to true
85-
stockartSection.isPhotoDescriptionRequired = true
86-
stockartSection.isPhotoURLRequired = true
87-
stockartSection.isFileNumberRequired = true
88-
}
89-
}
9056
}]
9157
}
9258
}
Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,17 @@
11
.fieldset(ng-repeat="(stockartId, stockart) in formStockarts")
22
button.clean.remove-section(type="button", ng-click="deleteStockartFieldset(stockartId)")
33

4-
tc-input.fieldset__input(
5-
label-text="Photo Description",
6-
asterisk-text="Field can't be empty",
7-
show-asterisk-text="true",
8-
placeholder="A picture of a girl",
9-
input-value="stockart.description",
10-
input-name="photoDescription{{stockartId}}",
11-
input-required="formStockarts[stockartId].isPhotoDescriptionRequired",
12-
maxlength="100",
13-
on-input-change="showMandatoryMessage(inputValue, inputName)"
14-
)
15-
164
tc-input.fieldset__input(
175
label-text="Photo URL",
18-
asterisk-text="Field can't be empty",
19-
show-asterisk-text="true",
206
placeholder="www.istockphoto.com",
217
input-value="stockart.sourceUrl",
228
input-name="photoURL{{stockartId}}",
239
input-required="formStockarts[stockartId].isPhotoURLRequired",
2410
input-pattern="urlRegEx",
25-
maxlength="250",
26-
on-input-change="showMandatoryMessage(inputValue, inputName)"
11+
maxlength="250"
2712
)
2813

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

32-
tc-input.fieldset__input(
33-
label-text="File Number",
34-
asterisk-text="Field can't be empty",
35-
show-asterisk-text="true",
36-
placeholder="u2434312",
37-
input-value="stockart.fileNumber",
38-
input-name="fileNumber{{stockartId}}",
39-
input-required="formStockarts[stockartId].isFileNumberRequired",
40-
maxlength="50",
41-
on-input-change="showMandatoryMessage(inputValue, inputName)"
42-
)
43-
4417
button.fieldset__button.tc-btn.tc-btn-s(type="button", ng-click="createAdditionalStockartFieldset()", ng-disabled="isButtonDisabled()") + Add Stock Photo

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

Lines changed: 9 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,7 @@ describe('Topcoder Form Stockart Directive', function() {
2929
var initialStockart = isolateScope.formStockarts[0]
3030

3131
expect(initialStockart.id).to.equal(0)
32-
expect(initialStockart.description).to.equal('')
3332
expect(initialStockart.sourceUrl).to.equal('')
34-
expect(initialStockart.fileNumber).to.equal('')
35-
expect(initialStockart.isPhotoDescriptionRequired).to.equal(false)
36-
expect(initialStockart.isPhotoURLRequired).to.equal(false)
37-
expect(initialStockart.isFileNumberRequired).to.equal(false)
3833
})
3934

4035
it('a regular expression', function() {
@@ -79,21 +74,21 @@ describe('Topcoder Form Stockart Directive', function() {
7974
it('resets the stockart fieldset when it\'s the only one', function() {
8075
var stockart = isolateScope.formStockarts[0]
8176

82-
expect(stockart.description).to.equal('')
77+
expect(stockart.sourceUrl).to.equal('')
8378

84-
stockart.description = 'a funny cat picture'
79+
stockart.sourceUrl = 'www.myURL.com'
8580
scope.$digest()
8681

87-
expect(stockart.description).to.equal('a funny cat picture')
82+
expect(stockart.sourceUrl).to.equal('www.myURL.com')
8883

8984
isolateScope.deleteStockartFieldset(0)
9085
scope.$digest()
9186

92-
expect(isolateScope.formStockarts[0].description).to.equal('')
87+
expect(isolateScope.formStockarts[0].sourceUrl).to.equal('')
9388
})
9489
})
9590

96-
describe('isButtonDisabled', function() {
91+
describe.only('isButtonDisabled', function() {
9792
var button
9893

9994
beforeEach(function() {
@@ -108,37 +103,20 @@ describe('Topcoder Form Stockart Directive', function() {
108103
expect(button.disabled).to.be.true
109104
})
110105

111-
it('disables the button when 1 field is filled out', function() {
112-
isolateScope.formStockarts[0].description = 'test description'
113-
scope.$digest()
114-
115-
expect(button.disabled).to.be.true
116-
})
117-
118-
it('disables the button when 2 fields are filled out', function() {
119-
isolateScope.formStockarts[0].description = 'test description'
120-
isolateScope.formStockarts[0].sourceUrl = 'url'
121-
scope.$digest()
122-
106+
it('enables the button when the url field is filled out', function() {
123107
expect(button.disabled).to.be.true
124-
})
125108

126-
it('enables the button when all fields are filled out', function() {
127-
isolateScope.formStockarts[0].description = 'test description'
128109
isolateScope.formStockarts[0].sourceUrl = 'url'
129-
isolateScope.formStockarts[0].fileNumber = '123'
130110
scope.$digest()
131111

132112
expect(button.disabled).to.be.false
133113
})
134114

135-
it('disables the button when any field in any fieldset is empty', function() {
115+
it('disables the button when any url field in any fieldset is empty', function() {
136116
expect(button.disabled).to.be.true
137117

138118
// Fill out first fieldset
139-
isolateScope.formStockarts[0].description = 'test description'
140119
isolateScope.formStockarts[0].sourceUrl = 'url.com'
141-
isolateScope.formStockarts[0].fileNumber = '123'
142120
scope.$digest()
143121

144122
expect(button.disabled).to.be.false
@@ -149,81 +127,16 @@ describe('Topcoder Form Stockart Directive', function() {
149127
expect(button.disabled).to.be.true
150128

151129
// Fill out second fieldset
152-
isolateScope.formStockarts[1].description = 'test description2'
153130
isolateScope.formStockarts[1].sourceUrl = 'url2.com'
154-
isolateScope.formStockarts[1].fileNumber = '1232'
155131
scope.$digest()
156132

157133
expect(button.disabled).to.be.false
158134

159-
// Empty a field in the first fieldset
160-
isolateScope.formStockarts[0].fileNumber = ''
135+
// Empty the field in the first fieldset
136+
isolateScope.formStockarts[0].sourceUrl = ''
161137
scope.$digest()
162138

163139
expect(button.disabled).to.be.true
164140
})
165141
})
166-
167-
describe('showMandatoryMessage', function() {
168-
describe('sets the stockart required properties to false when all fields are', function() {
169-
var stockart
170-
171-
beforeEach(function() {
172-
stockart = isolateScope.formStockarts[0]
173-
stockart.description = 'test description'
174-
stockart.sourceUrl = 'url.com'
175-
stockart.fileNumber = '123'
176-
scope.$digest()
177-
})
178-
179-
afterEach(function() {
180-
stockart = undefined
181-
})
182-
183-
it('filled out', function() {
184-
expect(stockart.isPhotoDescriptionRequired).to.be.false
185-
expect(stockart.isPhotoURLRequired).to.be.false
186-
expect(stockart.isFileNumberRequired).to.be.false
187-
})
188-
189-
it('empty', function() {
190-
// Reset stockart fields
191-
stockart.description = ''
192-
stockart.sourceUrl = ''
193-
stockart.fileNumber = ''
194-
scope.$digest()
195-
196-
expect(stockart.isPhotoDescriptionRequired).to.be.false
197-
expect(stockart.isPhotoURLRequired).to.be.false
198-
expect(stockart.isFileNumberRequired).to.be.false
199-
})
200-
})
201-
202-
203-
describe('sets the stockart required properties to false when all fields are', function() {
204-
var stockart
205-
206-
beforeEach(function() {
207-
stockart = isolateScope.formStockarts[0]
208-
stockart.description = 'test description'
209-
stockart.sourceUrl = 'url.com'
210-
stockart.fileNumber = '123'
211-
scope.$digest()
212-
})
213-
214-
afterEach(function() {
215-
stockart = undefined
216-
})
217-
218-
it('sets the stockart required properties to true if any field is blank', function() {
219-
// Reset stockart fields
220-
stockart.description = ''
221-
scope.$digest()
222-
223-
expect(stockart.isPhotoDescriptionRequired).to.be.true
224-
expect(stockart.isPhotoURLRequired).to.be.true
225-
expect(stockart.isFileNumberRequired).to.be.true
226-
})
227-
})
228-
})
229142
})

app/submissions/submit-design-files/submit-design-files.controller.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,8 @@ import _ from 'lodash'
131131

132132
// Process stock art
133133
var processedStockarts = _.reduce(vm.formStockarts, function(compiledStockarts, formStockart) {
134-
if (formStockart.description) {
134+
if (formStockart.sourceUrl) {
135135
delete formStockart.id
136-
delete formStockart.isPhotoDescriptionRequired
137-
delete formStockart.isPhotoURLRequired
138-
delete formStockart.isFileNumberRequired
139136

140137
compiledStockarts.push(formStockart)
141138
}

app/submissions/submit-design-files/submit-design-files.spec.js

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -196,38 +196,14 @@ describe('Submit Design Files Controller', function() {
196196
expect(vm.submissionsBody.data.stockArts).to.deep.equal([])
197197
})
198198

199-
it('removes the required properties and id from each stockart', function() {
199+
it('removes the id from each stockart', function() {
200200
vm.formStockarts = [
201-
{
202-
id: 0,
203-
description: 'first stockart',
204-
sourceUrl: 'url.com',
205-
fileNumber: '123',
206-
isPhotoDescriptionRequired: false,
207-
isPhotoURLRequired: false,
208-
isFileNumberRequired: false
209-
},
210-
{
211-
id: 1,
212-
description: 'second stockart',
213-
sourceUrl: 'url2.com',
214-
fileNumber: '234',
215-
isPhotoDescriptionRequired: false,
216-
isPhotoURLRequired: false,
217-
isFileNumberRequired: false
218-
}
201+
{ id: 0, sourceUrl: 'url.com' },
202+
{ id: 1, sourceUrl: 'url2.com' }
219203
]
220204
var processedStockart = [
221-
{
222-
description: 'first stockart',
223-
sourceUrl: 'url.com',
224-
fileNumber: '123'
225-
},
226-
{
227-
description: 'second stockart',
228-
sourceUrl: 'url2.com',
229-
fileNumber: '234'
230-
}
205+
{ sourceUrl: 'url.com' },
206+
{ sourceUrl: 'url2.com' }
231207
]
232208
scope.$digest()
233209

0 commit comments

Comments
 (0)