Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit 711acf8

Browse files
committed
Merge pull request #1654 from rmisio/1622
1622
2 parents a76a615 + 17bf3e3 commit 711acf8

File tree

3 files changed

+52
-29
lines changed

3 files changed

+52
-29
lines changed

js/templates/itemEdit.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ <h5 class="floatLeft"><%= polyglot.t('Photos') %></h5>
2727
<input type="file" name="image" id="itemImageUploadMain" accept="image/*" class="hide js-itemImageUpload" multiple <%= ob.images.length >= ob.MAX_PHOTOS ? 'disabled' : '' %>>
2828
</label>
2929
</div>
30-
<div class="flexRow js-editItemSubImagesWrapper editItemImageHolder">
30+
<div class="flexRow js-editItemSubImagesWrapper editItemImageHolder" data-label="<%= polyglot.t('Photos') %>">
3131
<div class="statusBar navBar fadeOut positionAbsolute js-itemEditImageLoading">
3232
<div class="pad20 rowTop20 width100"><h4 class="txt-center"><%= polyglot.t('LoadingImage') %></h4></div>
3333
</div>
@@ -164,7 +164,7 @@ <h5><%= polyglot.t('Listing') %></h5>
164164
<div class="note rowTop5"><%= polyglot.t('HighlightToStyle') %></div>
165165
</div>
166166
</div>
167-
<div class="flexCol-9">
167+
<div class="flexCol-9" data-label="<%= polyglot.t('Description') %>">
168168
<textarea name="description"
169169
rows="8"
170170
class="fieldItem-textarea custCol-text height130 customThemeScrollbar"
@@ -200,7 +200,7 @@ <h5><%= polyglot.t('Shipping') %></h5>
200200
</div>
201201
</div>
202202
<div class="flexCol-8">
203-
<div class="fieldItem padding0 js-shipToWrapper">
203+
<div class="fieldItem padding0 js-shipToWrapper" data-label="<%= polyglot.t('ShipsTo') %>">
204204
<div class="fieldItem-selectWrapper noIcon positionWrapper">
205205
<select name="ships_to" class="chosen custCol-text" id="shipsTo" multiple required>
206206
</select>
@@ -379,7 +379,7 @@ <h5><%= polyglot.t('Discover') %></h5>
379379
</div>
380380
</div>
381381
<div class="flexCol-9">
382-
<div class="fieldItem padding015" id="inputKeyword"></div>
382+
<div class="fieldItem padding015" id="inputKeyword" data-label="<%= polyglot.t('Tags') %>"></div>
383383
</div>
384384
</div>
385385
<div class="flexRow">

