Address PR comment's

Fix tests
This commit is contained in:
Nicolas Le Goff
2013-05-27 18:19:44 +02:00
committed by Romain Neutron
parent 848413dead
commit b52e4ee8c0
30 changed files with 369 additions and 191 deletions

View File

@@ -1,3 +1,12 @@
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
define([
"jquery",
"underscore",

View File

@@ -1,3 +1,12 @@
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
define([
"underscore",
"backbone",

View File

@@ -1,3 +1,12 @@
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
define([
"underscore",
"backbone",

View File

@@ -1,3 +1,12 @@
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
define([
"underscore",
"backbone",

View File

@@ -1,3 +1,12 @@
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
define([
"jquery",
"underscore"

View File

@@ -1,3 +1,12 @@
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
define([
"jquery",
"underscore",

View File

@@ -1,3 +1,12 @@
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
define([
"jquery",
"underscore"

View File

@@ -1,3 +1,12 @@
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
// configure AMD loading
require.config({
baseUrl: "/scripts",

View File

@@ -1,3 +1,12 @@
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
define([
"jquery",
"underscore",

View File

@@ -1,3 +1,12 @@
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
define([
"jquery",
"underscore",

View File

@@ -1,10 +1,19 @@
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
define([
"jquery",
"underscore",
"backbone",
"i18n",
"bootstrap",
"apps/admin/fields/views/create",
"apps/admin/fields/views/alert",
"models/field"
], function($, _, Backbone, i18n, bootstrap, AlertView, FieldModel) {
var CreateView = Backbone.View.extend({
@@ -105,18 +114,18 @@ define([
field.save(null, {
success: function(field, response, options) {
if (response.success) {
AdminFieldApp.fieldsCollection.add(field);
_.last(self.itemViews).clickAction().animate();
}
AdminFieldApp.fieldsCollection.add(field);
_.last(AdminFieldApp.fieldListView.itemViews).clickAction().animate();
new AlertView({
alert: response.success ? "success" : "error", message: response.message
new AlertView({alert: "info", message: i18n.t("created_success", {
postProcess: "sprintf",
sprintf: [field.get("name")]
})
}).render();
},
error: function(model, xhr, options) {
error: function(xhr, textStatus, errorThrown) {
new AlertView({
alert: "error", message: i18n.t("something_wrong")}
alert: "error", message: '' !== xhr.responseText ? xhr.responseText : i18n.t("something_wrong")}
).render();
self.toggleCreateFormAction();

View File

@@ -1,3 +1,12 @@
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
define([
"jquery",
"underscore",
@@ -17,7 +26,7 @@ define([
});
this.$el.html(template);
var index = $("#dces-element", this.$el)[0].selectedIndex - 1;
if (index > 0 ) {
$(".dces-help-block", AdminFieldApp.$rightBlock).html(

View File

@@ -1,3 +1,12 @@
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
define([
"jquery",
"underscore",
@@ -64,31 +73,6 @@ define([
var fieldTagId = fieldTag.attr("id");
var fieldTagValue = fieldTag.val();
// check for format tag
if ("" !== fieldTagValue && false === /[a-z]+:[a-z0-9]+/i.test(fieldTagValue)) {
fieldTag
.closest(".control-group")
.addClass("error")
.find(".help-block")
.empty()
.append(i18n.t("validation_tag_invalid"));
// add error
AdminFieldApp.errorManager.addModelFieldError(new Error(
self.model, fieldTagId, i18n.t("validation_tag_invalid")
));
} else if (fieldTag.closest(".control-group").hasClass("error")) {
// remove error
AdminFieldApp.errorManager.removeModelFieldError(
self.model, fieldTagId
);
fieldTag
.closest(".control-group")
.removeClass("error")
.find(".help-block")
.empty();
}
var data = {};
data[fieldTagId] = fieldTagValue;
self.model.set(data);
@@ -109,6 +93,7 @@ define([
"click .delete-field": "deleteAction",
"keyup #name": "changeNameAction",
"focusout input[type=text]": "fieldChangedAction",
"focusout input#tag": "tagFieldChangedAction",
"change input[type=checkbox]": "fieldChangedAction",
"change select": "selectionChangedAction"
},
@@ -170,6 +155,38 @@ define([
return this;
},
tagFieldChangedAction: function(e) {
var fieldTag = $(e.target);
var fieldTagId = fieldTag.attr("id");
var fieldTagValue = fieldTag.val();
// check for format tag
if ("" !== fieldTagValue && false === /[a-z]+:[a-z0-9]+/i.test(fieldTagValue)) {
fieldTag
.closest(".control-group")
.addClass("error")
.find(".help-block")
.empty()
.append(i18n.t("validation_tag_invalid"));
// add error
AdminFieldApp.errorManager.addModelFieldError(new Error(
this.model, fieldTagId, i18n.t("validation_tag_invalid")
));
} else if (fieldTag.closest(".control-group").hasClass("error")) {
// remove error
AdminFieldApp.errorManager.removeModelFieldError(
this.model, fieldTagId
);
fieldTag
.closest(".control-group")
.removeClass("error")
.find(".help-block")
.empty();
}
this.fieldChangedAction(e);
},
deleteAction: function() {
var self = this;
var modalView = new ModalView({
@@ -200,9 +217,9 @@ define([
})
}).render();
},
error: function(model, xhr) {
error: function(xhr, textStatus, errorThrown) {
new AlertView({
alert: "error", message: i18n.t("something_wrong")
alert: "error", message: '' !== xhr.responseText ? xhr.responseText : i18n.t("something_wrong")
}).render();
}
});
@@ -213,12 +230,13 @@ define([
_onModelChange: function() {
AdminFieldApp.fieldListView.collection.remove(this.model, {silent: true});
AdminFieldApp.fieldListView.collection.add(this.model);
var index = AdminFieldApp.fieldListView.collection.indexOf(this.model);
this._selectModelView(index);
this.render();
AdminFieldApp.saveView.updateStateButton();
},
// select temView by index in itemList
_selectModelView: function(index) {

View File

@@ -1,3 +1,12 @@
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
define([
"jquery",
"underscore",

View File

@@ -1,3 +1,12 @@
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
define([
"jquery",
"jqueryui",
@@ -85,7 +94,6 @@ define([
placeholder: "item-list-placeholder",
start: function(event, ui) {
ui.item.addClass("border-bottom");
},
stop: function(event, ui) {
ui.firstItemPosition = $("li:first", $(this).sortable('widget')).position().top;
@@ -105,18 +113,18 @@ define([
return this;
},
updateSortAction: function(event, model, ui) {
var position = ui.item.index();
this.collection.remove(model, {silent: true});
var newPosition = ui.item.index();
var curPosition = this.collection.indexOf(model);
// reorder all collection model
this.collection.each(function(model, index) {
var ordinal = index;
if (index >= position) ordinal += 1;
model.set("sorter", ordinal);
this.collection.each(function(el, index) {
if (newPosition > curPosition && (index > curPosition && index <= curPosition)) index -= 1;
else if (newPosition < curPosition && (index >= curPosition && index < curPosition)) index += 1;
el.set("sorter", index);
});
model.set("sorter", position);
this.collection.add(model, {at: position});
this.render();
this.itemViews[0].animate(Math.abs(ui.firstItemPosition));
@@ -125,6 +133,8 @@ define([
return el.get("id") === AdminFieldApp.fieldEditView.model.get("id");
});
AdminFieldApp.saveView.updateStateButton();
return this;
}
}));

View File

@@ -1,3 +1,12 @@
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
define([
"jquery",
"underscore",

View File

@@ -1,3 +1,12 @@
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
define([
"jquery",
"underscore",

View File

@@ -1,3 +1,12 @@
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
define([
"jquery",
"underscore",
@@ -29,20 +38,18 @@ define([
if (this._isModelDesync()) {
this._loadingState(true);
AdminFieldApp.fieldsCollection.save({
success: function(response) {
success: function(fields) {
// reset collection with new one
if (response.success) {
AdminFieldApp.fieldsCollection.reset(response.fields);
}
AdminFieldApp.fieldsCollection.reset(fields);
new AlertView({
alert: response.success ? "success" : "error",
message: response.messages.join("<br />")
alert: "success",
message: i18n.t("fields_save")
}).render();
},
error: function(model, xhr, options) {
error: function(xhr, textStatus, errorThrown) {
new AlertView({
alert: "error", message: i18n.t("something_wrong")
alert: "error", message: '' !== xhr.responseText ? xhr.responseText : i18n.t("something_wrong")
}).render();
}
}).done(function() {
@@ -55,9 +62,13 @@ define([
render: function () {
var template = _.template($("#save_template").html());
this.$el.html(template);
this.updateStateButton();
return this;
},
updateStateButton: function() {
this._disableSaveButton(!this._isModelDesync());
},
// check whether model has changed or not
_isModelDesync: function () {
return "undefined" !== typeof AdminFieldApp.fieldsCollection.find(function(model) {
@@ -86,7 +97,7 @@ define([
$(".save-block", AdminFieldApp.$top).removeClass("loading");
}
this._disableSaveButton(active);
this.updateStateButton();
this._overlay(active);
}
});