js/views/itemEditVw.js

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
var __ = require('underscore'),
44
Backbone = require('backbone'),
5-
$ = require('jquery');
6-
Backbone.$ = $;
7-
8-
var loadTemplate = require('../utils/loadTemplate'),
5+
$ = require('jquery'),
6+
loadTemplate = require('../utils/loadTemplate'),
97
countriesModel = require('../models/countriesMd'),
108
Taggle = require('taggle'),
119
MediumEditor = require('medium-editor'),
@@ -69,6 +67,7 @@ module.exports = baseVw.extend({
6967
this.prevShipsToVal = [];
7068
this.defaultDate = nowDate.getFullYear() + "-" + padTime(nowMonth) + "-" + padTime(nowDate.getDate()) + "T" + padTime(nowDate.getHours()) + ":" + padTime(nowDate.getMinutes());
7169
this.imgHashes = this.model.get('vendor_offer').listing.item.image_hashes;
70+
__.bindAll(this, 'validateDescription');
7271

7372
self.model.set('expTime', self.model.get('vendor_offer').listing.metadata.expiry.replace(" UTC", ""));
7473

@@ -111,7 +110,6 @@ module.exports = baseVw.extend({
111110
});
112111

113112
editor.subscribe('blur', self.validateDescription);
114-
115113

116114
//set chosen inputs
117115
self.$('.chosen').chosen({
@@ -194,7 +192,15 @@ module.exports = baseVw.extend({
194192
tags: keywordTags,
195193
preserveCase: true,
196194
saveOnBlur: true,
197-
placeholder: window.polyglot.t('KeywordsPlaceholder')
195+
placeholder: window.polyglot.t('KeywordsPlaceholder'),
196+
onTagAdd: () => {
197+
this.$('#inputKeyword').removeClass('invalid');
198+
},
199+
onTagRemove: () => {
200+
if (!self.inputKeyword.getTags().elements.length) {
201+
self.$('#inputKeyword').addClass('invalid');
202+
}
203+
}
198204
});
199205
}, 0);
200206

@@ -296,7 +302,12 @@ module.exports = baseVw.extend({
296302
$(e.target).val(newVal);
297303
this.$('.chosen').trigger('chosen:updated');
298304
this.prevShipsToVal = newVal;
299-
this.$('.js-shipToWrapper').removeClass('invalid');
305+
306+
if (newVal.length) {
307+
this.$('.js-shipToWrapper').removeClass('invalid');
308+
} else {
309+
this.$('.js-shipToWrapper').addClass('invalid');
310+
}
300311
},
301312

302313
clearDate: function(){
@@ -351,6 +362,7 @@ module.exports = baseVw.extend({
351362

352363
if (!imageFiles.length) return;
353364

365+
this.$('#imageForm .invalid').removeClass('invalid');
354366
imageCount = imageFiles.length;
355367
this.$el.find('.js-itemEditImageLoading').removeClass("fadeOut");
356368

@@ -488,6 +500,7 @@ module.exports = baseVw.extend({
488500

489501
this.imgHashes.splice(imgIndex, 1);
490502
this.updateImages();
503+
!this.imgHashes.length && this.$('.js-editItemSubImagesWrapper').addClass('invalid');
491504
},
492505

493506
validateInput: function(e) {
@@ -500,7 +513,7 @@ module.exports = baseVw.extend({
500513

501514
validateDescription: function() {
502515
validateMediumEditor.checkVal(this.$('#inputDescription'));
503-
},
516+
},
504517

505518
saveChanges: function(){
506519
var self = this,
@@ -509,16 +522,15 @@ module.exports = baseVw.extend({
509522
submitForm = this.$el.find('#contractForm')[0],
510523
keywordsArray = this.inputKeyword.getTagValues(),
511524
shipsToInput = this.$('#shipsTo'),
512-
invalidInputList = "";
525+
invalidInputList = [],
526+
hasError;
513527

514528
validateMediumEditor.checkVal(this.$('#inputDescription'));
515529

516530
if (keywordsArray.length < 1){
517-
this.$('#inputKeyword').closest('.flexRow').addClass('invalid');
518-
messageModal.show(window.polyglot.t('errorMessages.saveError'), window.polyglot.t('errorMessages.missingError') + "<br><i>"+ window.polyglot.t('Tags')+"</i>");
519-
return $.Deferred().reject('failed form validation').promise();
531+
this.$('#inputKeyword').addClass('invalid');
532+
hasError = true;
520533
}
521-
this.$('#inputKeyword').closest('.flexRow').removeClass('invalid');
522534

523535
keywordsArray = keywordsArray.map(function(tag){
524536
var re = /#/g;
@@ -542,8 +554,7 @@ module.exports = baseVw.extend({
542554
//make sure a ships to value is entered
543555
if (!shipsToInput.val() && !this.noShipping){
544556
this.$('.js-shipToWrapper').addClass('invalid');
545-
messageModal.show(window.polyglot.t('errorMessages.saveError'), window.polyglot.t('errorMessages.missingError'));
546-
return $.Deferred().reject('failed form validation').promise();
557+
hasError = true;
547558
}
548559

549560
//add old and new image hashes
@@ -554,12 +565,17 @@ module.exports = baseVw.extend({
554565
}
555566
});
556567

557-
if (keywordsArray.length > 0){
568+
if (!this.imgHashes.length) {
569+
this.$('.js-editItemSubImagesWrapper').addClass('invalid');
570+
hasError = true;
571+
}
572+
573+
if (keywordsArray.length) {
558574
__.each(keywordsArray, function(keyword){
559575
formData.append('keywords', keyword);
560576
});
561577
} else {
562-
formData.append('keywords', "");
578+
formData.append('keywords', '');
563579
}
564580

565581
//if this is an existing product, do not delete the images
@@ -581,7 +597,7 @@ module.exports = baseVw.extend({
581597
//add formChecked class to form so invalid fields are styled as invalid
582598
this.$el.find('#contractForm').addClass('formChecked');
583599

584-
if (this.checkFormValidity()){
600+
if (this.checkFormValidity() && !hasError) {
585601
return $.ajax({
586602
type: "POST",
587603
url: self.model.get('serverUrl') + "contracts",
@@ -603,13 +619,20 @@ module.exports = baseVw.extend({
603619
}
604620
});
605621
}
606-
$(submitForm).find('input, textarea').each(function() {
607-
if ($(this).is(":invalid")){
608-
var inputName = $("label[for='"+$(this).attr('id')+"']").text() || $(this).attr('id');
609-
invalidInputList += "<br/>"+inputName;
610-
}
622+
623+
$(submitForm).add(this.$('#imageForm')).find(':invalid, .invalid').each(function() {
624+
var inputName,
625+
$label;
626+
627+
inputName = (($label = self.$("label[for='"+$(this).attr('id')+"']")).length && $label.text()) ||
628+
$(this).attr('data-label') || $(this).attr('id');
629+
630+
invalidInputList.push(inputName.trim())
611631
});
612-
messageModal.show(window.polyglot.t('errorMessages.saveError'), window.polyglot.t('errorMessages.missingError') + "<br><i>"+ invalidInputList+"</i>");
632+
633+
invalidInputList = __.uniq(invalidInputList);
634+
messageModal.show(window.polyglot.t('errorMessages.saveError'), window.polyglot.t('errorMessages.missingError') +
635+
'<br><i><br />' + invalidInputList.join('<br />') + '</i>');
613636
return $.Deferred().reject('failed form validation').promise();
614637
},
615638

js/views/userPageVw.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1518,7 +1518,7 @@ UserPageVw = pageVw.extend({
15181518

15191519
saveItem: function(){
15201520
if (this.itemEditView) {
1521-
var $saveBtn = $('.js-saveItem');
1521+
var $saveBtn = this.$('.js-saveItem');
15221522

15231523
$saveBtn.addClass('loading');
15241524

0 commit comments

Comments
 (0)