Fix JS codestyle

This commit is contained in:
Romain Neutron
2013-11-12 12:49:23 +01:00
parent 51fb364d13
commit 9fa95db23c
78 changed files with 5184 additions and 6309 deletions

View File

@@ -19,19 +19,17 @@ define([
"apps/admin/fields/views/save",
"apps/admin/fields/views/fieldError",
"apps/admin/fields/errors/errorManager"
], function(
$, _, Backbone, i18n, FieldsCollection, VocabulariesCollection,
DcFieldsCollection, FieldListView, SaveView, FieldErrorView, ErrorManager) {
var initialize = function() {
], function ($, _, Backbone, i18n, FieldsCollection, VocabulariesCollection, DcFieldsCollection, FieldListView, SaveView, FieldErrorView, ErrorManager) {
var initialize = function () {
AdminFieldApp = {
$window : $(window),
$scope : $("#admin-field-app"),
$top : $(".row-top", this.$scope),
$bottom : $(".row-bottom", this.$scope),
$leftBlock : $(".left-block", this.$bottom),
$rightBlock : $(".right-block", this.$bottom),
fieldsToDelete : [],
lng : function() {
$window: $(window),
$scope: $("#admin-field-app"),
$top: $(".row-top", this.$scope),
$bottom: $(".row-bottom", this.$scope),
$leftBlock: $(".left-block", this.$bottom),
$rightBlock: $(".right-block", this.$bottom),
fieldsToDelete: [],
lng: function () {
return typeof p4 === "undefined" ? "en" : (p4.lng || "en");
},
resizeListBlock: function () {
@@ -56,7 +54,7 @@ define([
// initiliaze collections
AdminFieldApp.fieldsCollection = new FieldsCollection(null, {
sbas_id : AdminFieldApp.sbas_id
sbas_id: AdminFieldApp.sbas_id
});
AdminFieldApp.vocabularyCollection = new VocabulariesCollection();
AdminFieldApp.dcFieldsCollection = new DcFieldsCollection();
@@ -71,12 +69,12 @@ define([
AdminFieldApp.dcFieldsCollection.fetch(),
$.ajax({
url: '/available-languages',
success: function(languages) {
success: function (languages) {
AdminFieldApp.languages = languages;
}
})
]).done(
function() {
function () {
// register views
AdminFieldApp.saveView = new SaveView({
el: $(".save-block", AdminFieldApp.scope)
@@ -96,7 +94,7 @@ define([
AdminFieldApp.$window.trigger("resize");
// click on first item list
if (AdminFieldApp.fieldListView.itemViews.length > 0 ) {
if (AdminFieldApp.fieldListView.itemViews.length > 0) {
_.first(AdminFieldApp.fieldListView.itemViews).clickAction().animate();
}
}

View File

@@ -11,13 +11,13 @@ define([
"underscore",
"backbone",
"models/dcField"
], function(_, Backbone, DcFieldModel) {
], function (_, Backbone, DcFieldModel) {
var DcFieldCollection = Backbone.Collection.extend({
model: DcFieldModel,
url: function() {
url: function () {
return "/admin/fields/dc-fields";
},
comparator: function(item) {
comparator: function (item) {
return item.get("label");
}
});

View File

@@ -11,9 +11,9 @@ define([
"underscore",
"backbone",
"models/field"
], function(_, Backbone, FieldModel) {
], function (_, Backbone, FieldModel) {
var FieldCollection = Backbone.Collection.extend({
initialize: function(models, options) {
initialize: function (models, options) {
options = options || {};
if (typeof options === "object" && false === "sbas_id" in options) {
throw "You must set a sbas id"
@@ -21,23 +21,23 @@ define([
this.sbasId = options.sbas_id;
},
model: FieldModel,
url: function() {
url: function () {
return "/admin/fields/" + this.sbasId + "/fields";
},
search: function(letters) {
search: function (letters) {
if (letters === "")
return this;
var pattern = new RegExp(letters, "gi");
return _(this.filter(function(data) {
return _(this.filter(function (data) {
return pattern.test(data.get("name"));
}));
},
comparator: function(item) {
comparator: function (item) {
return item.get("sorter");
},
nextIndex: function(model) {
nextIndex: function (model) {
var index = this.indexOf(model);
if (index < 0) {
@@ -50,7 +50,7 @@ define([
return index + 1;
},
previousIndex: function(model) {
previousIndex: function (model) {
var index = this.indexOf(model);
if (index < 0) {
@@ -64,7 +64,7 @@ define([
return index - 1;
},
// save all collection
save: function(options) {
save: function (options) {
return Backbone.sync("update", this, options || {});
}
});

View File

@@ -11,13 +11,13 @@ define([
"underscore",
"backbone",
"models/vocabulary"
], function(_, Backbone, VocabularyModel) {
], function (_, Backbone, VocabularyModel) {
var VocabularyCollection = Backbone.Collection.extend({
model: VocabularyModel,
url: function() {
url: function () {
return "/admin/fields/vocabularies";
},
comparator: function(item) {
comparator: function (item) {
return item.get("name");
}
});

View File

@@ -10,7 +10,7 @@
define([
"jquery",
"underscore"
], function($, _) {
], function ($, _) {
var Error = function (model, fieldId, message) {
this.model = model;

View File

@@ -12,9 +12,9 @@ define([
"underscore",
"backbone",
"apps/admin/fields/errors/errorModel"
], function($, _, Backbone, ErrorModel) {
], function ($, _, Backbone, ErrorModel) {
var ErrorManager = function() {
var ErrorManager = function () {
this.errors = {};
_.extend(this, Backbone.Events);
};
@@ -38,8 +38,8 @@ define([
containsModelError: function (model) {
return "undefined" !== typeof this.errors[model.get("id")];
},
addModelFieldError: function(error) {
if (! error instanceof Error) {
addModelFieldError: function (error) {
if (!error instanceof Error) {
throw "Item must be an error object";
}
@@ -56,7 +56,7 @@ define([
return this;
},
removeModelFieldError: function(model, fieldId) {
removeModelFieldError: function (model, fieldId) {
var modelError = this.getModelError(model);
if (modelError) {
@@ -72,7 +72,7 @@ define([
}
}
},
clearModelFieldErrors: function(model, fieldId) {
clearModelFieldErrors: function (model, fieldId) {
var modelError = this.getModelError(model);
if (modelError) {
@@ -93,7 +93,7 @@ define([
return false;
},
getModelFieldError: function(model, fieldId) {
getModelFieldError: function (model, fieldId) {
var modelError = this.getModelError(model);
if (modelError) {
@@ -102,7 +102,7 @@ define([
return null;
},
clearAll: function() {
clearAll: function () {
this.errors = {};
this.trigger("no-error");
},
@@ -120,8 +120,8 @@ define([
},
all: function () {
var errors = [];
_.each(this.errors, function(modelErrors) {
_.each(modelErrors.all(), function(error) {
_.each(this.errors, function (modelErrors) {
_.each(modelErrors.all(), function (error) {
errors.push(error);
});
});

View File

@@ -10,21 +10,21 @@
define([
"jquery",
"underscore"
], function($, _) {
var ErrorModel = function(id) {
], function ($, _) {
var ErrorModel = function (id) {
this.id = id;
this.errors = {};
};
ErrorModel.prototype = {
add: function(id, error) {
if (! error instanceof Error) {
add: function (id, error) {
if (!error instanceof Error) {
throw "Item must be an error object";
}
this.errors[id] = error;
},
get: function(id) {
get: function (id) {
if (this.has(id)) {
return this.errors[id];
}
@@ -33,12 +33,12 @@ define([
has: function (id) {
return "undefined" !== typeof this.errors[id];
},
remove: function(id) {
remove: function (id) {
if (this.has(id)) {
delete this.errors[id];
}
},
count: function() {
count: function () {
var count = 0;
for (var k in this.errors) {
if (this.errors.hasOwnProperty(k)) {

View File

@@ -19,7 +19,7 @@ require.config({
bootstrap: "../skins/build/bootstrap/js/bootstrap.min"
},
shim: {
bootstrap : ["jquery"],
bootstrap: ["jquery"],
jqueryui: {
deps: [ "jquery" ]
}
@@ -27,6 +27,6 @@ require.config({
});
// launch application
require(["apps/admin/fields/app"], function(App) {
require(["apps/admin/fields/app"], function (App) {
App.initialize();
});

View File

@@ -13,11 +13,11 @@ define([
"backbone",
"i18n",
"bootstrap"
], function($, _, Backbone, i18n, bootstrap) {
], function ($, _, Backbone, i18n, bootstrap) {
var AlertView = Backbone.View.extend({
tagName: "div",
className: "alert",
initialize: function(options) {
initialize: function (options) {
var self = this;
if (options) {
@@ -30,7 +30,7 @@ define([
self.remove();
});
},
render: function() {
render: function () {
var self = this;
var template = _.template($("#alert_template").html(), {
msg: this.message
@@ -39,7 +39,9 @@ define([
this.$el.addClass("alert-" + this.alert).html(template).alert();
if (this.delay > 0) {
window.setTimeout(function() { self.$el.alert('close') }, this.delay);
window.setTimeout(function () {
self.$el.alert('close')
}, this.delay);
}
$(".block-alert").empty().append(this.$el);

View File

@@ -15,31 +15,31 @@ define([
"bootstrap",
"apps/admin/fields/views/alert",
"models/field"
], function($, _, Backbone, i18n, bootstrap, AlertView, FieldModel) {
], function ($, _, Backbone, i18n, bootstrap, AlertView, FieldModel) {
var CreateView = Backbone.View.extend({
tagName: "div",
events: {
"click .btn-submit-field": "createAction",
"click .btn-add-field": "toggleCreateFormAction",
"click .btn-cancel-field": "toggleCreateFormAction",
"keyup input": "onKeyupInput"
"keyup input": "onKeyupInput"
},
render: function() {
render: function () {
var template = _.template($("#create_template").html());
this.$el.html(template);
$("#new-source", this.$el).autocomplete({
minLength: 2,
source: function(request, response) {
source: function (request, response) {
$.ajax({
url: "/admin/fields/tags/search",
dataType: "json",
data: {
term: request.term
},
success: function(data) {
response($.map(data, function(item) {
success: function (data) {
response($.map(data, function (item) {
return {
label: item.label,
value: item.value
@@ -59,7 +59,7 @@ define([
.find(".help-block")
.empty();
},
createAction: function(event) {
createAction: function (event) {
var self = this;
var formErrors = 0;
@@ -81,7 +81,7 @@ define([
}
// check for duplicate field name
if ("undefined" !== typeof AdminFieldApp.fieldsCollection.find(function(model){
if ("undefined" !== typeof AdminFieldApp.fieldsCollection.find(function (model) {
return model.get("name").toLowerCase() === fieldNameValue.toLowerCase();
})) {
fieldName
@@ -118,7 +118,7 @@ define([
formErrors++;
}
if (formErrors > 0 ) {
if (formErrors > 0) {
return;
}
@@ -126,15 +126,15 @@ define([
"sbas-id": AdminFieldApp.sbas_id,
"name": fieldNameValue,
"tag": fieldTagValue,
"label_en" : $("#new-label_en", this.$el).val(),
"label_fr" : $("#new-label_fr", this.$el).val(),
"label_de" : $("#new-label_de", this.$el).val(),
"label_nl" : $("#new-label_nl", this.$el).val(),
"label_en": $("#new-label_en", this.$el).val(),
"label_fr": $("#new-label_fr", this.$el).val(),
"label_de": $("#new-label_de", this.$el).val(),
"label_nl": $("#new-label_nl", this.$el).val(),
"multi": $("#new-multivalued", this.$el).is(":checked")
});
field.save(null, {
success: function(field, response, options) {
success: function (field, response, options) {
AdminFieldApp.fieldsCollection.add(field);
_.last(AdminFieldApp.fieldListView.itemViews).clickAction().animate();
@@ -144,7 +144,7 @@ define([
})
}).render();
},
error: function(xhr, textStatus, errorThrown) {
error: function (xhr, textStatus, errorThrown) {
new AlertView({
alert: "error", message: '' !== xhr.responseText ? xhr.responseText : i18n.t("something_wrong")}
).render();
@@ -155,7 +155,7 @@ define([
return this;
},
toggleCreateFormAction: function(event) {
toggleCreateFormAction: function (event) {
var fieldBlock = $(".add-field-block", this.$el);
var addBtn = $(".btn-add-field", this.$el);

View File

@@ -17,22 +17,22 @@ define([
"apps/admin/fields/views/modal",
"apps/admin/fields/views/dcField",
"apps/admin/fields/errors/error"
], function($, _, Backbone, i18n, MultiViews, AlertView, ModalView, DcFieldView, Error) {
], function ($, _, Backbone, i18n, MultiViews, AlertView, ModalView, DcFieldView, Error) {
// Add multiview methods
var FieldEditView = Backbone.View.extend(_.extend({}, MultiViews, {
tagName: "div",
className: "field-edit",
initialize: function() {
initialize: function () {
this.model.on("change", this._onModelChange, this);
},
updateModel: function(model) {
updateModel: function (model) {
// unbind event to previous model
this.model.off("change");
this.model = model;
return this;
},
render: function() {
render: function () {
var self = this;
var template = _.template($("#edit_template").html(), {
lng: AdminFieldApp.lng(),
@@ -45,7 +45,7 @@ define([
this.$el.empty().html(template);
this._assignView({
".dc-fields-subview" : new DcFieldView({
".dc-fields-subview": new DcFieldView({
collection: AdminFieldApp.dcFieldsCollection,
field: this.model
})
@@ -53,15 +53,15 @@ define([
var completer = $("#tag", this.$el).autocomplete({
minLength: 2,
source: function(request, response) {
source: function (request, response) {
$.ajax({
url: "/admin/fields/tags/search",
dataType: "json",
data: {
term: request.term
},
success: function(data) {
response($.map(data, function(item) {
success: function (data) {
response($.map(data, function (item) {
return {
label: item.label,
value: item.value
@@ -70,7 +70,7 @@ define([
}
});
},
close: function(e) {
close: function (e) {
self.tagFieldChangedAction(e);
}
});
@@ -95,7 +95,7 @@ define([
"change select": "selectionChangedAction",
"click .lng-label a": "_toggleLabels"
},
triggerControlledVocabulary: function(e) {
triggerControlledVocabulary: function (e) {
if ($(e.target, this.$el).find("option:selected").val() === "") {
this.model.set("vocabulary-type", false);
this.render();
@@ -105,7 +105,7 @@ define([
this.render();
}
},
selectionChangedAction: function(e) {
selectionChangedAction: function (e) {
var field = $(e.target);
var data = {};
data[field.attr("id")] = $("option:selected", field).val();
@@ -113,7 +113,7 @@ define([
return this;
},
fieldChangedAction: function(e) {
fieldChangedAction: function (e) {
var field = $(e.target);
var fieldId = field.attr("id");
var data = {};
@@ -122,7 +122,7 @@ define([
return this;
},
labelChangedAction: function(e) {
labelChangedAction: function (e) {
var field = $(e.target);
var fieldId = field.attr("id");
var data = this.model.get("labels");
@@ -133,13 +133,13 @@ define([
return this;
},
tagFieldChangedAction: function(e) {
tagFieldChangedAction: function (e) {
var $this = this;
var fieldTag = $(e.target);
var fieldTagId = fieldTag.attr("id");
var fieldTagValue = fieldTag.val();
var onFieldValid = function() {
var onFieldValid = function () {
if (fieldTag.closest(".control-group").hasClass("error")) {
// remove error
AdminFieldApp.errorManager.removeModelFieldError(
@@ -157,7 +157,7 @@ define([
}
if ("" !== fieldTagValue) {
var jqxhr = $.get( "/admin/fields/tags/"+fieldTagValue, onFieldValid).fail(function() {
var jqxhr = $.get("/admin/fields/tags/" + fieldTagValue, onFieldValid).fail(function () {
fieldTag
.closest(".control-group")
.addClass("error")
@@ -173,7 +173,7 @@ define([
onFieldValid();
}
},
deleteAction: function() {
deleteAction: function () {
var self = this;
var modalView = new ModalView({
model: this.model,
@@ -191,7 +191,7 @@ define([
var index = previousIndex ? previousIndex : (nextIndex ? nextIndex - 1 : -1);
modalView.render();
modalView.on("modal:confirm", function() {
modalView.on("modal:confirm", function () {
AdminFieldApp.fieldsToDelete.push(self.model);
AdminFieldApp.fieldListView.collection.remove(self.model);
self._selectModelView(index);
@@ -200,19 +200,19 @@ define([
return this;
},
_onModelChange: function() {
_onModelChange: function () {
AdminFieldApp.fieldListView.collection.remove(this.model, {silent: true});
AdminFieldApp.fieldListView.collection.add(this.model, {silent: true});
AdminFieldApp.saveView.updateStateButton();
},
// select temView by index in itemList
_selectModelView: function(index) {
_selectModelView: function (index) {
// select previous or next itemview
if (index >= 0) {
AdminFieldApp.fieldListView.itemViews[index].select().animate().click();
}
},
_toggleLabels: function(event) {
_toggleLabels: function (event) {
event.preventDefault();
var curLabel = $(event.target);
$('.lng-label', this.$el).removeClass("select");

View File

@@ -12,20 +12,20 @@ define([
"underscore",
"backbone",
"i18n"
], function($, _, Backbone, i18n) {
], function ($, _, Backbone, i18n) {
var FieldErrorView = Backbone.View.extend({
initialize: function() {
initialize: function () {
AdminFieldApp.errorManager.on("add-error", this.render, this);
AdminFieldApp.errorManager.on("remove-error", this.render, this);
},
render: function() {
render: function () {
var messages = [];
var errors = AdminFieldApp.errorManager.all();
_.each(_.groupBy(errors, function(error) {
_.each(_.groupBy(errors, function (error) {
return error.model.get("name");
}), function(groupedErrors) {
_.each(groupedErrors, function(error) {
}), function (groupedErrors) {
_.each(groupedErrors, function (error) {
messages.push(i18n.t("field_error", {
postProcess: "sprintf",
sprintf: [error.model.get("name")]

View File

@@ -16,13 +16,13 @@ define([
"common/multiviews",
"apps/admin/fields/views/listRow",
"apps/admin/fields/views/create"
], function($, jqueryui, _, Backbone, i18n, MultiViews, FieldListRowView, CreateView) {
], function ($, jqueryui, _, Backbone, i18n, MultiViews, FieldListRowView, CreateView) {
var FieldListView = Backbone.View.extend(_.extend({}, MultiViews, {
events: {
"keyup #live_search": "searchAction",
"update-sort": "updateSortAction"
},
initialize: function() {
initialize: function () {
var self = this;
// store all single rendered views
this.itemViews = [];
@@ -40,9 +40,9 @@ define([
this.collection.bind("remove", this._onRemove, this);
this.collection.bind("remove", this.render, this);
AdminFieldApp.errorManager.on('add-error', function(error) {
AdminFieldApp.errorManager.on('add-error', function (error) {
var model = error.model;
var itemView = _.find(self.itemViews, function(view) {
var itemView = _.find(self.itemViews, function (view) {
return model.get('id') === view.model.get('id');
});
@@ -51,8 +51,8 @@ define([
}
});
AdminFieldApp.errorManager.on('remove-error', function(model) {
var itemView = _.find(self.itemViews, function(view) {
AdminFieldApp.errorManager.on('remove-error', function (model) {
var itemView = _.find(self.itemViews, function (view) {
return model.get('id') === view.model.get('id');
});
@@ -61,7 +61,7 @@ define([
}
});
},
render: function() {
render: function () {
var template = _.template($("#item_list_view_template").html());
this.$el.empty().html(template);
@@ -71,7 +71,7 @@ define([
this._renderList(this.collection);
this._assignView({
".create-subview" : new CreateView()
".create-subview": new CreateView()
});
AdminFieldApp.resizeListBlock();
@@ -79,13 +79,13 @@ define([
return this;
},
// render list by appending single item view, also fill itemViews
_renderList: function(fields) {
_renderList: function (fields) {
var that = this;
this.$listEl.empty();
this.itemViews = [];
fields.each(function(field) {
fields.each(function (field) {
var fieldErrors = AdminFieldApp.errorManager.getModelError(field);
var singleView = new FieldListRowView({
@@ -100,10 +100,10 @@ define([
this.$listEl.sortable({
handle: ".handle",
placeholder: "item-list-placeholder",
start: function(event, ui) {
start: function (event, ui) {
ui.item.addClass("border-bottom");
},
stop: function(event, ui) {
stop: function (event, ui) {
ui.firstItemPosition = $("li:first", $(this).sortable('widget')).position().top;
ui.item.trigger("drop", ui);
}
@@ -115,14 +115,14 @@ define([
return this;
},
searchAction: function(event) {
searchAction: function (event) {
this._renderList(this.collection.search($("#live_search", this.$el).val()));
return this;
},
_onRemove : function (model) {
_onRemove: function (model) {
var models = [];
this.collection.each(function(m) {
this.collection.each(function (m) {
if (m.get("sorter") > model.get("sorter")) {
m.set("sorter", m.get("sorter") - 1);
}
@@ -132,7 +132,7 @@ define([
this.collection.reset(models);
},
updateSortAction: function(event, model, ui) {
updateSortAction: function (event, model, ui) {
var newPosition = ui.item.index();
this.collection.remove(model, {silent: true});
this.collection.each(function (model, index) {
@@ -145,7 +145,7 @@ define([
this.itemViews[0].animate(Math.abs(ui.firstItemPosition));
// update edit view model
AdminFieldApp.fieldEditView.updateModel(this.collection.find(function(el) {
AdminFieldApp.fieldEditView.updateModel(this.collection.find(function (el) {
return el.get("id") === AdminFieldApp.fieldEditView.model.get("id");
}));

View File

@@ -12,18 +12,18 @@ define([
"underscore",
"backbone",
"apps/admin/fields/views/edit"
], function($, _, Backbone, FieldEditView) {
], function ($, _, Backbone, FieldEditView) {
var FieldListRowView = Backbone.View.extend({
tagName: "li",
className: "field-row",
initialize: function() {
initialize: function () {
// destroy view is model is deleted
this.model.on("change", this.onChange, this);
this.model.on("destroy", this.remove, this);
},
events : {
events: {
"click .trigger-click": "clickAction",
"drop" : "dropAction"
"drop": "dropAction"
},
clickAction: function (e) {
this.select();
@@ -33,7 +33,7 @@ define([
el: AdminFieldApp.$rightBlock,
model: this.model
});
} else {
} else {
AdminFieldApp.fieldEditView.updateModel(this.model).initialize();
}
@@ -41,17 +41,17 @@ define([
return this;
},
dropAction: function(event, ui) {
dropAction: function (event, ui) {
this.$el.trigger("update-sort", [this.model, ui]);
return this;
},
onChange: function() {
onChange: function () {
if (this.model.hasChanged("tag")) {
this.render();
}
},
render: function() {
render: function () {
var template = _.template($("#list_row_template").html(), {
id: this.model.get("id"),
position: this.model.get("sorter"),
@@ -76,7 +76,7 @@ define([
return this;
},
click: function() {
click: function () {
this.$el.find('.trigger-click').first().trigger('click');
return this;
},
@@ -96,7 +96,7 @@ define([
error: function (errored) {
if (errored) {
this.$el.addClass("error");
} else {
} else {
this.$el.removeClass("error");
}

View File

@@ -13,7 +13,7 @@ define([
"backbone",
"i18n",
"bootstrap"
], function($, _, Backbone, i18n, bootstrap) {
], function ($, _, Backbone, i18n, bootstrap) {
var ModalView = Backbone.View.extend({
tagName: "div",
className: "modal",
@@ -23,7 +23,7 @@ define([
initialize: function (options) {
var self = this;
// remove view when modal is closed
this.$el.on("hidden", function() {
this.$el.on("hidden", function () {
self.remove();
});
@@ -31,7 +31,7 @@ define([
this.message = options.message;
}
},
render: function() {
render: function () {
var template = _.template($("#modal_template").html(), {
msg: this.message || ""
});

View File

@@ -14,46 +14,46 @@ define([
"i18n",
"bootstrap",
"apps/admin/fields/views/alert"
], function($, _, Backbone, i18n, bootstrap, AlertView) {
], function ($, _, Backbone, i18n, bootstrap, AlertView) {
var SaveView = Backbone.View.extend({
initialize: function() {
initialize: function () {
var self = this;
this.previousAttributes = [];
this.$overlay = null;
AdminFieldApp.errorManager.on("add-error", function(errors) {
AdminFieldApp.errorManager.on("add-error", function (errors) {
self._disableSaveButton(true);
});
AdminFieldApp.errorManager.on("no-error", function() {
AdminFieldApp.errorManager.on("no-error", function () {
self._disableSaveButton(false);
});
},
events: {
"click button.save-all" : "clickSaveAction"
"click button.save-all": "clickSaveAction"
},
clickSaveAction: function(event) {
clickSaveAction: function (event) {
var self = this;
if (this._isModelDesync()) {
this._loadingState(true);
$.when.apply($, _.map(AdminFieldApp.fieldsToDelete, function(m){
$.when.apply($, _.map(AdminFieldApp.fieldsToDelete, function (m) {
return m.destroy({
success: function(model, response) {
AdminFieldApp.fieldsToDelete = _.filter(AdminFieldApp.fieldsToDelete, function(m){
success: function (model, response) {
AdminFieldApp.fieldsToDelete = _.filter(AdminFieldApp.fieldsToDelete, function (m) {
return model.get("id") !== m.get("id");
});
},
error: function(xhr, textStatus, errorThrown) {
error: function (xhr, textStatus, errorThrown) {
new AlertView({
alert: "error", message: '' !== xhr.responseText ? xhr.responseText : i18n.t("something_wrong")
}).render();
}
});
})).done(
function() {
function () {
AdminFieldApp.fieldsCollection.save({
success: function(fields) {
success: function (fields) {
// reset collection with new one
AdminFieldApp.fieldsCollection.reset(fields);
@@ -63,12 +63,12 @@ define([
delay: 2000
}).render();
},
error: function(xhr, textStatus, errorThrown) {
error: function (xhr, textStatus, errorThrown) {
new AlertView({
alert: "error", message: '' !== xhr.responseText ? xhr.responseText : i18n.t("something_wrong")
}).render();
}
}).done(function() {
}).done(function () {
self._loadingState(false);
});
}
@@ -84,18 +84,18 @@ define([
return this;
},
updateStateButton: function() {
updateStateButton: function () {
this._disableSaveButton(!this._isModelDesync());
},
// check whether model has changed or not
_isModelDesync: function () {
return "undefined" !== typeof AdminFieldApp.fieldsCollection.find(function(model) {
return "undefined" !== typeof AdminFieldApp.fieldsCollection.find(function (model) {
return !_.isEmpty(model.previousAttributes());
});
},
// create a transparent overlay on top of the application
_overlay: function(showOrHide) {
if(showOrHide && !this.$overlay) {
_overlay: function (showOrHide) {
if (showOrHide && !this.$overlay) {
this.$overlay = $("<div>").addClass("overlay");
AdminFieldApp.$bottom.append(this.$overlay);
} else if (!showOrHide && this.$overlay) {
@@ -107,7 +107,7 @@ define([
$("button.save-all", this.$el).attr("disabled", active);
},
// put application on loading state (add overlay, add spinner, disable global save button)
_loadingState: function(active) {
_loadingState: function (active) {
if (active) {
$(".save-block", AdminFieldApp.$top).addClass("loading");
$(".block-alert", AdminFieldApp.$top).empty();

View File

@@ -12,24 +12,27 @@ require([
"i18n",
"apps/login/home/common",
"common/forms/views/form"
], function($, i18n, Common, LoginForm) {
], function ($, i18n, Common, LoginForm) {
Common.initialize();
i18n.init({
resGetPath: Common.languagePath,
useLocalStorage: true
}, function() {
}, function () {
new LoginForm({
el : $("form[name=loginForm]"),
rules: [{
name: "login",
rules: "required",
message: i18n.t("validation_blank")
},{
name: "password",
rules: "required",
message: i18n.t("validation_blank")
}]
el: $("form[name=loginForm]"),
rules: [
{
name: "login",
rules: "required",
message: i18n.t("validation_blank")
},
{
name: "password",
rules: "required",
message: i18n.t("validation_blank")
}
]
});
});
});

View File

@@ -14,28 +14,28 @@ define([
"backbone",
"bootstrap",
"multiselect"
], function($, _, i18n, Backbone, bootstrap, multiselect) {
var initialize = function() {
], function ($, _, i18n, Backbone, bootstrap, multiselect) {
var initialize = function () {
// close alerts
$(document).on("click", ".alert .alert-block-close a", function(e){
$(document).on("click", ".alert .alert-block-close a", function (e) {
e.preventDefault();
$(this).closest('.alert').alert('close');
return false;
});
$("select[multiple='multiple']").multiselect({
buttonWidth : "100%",
buttonWidth: "100%",
buttonClass: 'btn btn-inverse',
maxHeight: 185,
includeSelectAllOption: true,
selectAllValue: 'all',
selectAllText: i18n.t("all_collections"),
buttonText: function(options, select) {
buttonText: function (options, select) {
if (options.length === 0) {
return i18n.t("no_collection_selected") + '<b class="caret"></b>';
} else {
return i18n.t(
options.length === 1 ? "one_collection_selected": "collections_selected", {
options.length === 1 ? "one_collection_selected" : "collections_selected", {
postProcess: "sprintf",
sprintf: [options.length]
}) + ' <b class="caret"></b>';

View File

@@ -21,11 +21,11 @@ require.config({
"jquery.geonames": "../assets/geonames-server-jquery-plugin/jquery.geonames"
},
shim: {
bootstrap : ["jquery"],
bootstrap: ["jquery"],
jqueryui: {
deps: ["jquery"]
},
"jquery.geonames" : {
"jquery.geonames": {
deps: ['jquery', 'jqueryui'],
exports: '$.fn.geocompleter'
},

View File

@@ -12,24 +12,27 @@ require([
"i18n",
"apps/login/home/common",
"common/forms/views/form"
], function($, i18n, Common, ForgotPassWordForm) {
], function ($, i18n, Common, ForgotPassWordForm) {
Common.initialize();
i18n.init({
resGetPath: Common.languagePath,
useLocalStorage: true
}, function() {
}, function () {
new ForgotPassWordForm({
el : $("form[name=forgottenPasswordForm]"),
rules: [{
name: "email",
rules: "required",
message: i18n.t("validation_blank")
},{
name: "email",
rules: "valid_email",
message: i18n.t("validation_email")
}]
el: $("form[name=forgottenPasswordForm]"),
rules: [
{
name: "email",
rules: "required",
message: i18n.t("validation_blank")
},
{
name: "email",
rules: "valid_email",
message: i18n.t("validation_email")
}
]
});
});
});

View File

@@ -12,24 +12,27 @@ require([
"i18n",
"apps/login/home/common",
"common/forms/views/form"
], function($, i18n, Common, LoginForm) {
], function ($, i18n, Common, LoginForm) {
Common.initialize();
i18n.init({
resGetPath: Common.languagePath,
useLocalStorage: true
}, function() {
}, function () {
new LoginForm({
el : $("form[name=loginForm]"),
rules: [{
name: "login",
rules: "required",
message: i18n.t("validation_blank")
},{
name: "password",
rules: "required",
message: i18n.t("validation_blank")
}]
el: $("form[name=loginForm]"),
rules: [
{
name: "login",
rules: "required",
message: i18n.t("validation_blank")
},
{
name: "password",
rules: "required",
message: i18n.t("validation_blank")
}
]
});
});
});

View File

@@ -12,24 +12,27 @@ require([
"i18n",
"apps/login/home/common",
"common/forms/views/form"
], function($, i18n, Common, LoginForm) {
], function ($, i18n, Common, LoginForm) {
Common.initialize();
i18n.init({
resGetPath: Common.languagePath,
useLocalStorage: true
}, function() {
}, function () {
new LoginForm({
el : $("form[name=loginForm]"),
rules: [{
name: "login",
rules: "required",
message: i18n.t("validation_blank")
},{
name: "password",
rules: "required",
message: i18n.t("validation_blank")
}]
el: $("form[name=loginForm]"),
rules: [
{
name: "login",
rules: "required",
message: i18n.t("validation_blank")
},
{
name: "password",
rules: "required",
message: i18n.t("validation_blank")
}
]
});
});
});

View File

@@ -12,24 +12,27 @@ require([
"i18n",
"apps/login/home/common",
"common/forms/views/form"
], function($, i18n, Common, LoginForm) {
], function ($, i18n, Common, LoginForm) {
Common.initialize();
i18n.init({
resGetPath: Common.languagePath,
useLocalStorage: true
}, function() {
}, function () {
new LoginForm({
el : $("form[name=loginForm]"),
rules: [{
name: "login",
rules: "required",
message: i18n.t("validation_blank")
},{
name: "password",
rules: "required",
message: i18n.t("validation_blank")
}]
el: $("form[name=loginForm]"),
rules: [
{
name: "login",
rules: "required",
message: i18n.t("validation_blank")
},
{
name: "password",
rules: "required",
message: i18n.t("validation_blank")
}
]
});
});
});

View File

@@ -12,31 +12,35 @@ require([
"i18n",
"apps/login/home/common",
"common/forms/views/formType/passwordSetter"
], function($, i18n, Common, RenewPassword) {
], function ($, i18n, Common, RenewPassword) {
i18n.init({
resGetPath: Common.languagePath,
useLocalStorage: true
}, function() {
}, function () {
Common.initialize();
new RenewPassword({
el : $("form[name=passwordRenewForm]"),
rules: [{
name: "password[password]",
rules: "required",
message: i18n.t("validation_blank")
},{
name: "password[password]",
rules: "min_length[5]",
message: i18n.t("validation_length_min", {
postProcess: "sprintf",
sprintf: ["5"]
})
},{
name: "password[confirm]",
rules: "matches[password[password]]",
message: i18n.t("password_match")
}]
el: $("form[name=passwordRenewForm]"),
rules: [
{
name: "password[password]",
rules: "required",
message: i18n.t("validation_blank")
},
{
name: "password[password]",
rules: "min_length[5]",
message: i18n.t("validation_length_min", {
postProcess: "sprintf",
sprintf: ["5"]
})
},
{
name: "password[confirm]",
rules: "matches[password[password]]",
message: i18n.t("password_match")
}
]
});
});
});

View File

@@ -14,62 +14,70 @@ require([
"apps/login/home/common",
"common/forms/views/formType/passwordSetter",
"common/geonames"
], function($, i18n, Common, RegisterForm, geonames) {
], function ($, i18n, Common, RegisterForm, geonames) {
var fieldsConfiguration = [];
$.when.apply($, [
$.ajax({
url: '/login/registration-fields/',
success: function(config) {
success: function (config) {
fieldsConfiguration = config;
}
})
]).done(function(){
]).done(function () {
i18n.init({
resGetPath: Common.languagePath,
useLocalStorage: true
}, function() {
}, function () {
Common.initialize();
var rules = [{
name: "email",
rules: "required",
message: i18n.t("validation_blank")
},{
name: "email",
rules: "valid_email",
message: i18n.t("validation_email")
},{
name: "password[password]",
rules: "required",
message: i18n.t("validation_blank")
},{
name: "password[password]",
rules: "min_length[5]",
message: i18n.t("validation_length_min", {
postProcess: "sprintf",
sprintf: ["5"]
})
},{
name: "password[confirm]",
rules: "matches[password[password]]",
message: i18n.t("password_match")
},{
name: "accept-tou",
rules: "required",
message: i18n.t("accept_tou"),
type: "checkbox"
},{
name: "collections[]",
rules: "min_length[1]",
message: i18n.t("validation_choice_min", {
postProcess: "sprintf",
sprintf: ["1"]
}),
type: "multiple"
}];
var rules = [
{
name: "email",
rules: "required",
message: i18n.t("validation_blank")
},
{
name: "email",
rules: "valid_email",
message: i18n.t("validation_email")
},
{
name: "password[password]",
rules: "required",
message: i18n.t("validation_blank")
},
{
name: "password[password]",
rules: "min_length[5]",
message: i18n.t("validation_length_min", {
postProcess: "sprintf",
sprintf: ["5"]
})
},
{
name: "password[confirm]",
rules: "matches[password[password]]",
message: i18n.t("password_match")
},
{
name: "accept-tou",
rules: "required",
message: i18n.t("accept_tou"),
type: "checkbox"
},
{
name: "collections[]",
rules: "min_length[1]",
message: i18n.t("validation_choice_min", {
postProcess: "sprintf",
sprintf: ["1"]
}),
type: "multiple"
}
];
_.each(fieldsConfiguration, function(field) {
_.each(fieldsConfiguration, function (field) {
if (field.required) {
var rule = {
"name": field.name,
@@ -84,7 +92,7 @@ require([
var $form = $("form[name=registerForm]");
new RegisterForm({
el : $form,
el: $form,
rules: rules
});
@@ -92,7 +100,7 @@ require([
"server": $form.data("geonames-server-adress"),
"limit": 40,
"init-input": false,
"onInit": function(input, autoinput) {
"onInit": function (input, autoinput) {
// Set default name to geonameid-completer
autoinput.prop("name", "geonameid-completer");
}
@@ -106,7 +114,7 @@ require([
});
// On open menu calculate max-width
geocompleter.geocompleter("autocompleter", "on", "autocompleteopen", function(event, ui) {
geocompleter.geocompleter("autocompleter", "on", "autocompleteopen", function (event, ui) {
$(this).autocomplete("widget").css("min-width", geocompleter.closest(".input-table").outerWidth());
});
});

View File

@@ -13,7 +13,7 @@ require([
"i18n",
"apps/login/home/common",
"common/forms/views/form"
], function($, i18n, Common, RegisterForm) {
], function ($, i18n, Common, RegisterForm) {
Common.initialize();
var fieldsConfiguration = [];
@@ -21,54 +21,62 @@ require([
$.when.apply($, [
$.ajax({
url: '/login/registration-fields/',
success: function(config) {
success: function (config) {
fieldsConfiguration = config;
}
})
]).done(function(){
]).done(function () {
i18n.init({
resGetPath: Common.languagePath,
useLocalStorage: true
}, function() {
var rules = [{
name: "email",
rules: "required",
message: i18n.t("validation_blank")
},{
name: "email",
rules: "valid_email",
message: i18n.t("validation_email")
},{
name: "password",
rules: "required",
message: i18n.t("validation_blank")
},{
name: "password",
rules: "min_length[5]",
message: i18n.t("validation_length_min", {
postProcess: "sprintf",
sprintf: ["5"]
})
},{
name: "passwordConfirm",
rules: "matches[password]",
message: i18n.t("password_match")
},{
name: "accept-tou",
rules: "required",
message: i18n.t("accept_tou"),
type: "checkbox"
},{
name: "collections[]",
rules: "min_length[1]",
message: i18n.t("validation_choice_min", {
postProcess: "sprintf",
sprintf: ["1"]
}),
type: "multiple"
}];
}, function () {
var rules = [
{
name: "email",
rules: "required",
message: i18n.t("validation_blank")
},
{
name: "email",
rules: "valid_email",
message: i18n.t("validation_email")
},
{
name: "password",
rules: "required",
message: i18n.t("validation_blank")
},
{
name: "password",
rules: "min_length[5]",
message: i18n.t("validation_length_min", {
postProcess: "sprintf",
sprintf: ["5"]
})
},
{
name: "passwordConfirm",
rules: "matches[password]",
message: i18n.t("password_match")
},
{
name: "accept-tou",
rules: "required",
message: i18n.t("accept_tou"),
type: "checkbox"
},
{
name: "collections[]",
rules: "min_length[1]",
message: i18n.t("validation_choice_min", {
postProcess: "sprintf",
sprintf: ["1"]
}),
type: "multiple"
}
];
_.each(fieldsConfiguration, function(field) {
_.each(fieldsConfiguration, function (field) {
if (field.required) {
var rule = {
"name": field.name,
@@ -81,7 +89,7 @@ require([
});
new RegisterForm({
el : $("form[name=registerForm]"),
el: $("form[name=registerForm]"),
rules: rules
});
});

View File

@@ -12,36 +12,41 @@ require([
"i18n",
"apps/login/home/common",
"common/forms/views/form"
], function($, i18n, Common, RenewEmail) {
], function ($, i18n, Common, RenewEmail) {
i18n.init({
resGetPath: Common.languagePath,
useLocalStorage: true
}, function() {
}, function () {
Common.initialize();
new RenewEmail({
el : $("form[name=changeEmail]"),
el: $("form[name=changeEmail]"),
errorTemplate: "#field_errors_block",
onRenderError: function(name, $el) {
onRenderError: function (name, $el) {
$el.closest(".control-group").addClass("error");
},
rules: [{
name: "form_password",
rules: "required",
message: i18n.t("validation_blank")
},{
name: "form_email",
rules: "required",
message: i18n.t("validation_blank")
},{
name: "form_email",
rules: "email",
message: i18n.t("validation_email")
},{
name: "form_email_confirm",
rules: "matches[form_email]",
message: i18n.t("email_match")
}]
rules: [
{
name: "form_password",
rules: "required",
message: i18n.t("validation_blank")
},
{
name: "form_email",
rules: "required",
message: i18n.t("validation_blank")
},
{
name: "form_email",
rules: "email",
message: i18n.t("validation_email")
},
{
name: "form_email_confirm",
rules: "matches[form_email]",
message: i18n.t("email_match")
}
]
});
});
});

View File

@@ -12,35 +12,40 @@ require([
"i18n",
"apps/login/home/common",
"common/forms/views/formType/passwordSetter"
], function($, i18n, Common, RenewPassword) {
], function ($, i18n, Common, RenewPassword) {
i18n.init({
resGetPath: Common.languagePath,
useLocalStorage: true
}, function() {
}, function () {
Common.initialize();
new RenewPassword({
el : $("form[name=passwordChangeForm]"),
rules: [{
name: "oldPassword",
rules: "required",
message: i18n.t("validation_blank")
},{
name: "password[password]",
rules: "required",
message: i18n.t("validation_blank")
},{
name: "password[password]",
rules: "min_length[5]",
message: i18n.t("validation_length_min", {
postProcess: "sprintf",
sprintf: ["5"]
})
},{
name: "password[confirm]",
rules: "matches[password[password]]",
message: i18n.t("password_match")
}]
el: $("form[name=passwordChangeForm]"),
rules: [
{
name: "oldPassword",
rules: "required",
message: i18n.t("validation_blank")
},
{
name: "password[password]",
rules: "required",
message: i18n.t("validation_blank")
},
{
name: "password[password]",
rules: "min_length[5]",
message: i18n.t("validation_length_min", {
postProcess: "sprintf",
sprintf: ["5"]
})
},
{
name: "password[confirm]",
rules: "matches[password[password]]",
message: i18n.t("password_match")
}
]
});
});
});

View File

@@ -11,8 +11,8 @@ define([
"jquery",
"underscore",
"backbone"
], function($, _, Backbone) {
var FormValidator = function(rules, handlers) {
], function ($, _, Backbone) {
var FormValidator = function (rules, handlers) {
// rules setted by user
this.rules = rules || [];
// custom callbacks
@@ -22,7 +22,7 @@ define([
var self = this;
_.each(this.rules, function(field) {
_.each(this.rules, function (field) {
if ("name" in field && "rules" in field) {
self._addField(field);
}
@@ -30,16 +30,16 @@ define([
};
// Validate method, argument is the serialize form
FormValidator.prototype.validate = function(inputs) {
FormValidator.prototype.validate = function (inputs) {
var self = this;
// possible errors
this.errors = [];
// inputs present in form
this.inputs = {};
_.each(_.groupBy(inputs, function(input){
_.each(_.groupBy(inputs, function (input) {
return input.name;
}), function(fields, name) {
}), function (fields, name) {
self.inputs[name] = fields;
});
@@ -48,19 +48,19 @@ define([
return this;
};
FormValidator.prototype.getErrors = function() {
FormValidator.prototype.getErrors = function () {
return this.errors;
};
FormValidator.prototype.hasErrors = function() {
FormValidator.prototype.hasErrors = function () {
return this.errors.length > 0;
};
FormValidator.prototype.getRules = function() {
FormValidator.prototype.getRules = function () {
return this.rules;
};
FormValidator.prototype._addField = function(field) {
FormValidator.prototype._addField = function (field) {
this.fields.push({
name: field.name,
rules: field.rules,
@@ -70,15 +70,15 @@ define([
});
};
FormValidator.prototype._validateForm = function() {
FormValidator.prototype._validateForm = function () {
var self = this;
this.errors = [];
_.each(this.fields, function(field){
_.each(this.fields, function (field) {
if (_.has(self.inputs, field.name)) {
// values can be multiple
var values = [];
_.each(self.inputs[field.name], function(field){
_.each(self.inputs[field.name], function (field) {
return values.push(field.value);
});
@@ -92,13 +92,13 @@ define([
});
};
FormValidator.prototype._validateField = function(field) {
FormValidator.prototype._validateField = function (field) {
var self = this;
var ruleRegex = /^(.+?)\[(.+)\]$/;
var rules = field.rules.split('|');
// Run through the rules and execute the validation methods as needed
_.every(rules, function(method) {
_.every(rules, function (method) {
var param = null;
var failed = false;
var parts = ruleRegex.exec(method);
@@ -141,32 +141,32 @@ define([
};
FormValidator.prototype.Regexp = {
numericRegex : /^[0-9]+$/,
integerRegex : /^\-?[0-9]+$/,
decimalRegex : /^\-?[0-9]*\.?[0-9]+$/,
emailRegex : /^[^@]+@[^@]+\.[^@]+$/,
alphaRegex : /^[a-z]+$/i,
alphaNumericRegex : /^[a-z0-9]+$/i,
alphaDashRegex : /^[a-z0-9_\-]+$/i,
naturalRegex : /^[0-9]+$/i,
naturalNoZeroRegex : /^[1-9][0-9]*$/i,
numericRegex: /^[0-9]+$/,
integerRegex: /^\-?[0-9]+$/,
decimalRegex: /^\-?[0-9]*\.?[0-9]+$/,
emailRegex: /^[^@]+@[^@]+\.[^@]+$/,
alphaRegex: /^[a-z]+$/i,
alphaNumericRegex: /^[a-z0-9]+$/i,
alphaDashRegex: /^[a-z0-9_\-]+$/i,
naturalRegex: /^[0-9]+$/i,
naturalNoZeroRegex: /^[1-9][0-9]*$/i,
// IP v6 a v4 or hostname, by Mikulas Dite see http://stackoverflow.com/a/9209720/96656
ipRegex : /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$|^(?:(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){6})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:::(?:(?:(?:[0-9a-fA-F]{1,4})):){5})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})))?::(?:(?:(?:[0-9a-fA-F]{1,4})):){4})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,1}(?:(?:[0-9a-fA-F]{1,4})))?::(?:(?:(?:[0-9a-fA-F]{1,4})):){3})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,2}(?:(?:[0-9a-fA-F]{1,4})))?::(?:(?:(?:[0-9a-fA-F]{1,4})):){2})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,3}(?:(?:[0-9a-fA-F]{1,4})))?::(?:(?:[0-9a-fA-F]{1,4})):)(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,4}(?:(?:[0-9a-fA-F]{1,4})))?::)(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,5}(?:(?:[0-9a-fA-F]{1,4})))?::)(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,6}(?:(?:[0-9a-fA-F]{1,4})))?::))))$/i,
numericDashRegex : /^[\d\-\s]+$/,
urlRegex : /^((http|https):\/\/(\w+:{0,1}\w*@)?(\S+)|)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$/
ipRegex: /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$|^(?:(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){6})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:::(?:(?:(?:[0-9a-fA-F]{1,4})):){5})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})))?::(?:(?:(?:[0-9a-fA-F]{1,4})):){4})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,1}(?:(?:[0-9a-fA-F]{1,4})))?::(?:(?:(?:[0-9a-fA-F]{1,4})):){3})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,2}(?:(?:[0-9a-fA-F]{1,4})))?::(?:(?:(?:[0-9a-fA-F]{1,4})):){2})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,3}(?:(?:[0-9a-fA-F]{1,4})))?::(?:(?:[0-9a-fA-F]{1,4})):)(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,4}(?:(?:[0-9a-fA-F]{1,4})))?::)(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,5}(?:(?:[0-9a-fA-F]{1,4})))?::)(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,6}(?:(?:[0-9a-fA-F]{1,4})))?::))))$/i,
numericDashRegex: /^[\d\-\s]+$/,
urlRegex: /^((http|https):\/\/(\w+:{0,1}\w*@)?(\S+)|)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$/
};
// Object containing all of the validation hooks
FormValidator.prototype._hooks = {
"required": function(field) {
"required": function (field) {
var value = field.value;
return (value !== null && value !== '');
},
"equal": function(field, defaultName) {
"equal": function (field, defaultName) {
return field.value === defaultName;
},
"matches": function(field, matchName) {
"matches": function (field, matchName) {
if (typeof this.inputs[matchName] === "undefined") {
return false;
}
@@ -179,10 +179,10 @@ define([
return false;
},
"valid_email": function(field) {
"valid_email": function (field) {
return this.Regexp.emailRegex.test(field.value);
},
"valid_emails": function(field) {
"valid_emails": function (field) {
var result = field.value.split(",");
for (var i = 0; i < result.length; i++) {
@@ -193,9 +193,11 @@ define([
return true;
},
"min_length": function(field, length) {
"min_length": function (field, length) {
if (field.type === "multiple") {
return _.filter(field.value.split(","), function(value){ return value !== ""; }).length >= parseInt(length, 10)
return _.filter(field.value.split(","),function (value) {
return value !== "";
}).length >= parseInt(length, 10)
}
if (!this.Regexp.numericRegex.test(length)) {
@@ -204,9 +206,11 @@ define([
return (field.value.length >= parseInt(length, 10));
},
"max_length": function(field, length) {
"max_length": function (field, length) {
if (field.type === "multiple") {
return _.filter(field.value.split(","), function(value){ return value !== ""; }).length <= parseInt(length, 10)
return _.filter(field.value.split(","),function (value) {
return value !== "";
}).length <= parseInt(length, 10)
}
if (!this.Regexp.numericRegex.test(length)) {
@@ -215,9 +219,11 @@ define([
return (field.value.length <= parseInt(length, 10));
},
"exact_length": function(field, length) {
"exact_length": function (field, length) {
if (field.type === "multiple") {
return _.filter(field.value.split(","), function(value){ return value !== ""; }).length === parseInt(length, 10)
return _.filter(field.value.split(","),function (value) {
return value !== "";
}).length === parseInt(length, 10)
}
if (!this.Regexp.numericRegex.test(length)) {
@@ -226,48 +232,48 @@ define([
return (field.value.length === parseInt(length, 10));
},
"greater_than": function(field, param) {
"greater_than": function (field, param) {
if (!this.Regexp.decimalRegex.test(field.value)) {
return false;
}
return (parseFloat(field.value) > parseFloat(param));
},
"less_than": function(field, param) {
"less_than": function (field, param) {
if (!this.Regexp.decimalRegex.test(field.value)) {
return false;
}
return (parseFloat(field.value) < parseFloat(param));
},
"alpha": function(field) {
"alpha": function (field) {
return (this.Regexp.alphaRegex.test(field.value));
},
"alpha_numeric": function(field) {
"alpha_numeric": function (field) {
return (this.Regexp.alphaNumericRegex.test(field.value));
},
"alpha_dash": function(field) {
"alpha_dash": function (field) {
return (this.Regexp.alphaDashRegex.test(field.value));
},
"numeric": function(field) {
"numeric": function (field) {
return (this.Regexp.numericRegex.test(field.value));
},
"integer": function(field) {
"integer": function (field) {
return (this.Regexp.integerRegex.test(field.value));
},
"decimal": function(field) {
"decimal": function (field) {
return (this.Regexp.decimalRegex.test(field.value));
},
"is_natural": function(field) {
"is_natural": function (field) {
return (this.Regexp.naturalRegex.test(field.value));
},
"is_natural_no_zero": function(field) {
"is_natural_no_zero": function (field) {
return (this.Regexp.naturalNoZeroRegex.test(field.value));
},
"valid_ip": function(field) {
"valid_ip": function (field) {
return (this.Regexp.ipRegex.test(field.value));
},
"valid_url": function(field) {
"valid_url": function (field) {
return (this.Regexp.urlRegex.test(field.value));
}
};

View File

@@ -11,11 +11,11 @@ define([
"jquery",
"underscore",
"backbone"
], function($, _, Backbone) {
], function ($, _, Backbone) {
var ErrorView = Backbone.View.extend({
tagName: "div",
initialize: function(options) {
options = options || {};
initialize: function (options) {
options = options || {};
if (false === "name" in options) {
throw "Missing name attribute in error view";
@@ -28,11 +28,11 @@ define([
this.name = options.name;
this.errorTemplate = options.errorTemplate;
this.errors = options.errors || {};
this.errors = options.errors || {};
this.onRenderError = options.onRenderError || null;
},
render: function() {
if (this.errors.length > 0 ) {
render: function () {
if (this.errors.length > 0) {
var template = _.template($(this.errorTemplate).html(), {
errors: this.errors
});
@@ -54,7 +54,7 @@ define([
return this;
},
reset: function() {
reset: function () {
this.$el.empty();
}
});

View File

@@ -14,13 +14,13 @@ define([
"bootstrap",
"common/forms/validator",
"common/forms/views/input"
], function($, _, Backbone, bootstrap, Validator, InputView) {
], function ($, _, Backbone, bootstrap, Validator, InputView) {
var Form = Backbone.View.extend({
events: {
"submit": "_onSubmit"
},
initialize: function(options) {
options = options || {};
initialize: function (options) {
options = options || {};
var self = this;
@@ -49,7 +49,7 @@ define([
// cancel submit
event.preventDefault();
// group errors by input
_.each(_.groupBy(this.validator.getErrors(), function(error){
_.each(_.groupBy(this.validator.getErrors(), function (error) {
return error.name;
}), function (errors, name) {
// show new errors in the views
@@ -66,17 +66,17 @@ define([
});
}
},
_resetInputErrors: function() {
_.each(this.inputViews, function(view) {
_resetInputErrors: function () {
_.each(this.inputViews, function (view) {
view.resetErrors();
});
},
_addInputView: function(input) {
_addInputView: function (input) {
var name = input.name;
this.inputViews[name] = new InputView({
name: name,
el : $("input[name='"+name+"'], select[name='"+name+"'], textarea[name='"+name+"']", this.$el).first().closest("div"),
el: $("input[name='" + name + "'], select[name='" + name + "'], textarea[name='" + name + "']", this.$el).first().closest("div"),
errorTemplate: this.errorTemplate,
onRenderError: this.onRenderError
});

View File

@@ -14,14 +14,14 @@ define([
"backbone",
"bootstrap",
"common/forms/views/form"
], function($, _, i18n, Backbone, bootstrap, FormView) {
], function ($, _, i18n, Backbone, bootstrap, FormView) {
var PasswordSetterForm = FormView.extend({
events: function(){
return _.extend({},FormView.prototype.events,{
'keyup input[type=password]' : 'onPasswordKeyup'
events: function () {
return _.extend({}, FormView.prototype.events, {
'keyup input[type=password]': 'onPasswordKeyup'
});
},
onPasswordKeyup : function(event) {
onPasswordKeyup: function (event) {
var input = $(event.target);
var password = input.val();
var inputView = this.inputViews[input.attr("name")];
@@ -34,7 +34,7 @@ define([
};
var result = "";
if (password.length > 0 ) {
if (password.length > 0) {
var passMeter = zxcvbn(input.val());
switch (passMeter.score) {

View File

@@ -13,10 +13,10 @@ define([
"backbone",
"common/forms/views/error",
"common/multiviews"
], function($, _, Backbone, ErrorView, MultiViews) {
], function ($, _, Backbone, ErrorView, MultiViews) {
var InputView = Backbone.View.extend(_.extend({}, MultiViews, {
initialize: function(options) {
options = options || {};
initialize: function (options) {
options = options || {};
if (false === "name" in options) {
throw "Missing name attribute in input view";
@@ -35,7 +35,7 @@ define([
});
},
render: function () {
this._assignView({".error-view" : this.errorView});
this._assignView({".error-view": this.errorView});
},
showErrors: function (errors) {
this.render();

View File

@@ -1,4 +1,5 @@
;(function (root, factory) {
;
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define([''], factory);
} else {
@@ -6,33 +7,33 @@
}
}(this, function () {
return {
init: function($field, options) {
init: function ($field, options) {
var geocompleter = $field.geocompleter(options);
// On focus add select-state
geocompleter.geocompleter("autocompleter", "on", "autocompletefocus", function(event, ui) {
geocompleter.geocompleter("autocompleter", "on", "autocompletefocus", function (event, ui) {
$("li", $(event.originalEvent.target)).closest("li").removeClass("selected");
$("a.ui-state-active, a.ui-state-hover, a.ui-state-focus", $(event.originalEvent.target)).closest("li").addClass("selected");
});
// On search request add loading-state
geocompleter.geocompleter("autocompleter", "on", "autocompletesearch", function(event, ui) {
geocompleter.geocompleter("autocompleter", "on", "autocompletesearch", function (event, ui) {
$(this).addClass('input-loading');
$(this).removeClass('input-error');
});
// On response remove loading-state
geocompleter.geocompleter("autocompleter", "on", "autocompleteresponse", function(event, ui) {
geocompleter.geocompleter("autocompleter", "on", "autocompleteresponse", function (event, ui) {
$(this).removeClass('input-loading');
});
// On close menu remove loading-state
geocompleter.geocompleter("autocompleter", "on", "autocompleteclose", function(event, ui) {
geocompleter.geocompleter("autocompleter", "on", "autocompleteclose", function (event, ui) {
$(this).removeClass('input-loading');
});
// On request error add error-state
geocompleter.geocompleter("autocompleter", "on", "geotocompleter.request.error", function(jqXhr, status, error) {
geocompleter.geocompleter("autocompleter", "on", "geotocompleter.request.error", function (jqXhr, status, error) {
$(this).removeClass('input-loading');
$(this).addClass('input-error');
});

View File

@@ -11,10 +11,10 @@ define([
"jquery",
"underscore",
"backbone"
], function($, _, Backbone) {
], function ($, _, Backbone) {
return {
// bind a subview to a DOM element
"_assignView": function(selector, view) {
"_assignView": function (selector, view) {
var selectors;
if (_.isObject(selector)) {
selectors = selector;
@@ -23,7 +23,7 @@ define([
selectors[selector] = view;
}
if (!selectors) return;
_.each(selectors, function(view, selector) {
_.each(selectors, function (view, selector) {
view.setElement(this.$(selector)).render();
}, this);
}

View File

@@ -10,7 +10,7 @@
define([
"underscore",
"backbone"
], function(_, Backbone) {
], function (_, Backbone) {
var DcFieldModel = Backbone.Model.extend({
urlRoot: function () {
return "/admin/fields/dc-fields";

View File

@@ -10,16 +10,16 @@
define([
"underscore",
"backbone"
], function(_, Backbone) {
], function (_, Backbone) {
var FieldModel = Backbone.Model.extend({
initialize : function(attributes, options) {
initialize: function (attributes, options) {
attributes = attributes || {};
if (typeof attributes === "object" && false === "sbas-id" in attributes) {
throw "You must set a sbas id";
}
},
urlRoot: function () {
return "/admin/fields/"+ this.get("sbas-id") +"/fields";
return "/admin/fields/" + this.get("sbas-id") + "/fields";
},
defaults: {
"business": false,
@@ -36,10 +36,10 @@ define([
"vocabulary-type": null,
"vocabulary-restricted": false,
"labels": {
"fr" : "",
"en" : "",
"de" : "",
"nl" : ""
"fr": "",
"en": "",
"de": "",
"nl": ""
}
}
});

View File

@@ -10,7 +10,7 @@
define([
"underscore",
"backbone"
], function(_, Backbone) {
], function (_, Backbone) {
var VocabularyModel = Backbone.Model.extend({
urlRoot: function () {
return "/admin/fields/vocabularies";

View File

@@ -1,4 +1,4 @@
define(["chai"], function(shai) {
define(["chai"], function (shai) {
window.expect = shai.expect;
window.assert = shai.assert;
});

View File

@@ -18,7 +18,7 @@ require.config({
bootstrap: "../skins/build/bootstrap/js/bootstrap.min"
},
shim: {
bootstrap : ["jquery"],
bootstrap: ["jquery"],
jqueryui: {
deps: ["jquery"]
},
@@ -39,11 +39,12 @@ mocha.setup({
globals: ['js-fixtures']
});
console = window.console || function() {};
console = window.console || function () {
};
window.notrack = true;
var runMocha = function() {
var runMocha = function () {
if (window.mochaPhantomJS) {
mochaPhantomJS.run();
} else {

View File

@@ -15,24 +15,7 @@ define([
'apps/admin/fields/views/modal',
'apps/admin/fields/views/save',
'apps/admin/fields/views/dcField'
], function(
chai,
fixtures,
$,
App,
FieldModel,
FieldCollection,
DcFieldCollection,
VocabularyCollection,
SingleItemView,
ListItemView,
AlertView,
EditView,
FieldErrorView,
ModalView,
SaveView,
DcFieldView
) {
], function (chai, fixtures, $, App, FieldModel, FieldCollection, DcFieldCollection, VocabularyCollection, SingleItemView, ListItemView, AlertView, EditView, FieldErrorView, ModalView, SaveView, DcFieldView) {
var expect = chai.expect;
var assert = chai.assert;
var should = chai.should();
@@ -44,36 +27,36 @@ define([
App.initialize();
describe("Admin field", function() {
describe("Initialization", function() {
it("should create a global variable", function() {
describe("Admin field", function () {
describe("Initialization", function () {
it("should create a global variable", function () {
should.exist(AdminFieldApp);
});
});
describe("Collections", function() {
describe("DcField Collection", function() {
beforeEach(function() {
describe("Collections", function () {
describe("DcField Collection", function () {
beforeEach(function () {
this.collection = new DcFieldCollection([]);
});
it("should set collection url according to provided 'sbas-id'", function() {
it("should set collection url according to provided 'sbas-id'", function () {
this.collection.url().should.equal("/admin/fields/dc-fields");
});
});
describe("Vocabulary Collection", function() {
beforeEach(function() {
describe("Vocabulary Collection", function () {
beforeEach(function () {
this.collection = new VocabularyCollection([]);
});
it("should set collection url according to provided 'sbas-id'", function() {
it("should set collection url according to provided 'sbas-id'", function () {
this.collection.url().should.equal("/admin/fields/vocabularies");
});
});
describe("Field Collection", function() {
beforeEach(function() {
describe("Field Collection", function () {
beforeEach(function () {
this.collection = new FieldCollection([
{"id": 1, "sbas-id": sbasId, "name": "Categorie", "tag": "XMP:Categorie"},
{"id": 2, "sbas-id": sbasId, "name": "Object", "tag": "XMP:Object"}
@@ -82,24 +65,24 @@ define([
});
});
describe("Initialization", function() {
it("should throw an exception if 'sbas_id' is missing", function() {
expect(function() {
describe("Initialization", function () {
it("should throw an exception if 'sbas_id' is missing", function () {
expect(function () {
new FieldCollection([]);
}).to.throw("You must set a sbas id");
});
it("should set collection url according to provided 'sbas-id'", function() {
this.collection.url().should.equal("/admin/fields/"+sbasId+"/fields");
it("should set collection url according to provided 'sbas-id'", function () {
this.collection.url().should.equal("/admin/fields/" + sbasId + "/fields");
});
});
describe("Methods", function() {
it("should retrieve categorie item if searching terms begins with 'cat'", function() {
describe("Methods", function () {
it("should retrieve categorie item if searching terms begins with 'cat'", function () {
this.collection.search('Cat')._wrapped.length.should.equal(1);
});
it("should retrieve previous and next index for given model", function() {
it("should retrieve previous and next index for given model", function () {
expect(this.collection.previousIndex(this.collection.first())).to.be.null;
this.collection.nextIndex(this.collection.first()).should.equal(1);
this.collection.previousIndex(this.collection.last()).should.equal(0);
@@ -109,29 +92,29 @@ define([
});
});
describe("Views", function() {
describe("Single Item Views", function() {
beforeEach(function() {
describe("Views", function () {
describe("Single Item Views", function () {
beforeEach(function () {
this.field = new FieldModel({"sbas-id": sbasId, "name": "Categorie", "tag": "XMP:Categorie"});
this.view = new SingleItemView({model: this.field});
});
it("render() should return the view object", function() {
it("render() should return the view object", function () {
this.view.render().should.equal(this.view);
});
it("should render as a LI element", function() {
it("should render as a LI element", function () {
this.view.render().el.nodeName.should.equal("LI");
});
it("should render as a LI element with proper properties", function() {
it("should render as a LI element with proper properties", function () {
this.view.render().$el.find('.field-name').html().should.equal("Categorie");
this.view.render().$el.find('.field-tag').html().should.equal("XMP:Categorie");
});
});
describe("List Item Views", function() {
beforeEach(function() {
describe("List Item Views", function () {
beforeEach(function () {
this.collection = new FieldCollection([
{"sbas-id": sbasId, "name": "Categorie", "tag": "XMP:Categorie"},
{"sbas-id": sbasId, "name": "Object", "tag": "XMP:Object"}
@@ -145,45 +128,47 @@ define([
});
});
it("render() should return the view object", function() {
it("render() should return the view object", function () {
this.view.render().should.equal(this.view);
});
it("should render as a DIV block", function() {
it("should render as a DIV block", function () {
this.view.render().el.nodeName.should.equal("DIV");
});
it("should include list items for all models in collection", function() {
it("should include list items for all models in collection", function () {
this.view.render();
this.view.$el.find("li").should.have.length(2);
});
});
describe("Alert Views", function() {
beforeEach(function() {
describe("Alert Views", function () {
beforeEach(function () {
this.view = new AlertView({alert: "info", message: "Hello world!"});
});
it("render() should return the view object", function() {
it("render() should return the view object", function () {
this.view.render().should.equal(this.view);
});
it("should render as a DIV element", function() {
it("should render as a DIV element", function () {
this.view.render().el.nodeName.should.equal("DIV");
});
});
describe("DcField Views", function() {
beforeEach(function() {
this.collection = new DcFieldCollection([{
"label": "Contributor",
"definition": "An entity responsible for making contributions to the resource.",
"URI": "http://dublincore.org/documents/dces/#contributor"
}, {
"label": "Coverage",
"definition": "The spatial or temporal topic of the resource, the spatial applicability of the resource,\n or the jurisdiction under which the resource\n is relevant.",
"URI": "http://dublincore.org/documents/dces/#coverage"
}
describe("DcField Views", function () {
beforeEach(function () {
this.collection = new DcFieldCollection([
{
"label": "Contributor",
"definition": "An entity responsible for making contributions to the resource.",
"URI": "http://dublincore.org/documents/dces/#contributor"
},
{
"label": "Coverage",
"definition": "The spatial or temporal topic of the resource, the spatial applicability of the resource,\n or the jurisdiction under which the resource\n is relevant.",
"URI": "http://dublincore.org/documents/dces/#coverage"
}
]);
var model = new FieldModel({"id": 1, "sbas-id": sbasId, "name": "Categorie", "tag": "XMP:Categorie"});
@@ -194,17 +179,17 @@ define([
});
});
it("render() should return the view object", function() {
it("render() should return the view object", function () {
this.view.render().should.equal(this.view);
});
it("should render as a DIV element", function() {
it("should render as a DIV element", function () {
this.view.render().el.nodeName.should.equal("DIV");
});
});
describe("Edit Views", function() {
beforeEach(function() {
describe("Edit Views", function () {
beforeEach(function () {
var model = new FieldModel({"id": 1, "sbas-id": sbasId, "name": "Categorie", "tag": "XMP:Categorie"});
this.view = new EditView({"model": model});
@@ -227,24 +212,24 @@ define([
AdminFieldApp.fieldListView.render();
});
it("render() should return the view object", function() {
it("render() should return the view object", function () {
this.view.render().should.equal(this.view);
});
it("should render as a DIV element", function() {
it("should render as a DIV element", function () {
this.view.render().el.nodeName.should.equal("DIV");
});
it("should not render an error message if provided tag is empty", function() {
var view = this.view.render();
it("should not render an error message if provided tag is empty", function () {
var view = this.view.render();
view.$('input#tag').val("").blur();
assert.isFalse(view.$('input#tag').closest(".control-group").hasClass("error"));
});
it("should uncheck vocabulary restricted if provided vocabulary is empty", function() {
var view = this.view.render();
it("should uncheck vocabulary restricted if provided vocabulary is empty", function () {
var view = this.view.render();
view.$('input#vocabulary-restricted').attr("checked", true);
view.$('input#vocabulary-type option').first().attr("selected", true);
@@ -253,22 +238,22 @@ define([
});
});
describe("FieldError Views", function() {
beforeEach(function() {
describe("FieldError Views", function () {
beforeEach(function () {
this.view = new FieldErrorView();
});
it("render() should return the view object", function() {
it("render() should return the view object", function () {
this.view.render().should.equal(this.view);
});
it("should render as a DIV element", function() {
it("should render as a DIV element", function () {
this.view.render().el.nodeName.should.equal("DIV");
});
});
describe("Modal Views", function() {
beforeEach(function() {
describe("Modal Views", function () {
beforeEach(function () {
var model = new FieldModel({"id": 1, "sbas-id": sbasId, "name": "Categorie", "tag": "XMP:Categorie"});
this.view = new ModalView({
@@ -277,34 +262,34 @@ define([
});
});
it("render() should return the view object", function() {
it("render() should return the view object", function () {
this.view.render().should.equal(this.view);
this.view.remove();
});
it("should render as a DIV element", function() {
it("should render as a DIV element", function () {
this.view.render().el.nodeName.should.equal("DIV");
this.view.remove();
});
});
describe("Save Views", function() {
beforeEach(function() {
describe("Save Views", function () {
beforeEach(function () {
this.view = new SaveView();
});
it("render() should return the view object", function() {
it("render() should return the view object", function () {
this.view.render().should.equal(this.view);
});
it("should render as a DIV element", function() {
it("should render as a DIV element", function () {
this.view.render().el.nodeName.should.equal("DIV");
});
});
});
describe("Edge cases", function() {
beforeEach(function() {
describe("Edge cases", function () {
beforeEach(function () {
AdminFieldApp.fieldsCollection.reset();
AdminFieldApp.fieldsCollection.add({"sbas-id": sbasId, "name": "Categorie", "tag": "XMP:Categorie"});
AdminFieldApp.dcFieldsCollection.add({
@@ -324,7 +309,7 @@ define([
AdminFieldApp.fieldListView.render();
});
it("should update collection when model change", function() {
it("should update collection when model change", function () {
AdminFieldApp.fieldListView.itemViews[0].clickAction();
AdminFieldApp.fieldEditView.model.set({
"name": "new name"
@@ -332,15 +317,17 @@ define([
assert.equal(AdminFieldApp.fieldListView.itemViews[0].model.get('name'), "new name", 'model is updated');
});
it("should update edit view when clicking on single element", function() {
it("should update edit view when clicking on single element", function () {
AdminFieldApp.fieldListView.itemViews[0].clickAction();
should.exist(AdminFieldApp.fieldEditView);
assert.equal(AdminFieldApp.fieldEditView.model, AdminFieldApp.fieldListView.collection.first(), 'model is updated');
});
it("should reorder collection on drop action", function() {
var ui = {item: {index: function() {return 2;}}};
AdminFieldApp.fieldListView.itemViews[0].dropAction({},ui);
it("should reorder collection on drop action", function () {
var ui = {item: {index: function () {
return 2;
}}};
AdminFieldApp.fieldListView.itemViews[0].dropAction({}, ui);
assert.equal(AdminFieldApp.fieldListView.collection.last().get('sorter'), 3, 'model is updated');
});
});

View File

@@ -5,14 +5,7 @@ define([
'common/forms/views/form',
'common/forms/views/input',
'common/forms/views/error'
], function(
chai,
fixtures,
$,
FormView,
InputView,
ErrorView
) {
], function (chai, fixtures, $, FormView, InputView, ErrorView) {
var expect = chai.expect;
var assert = chai.assert;
var should = chai.should();
@@ -20,10 +13,12 @@ define([
fixtures.path = 'fixtures';
$("body").append(fixtures.read('home/login/form', 'home/login/templates'));
describe("Login Home", function() {
describe("Form View", function() {
it("should initialize validator with proper rules", function() {
var rules = [{name: "hello",rules: "simple_rules"}];
describe("Login Home", function () {
describe("Form View", function () {
it("should initialize validator with proper rules", function () {
var rules = [
{name: "hello", rules: "simple_rules"}
];
var form = new FormView({
el: $('form[name=loginForm]'),
rules: rules
@@ -31,7 +26,7 @@ define([
form.validator.getRules().should.equal(rules);
});
it("should initialize input views", function() {
it("should initialize input views", function () {
var form = new FormView({
el: $('form[name=loginForm]')
});
@@ -39,7 +34,7 @@ define([
Object.keys(form.inputViews).length.should.equal(5);
});
it("should initialize errors", function() {
it("should initialize errors", function () {
var form = new FormView({
el: $('form[name=loginForm]')
});
@@ -47,14 +42,16 @@ define([
assert.isTrue(_.isEmpty(form.validator.getErrors()));
});
it("should render errors on submit", function() {
it("should render errors on submit", function () {
var form = new FormView({
el: $('form[name=loginForm]'),
rules: [{
"name": "login",
"rules": "required",
"message" : "something is wrong"
}]
rules: [
{
"name": "login",
"rules": "required",
"message": "something is wrong"
}
]
});
form._onSubmit(document.createEvent("Event"));
@@ -62,8 +59,8 @@ define([
});
});
describe("Input View", function() {
it("should initialize error view", function() {
describe("Input View", function () {
it("should initialize error view", function () {
var input = new InputView({
"name": "test",
"errorTemplate": "#field_errors"
@@ -72,9 +69,9 @@ define([
});
});
describe("Error View", function() {
it("should render errors", function() {
var error ={
describe("Error View", function () {
it("should render errors", function () {
var error = {
name: "test",
message: "Something is wrong"
};
@@ -82,7 +79,7 @@ define([
var errorView = new ErrorView({
"name": "test",
"errors": [error],
"el" : $(".error-view").first(),
"el": $(".error-view").first(),
"errorTemplate": "#field_errors"
});
@@ -91,7 +88,7 @@ define([
assert.isTrue(errorView.$el.html().indexOf(error.message) !== -1);
});
it("should empty errors content if there are no errors", function() {
it("should empty errors content if there are no errors", function () {
var $el = $(".error-view").first();
$el.html('previous error here');
@@ -99,7 +96,7 @@ define([
var errorView = new ErrorView({
"name": "test",
"errors": [],
"el" : $el,
"el": $el,
"errorTemplate": "#field_errors"
});

View File

@@ -3,108 +3,108 @@ define([
'models/field',
'models/dcField',
'models/vocabulary'
], function(chai, Field, DcField, Vocabulary) {
], function (chai, Field, DcField, Vocabulary) {
var expect = chai.expect;
var assert = chai.assert;
var should = chai.should();
describe("Models", function(){
describe("Field Model", function(){
describe("Initialization", function() {
describe("Models", function () {
describe("Field Model", function () {
describe("Initialization", function () {
var sbasId = 1;
beforeEach(function() {
beforeEach(function () {
this.field = new Field({
"sbas-id" : sbasId
"sbas-id": sbasId
});
});
it("should throw an exception if 'sbas-id' is missing", function() {
expect(function() {
it("should throw an exception if 'sbas-id' is missing", function () {
expect(function () {
new Field();
}).to.throw("You must set a sbas id");
});
it("should set model url according to provided 'sbas-id'", function() {
this.field.urlRoot().should.equal("/admin/fields/"+sbasId+"/fields");
it("should set model url according to provided 'sbas-id'", function () {
this.field.urlRoot().should.equal("/admin/fields/" + sbasId + "/fields");
});
it("should default business property to 'false'", function() {
it("should default business property to 'false'", function () {
this.field.get('business').should.be.false;
});
it("should default type property to 'string'", function() {
it("should default type property to 'string'", function () {
this.field.get('type').should.equal("string");
});
it("should default thumbtitle property to '0'", function() {
it("should default thumbtitle property to '0'", function () {
this.field.get('thumbtitle').should.equal("0");
});
it("should default tbranch property to 'empty'", function() {
it("should default tbranch property to 'empty'", function () {
this.field.get('tbranch').should.equal("");
});
it("should default separator property to 'empty'", function() {
it("should default separator property to 'empty'", function () {
this.field.get('separator').should.equal("");
});
it("should default required property to 'false'", function() {
it("should default required property to 'false'", function () {
this.field.get('required').should.be.false;
});
it("should default readonly property to 'false'", function() {
it("should default readonly property to 'false'", function () {
this.field.get('readonly').should.be.false;
});
it("should default multi property to 'false'", function() {
it("should default multi property to 'false'", function () {
this.field.get('multi').should.be.false;
});
it("should default vocabulary-restricted property to 'false'", function() {
it("should default vocabulary-restricted property to 'false'", function () {
this.field.get('vocabulary-restricted').should.be.false;
});
it("should default vocabulary-restricted property to 'false'", function() {
it("should default vocabulary-restricted property to 'false'", function () {
this.field.get('vocabulary-restricted').should.be.false;
});
it("should default report property to 'true'", function() {
it("should default report property to 'true'", function () {
this.field.get('report').should.be.true;
});
it("should default indexable property to 'true'", function() {
it("should default indexable property to 'true'", function () {
this.field.get('indexable').should.be.true;
});
it("should default dces-element property to 'null'", function() {
it("should default dces-element property to 'null'", function () {
expect(this.field.get('dces-element')).to.be.null;
});
it("should default vocabulary-type property to 'null'", function() {
it("should default vocabulary-type property to 'null'", function () {
expect(this.field.get('vocabulary-type')).to.be.null;
});
});
});
describe("DcField Model", function(){
describe("Initialization", function() {
beforeEach(function() {
describe("DcField Model", function () {
describe("Initialization", function () {
beforeEach(function () {
this.dcField = new DcField();
});
it("should set proper model url", function() {
it("should set proper model url", function () {
this.dcField.urlRoot().should.equal("/admin/fields/dc-fields");
});
});
});
describe("DcField Model", function(){
describe("Initialization", function() {
beforeEach(function() {
describe("DcField Model", function () {
describe("Initialization", function () {
beforeEach(function () {
this.vocabulary = new Vocabulary();
});
it("should set proper model url", function() {
it("should set proper model url", function () {
this.vocabulary.urlRoot().should.equal("/admin/fields/vocabularies");
});
});

View File

@@ -1,490 +1,611 @@
define([
'chai',
'common/forms/validator'
], function(chai, Validator) {
], function (chai, Validator) {
var expect = chai.expect;
var assert = chai.assert;
var should = chai.should();
describe("Validator", function(){
describe("Validator rules", function(){
describe("Validator", function () {
describe("Validator rules", function () {
beforeEach(function() {
this.validator = new Validator([{
name: "required",
rules: "required"
},{
name: "valid_email",
rules: "valid_email"
},{
name: "equal",
rules: "equal[toto]"
},{
name: "matches",
rules: "matches[to_match]"
},{
name: "valid_emails",
rules: "valid_emails"
},{
name: "min_length",
rules: "min_length[5]"
},{
name: "max_length",
rules: "max_length[5]"
},{
name: "exact_length",
rules: "exact_length[5]"
},{
name: "greater_than",
rules: "greater_than[5]"
},{
name: "less_than",
rules: "less_than[5]"
},{
name: "alpha",
rules: "alpha"
},{
name: "alpha_numeric",
rules: "alpha_numeric"
},{
name: "alpha_dash",
rules: "alpha_dash"
},{
name: "numeric",
rules: "numeric"
},{
name: "integer",
rules: "integer"
},{
name: "decimal",
rules: "decimal"
},{
name: "is_natural",
rules: "is_natural"
},{
name: "is_natural_no_zero",
rules: "is_natural_no_zero"
},{
name: "valid_ip",
rules: "valid_ip"
},{
name: "valid_url",
rules: "valid_url"
}]);
beforeEach(function () {
this.validator = new Validator([
{
name: "required",
rules: "required"
},
{
name: "valid_email",
rules: "valid_email"
},
{
name: "equal",
rules: "equal[toto]"
},
{
name: "matches",
rules: "matches[to_match]"
},
{
name: "valid_emails",
rules: "valid_emails"
},
{
name: "min_length",
rules: "min_length[5]"
},
{
name: "max_length",
rules: "max_length[5]"
},
{
name: "exact_length",
rules: "exact_length[5]"
},
{
name: "greater_than",
rules: "greater_than[5]"
},
{
name: "less_than",
rules: "less_than[5]"
},
{
name: "alpha",
rules: "alpha"
},
{
name: "alpha_numeric",
rules: "alpha_numeric"
},
{
name: "alpha_dash",
rules: "alpha_dash"
},
{
name: "numeric",
rules: "numeric"
},
{
name: "integer",
rules: "integer"
},
{
name: "decimal",
rules: "decimal"
},
{
name: "is_natural",
rules: "is_natural"
},
{
name: "is_natural_no_zero",
rules: "is_natural_no_zero"
},
{
name: "valid_ip",
rules: "valid_ip"
},
{
name: "valid_url",
rules: "valid_url"
}
]);
});
it("should detect an error if field is required and value is blank", function() {
this.validator.validate([{
name :"required",
value: ""
}]);
it("should detect an error if field is required and value is blank", function () {
this.validator.validate([
{
name: "required",
value: ""
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should detect an error if field is not a valid email", function() {
this.validator.validate([{
name :"valid_email",
value: "email.not.va@"
}]);
it("should detect an error if field is not a valid email", function () {
this.validator.validate([
{
name: "valid_email",
value: "email.not.va@"
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should not detect an error if field is a valid email", function() {
this.validator.validate([{
name :"valid_email",
value: "valid@email.com"
}]);
it("should not detect an error if field is a valid email", function () {
this.validator.validate([
{
name: "valid_email",
value: "valid@email.com"
}
]);
this.validator.getErrors().length.should.equal(0);
this.validator.validate([{
name :"valid_email",
value: "valid+34@email.com"
}]);
this.validator.validate([
{
name: "valid_email",
value: "valid+34@email.com"
}
]);
this.validator.getErrors().length.should.equal(0);
});
it("should detect an error if field is not a valid emails", function() {
this.validator.validate([{
name :"valid_emails",
value: "valid@email.com, email.not.va@"
}]);
it("should detect an error if field is not a valid emails", function () {
this.validator.validate([
{
name: "valid_emails",
value: "valid@email.com, email.not.va@"
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should not detect an error if field is a valid emails", function() {
this.validator.validate([{
name :"valid_emails",
value: "valid32@email.com, valid2@email.com"
}]);
it("should not detect an error if field is a valid emails", function () {
this.validator.validate([
{
name: "valid_emails",
value: "valid32@email.com, valid2@email.com"
}
]);
this.validator.getErrors().length.should.equal(0);
this.validator.validate([{
name :"valid_emails",
value: "valid@email.com"
}]);
this.validator.validate([
{
name: "valid_emails",
value: "valid@email.com"
}
]);
this.validator.getErrors().length.should.equal(0);
});
it("should detect an error if field is not equal to default string toto", function() {
this.validator.validate([{
name :"equal",
value: "tata"
}]);
it("should detect an error if field is not equal to default string toto", function () {
this.validator.validate([
{
name: "equal",
value: "tata"
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should not detect an error if field is equal to default string toto", function() {
this.validator.validate([{
name :"equal",
value: "toto"
}]);
it("should not detect an error if field is equal to default string toto", function () {
this.validator.validate([
{
name: "equal",
value: "toto"
}
]);
this.validator.getErrors().length.should.equal(0);
});
it("should detect an error if field value 'match 'is not equal to field value 'to_match'", function() {
this.validator.validate([{
name :"matches",
value: "toto"
}, {
name: "to_match",
value: "tata"
}]);
it("should detect an error if field value 'match 'is not equal to field value 'to_match'", function () {
this.validator.validate([
{
name: "matches",
value: "toto"
},
{
name: "to_match",
value: "tata"
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should not detect an error if field value 'match' is equal to field value 'to_match'", function() {
this.validator.validate([{
name :"matches",
value: "toto"
}, {
name: "to_match",
value: "toto"
}]);
it("should not detect an error if field value 'match' is equal to field value 'to_match'", function () {
this.validator.validate([
{
name: "matches",
value: "toto"
},
{
name: "to_match",
value: "toto"
}
]);
this.validator.getErrors().length.should.equal(0);
});
it("should detect an error if field value 'min_length' is < to 5", function() {
this.validator.validate([{
name :"min_length",
value: "toto"
}]);
it("should detect an error if field value 'min_length' is < to 5", function () {
this.validator.validate([
{
name: "min_length",
value: "toto"
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should not detect an error if field value 'min_length' is >= to 5", function() {
this.validator.validate([{
name :"min_length",
value: "totos"
}]);
it("should not detect an error if field value 'min_length' is >= to 5", function () {
this.validator.validate([
{
name: "min_length",
value: "totos"
}
]);
this.validator.getErrors().length.should.equal(0);
});
it("should detect an error if field value 'max_length' is > to 5", function() {
this.validator.validate([{
name :"max_length",
value: "tostos"
}]);
it("should detect an error if field value 'max_length' is > to 5", function () {
this.validator.validate([
{
name: "max_length",
value: "tostos"
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should not detect an error if field value 'max_length' is <= to 5", function() {
this.validator.validate([{
name :"max_length",
value: "toto"
}]);
it("should not detect an error if field value 'max_length' is <= to 5", function () {
this.validator.validate([
{
name: "max_length",
value: "toto"
}
]);
this.validator.getErrors().length.should.equal(0);
});
it("should detect an error if field value 'greater_than' is < to 5", function() {
this.validator.validate([{
name :"greater_than",
value: "3"
}]);
it("should detect an error if field value 'greater_than' is < to 5", function () {
this.validator.validate([
{
name: "greater_than",
value: "3"
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should not detect an error if field value 'greater_than' is > to 5", function() {
this.validator.validate([{
name :"greater_than",
value: "6"
}]);
it("should not detect an error if field value 'greater_than' is > to 5", function () {
this.validator.validate([
{
name: "greater_than",
value: "6"
}
]);
this.validator.getErrors().length.should.equal(0);
});
it("should detect an error if field value 'less_than' is > to 5", function() {
this.validator.validate([{
name :"less_than",
value: "6"
}]);
it("should detect an error if field value 'less_than' is > to 5", function () {
this.validator.validate([
{
name: "less_than",
value: "6"
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should not detect an error if field value 'less_than' is <= to 5", function() {
this.validator.validate([{
name :"less_than",
value: "3"
}]);
it("should not detect an error if field value 'less_than' is <= to 5", function () {
this.validator.validate([
{
name: "less_than",
value: "3"
}
]);
this.validator.getErrors().length.should.equal(0);
});
it("should detect an error if field value 'exact_length' is = to 5", function() {
this.validator.validate([{
name :"exact_length",
value: "toto"
}]);
it("should detect an error if field value 'exact_length' is = to 5", function () {
this.validator.validate([
{
name: "exact_length",
value: "toto"
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should not detect an error if field value 'exact_length' is = to 5", function() {
this.validator.validate([{
name :"exact_length",
value: "totos"
}]);
it("should not detect an error if field value 'exact_length' is = to 5", function () {
this.validator.validate([
{
name: "exact_length",
value: "totos"
}
]);
this.validator.getErrors().length.should.equal(0);
});
it("should detect an error if field value 'alpha' is not alpha", function() {
this.validator.validate([{
name :"alpha",
value: "toto12"
}]);
it("should detect an error if field value 'alpha' is not alpha", function () {
this.validator.validate([
{
name: "alpha",
value: "toto12"
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should not detect an error if field value 'alpha' is alpha", function() {
this.validator.validate([{
name :"alpha",
value: "totos"
}]);
it("should not detect an error if field value 'alpha' is alpha", function () {
this.validator.validate([
{
name: "alpha",
value: "totos"
}
]);
this.validator.getErrors().length.should.equal(0);
});
it("should detect an error if field value 'alpha_numeric' is not alpha numeric", function() {
this.validator.validate([{
name :"alpha_numeric",
value: "toto#"
}]);
it("should detect an error if field value 'alpha_numeric' is not alpha numeric", function () {
this.validator.validate([
{
name: "alpha_numeric",
value: "toto#"
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should not detect an error if field value 'alpha_numeric' is alpha numeric", function() {
this.validator.validate([{
name :"alpha_numeric",
value: "totos12"
}]);
it("should not detect an error if field value 'alpha_numeric' is alpha numeric", function () {
this.validator.validate([
{
name: "alpha_numeric",
value: "totos12"
}
]);
this.validator.getErrors().length.should.equal(0);
});
it("should detect an error if field value 'numeric' is not numeric", function() {
this.validator.validate([{
name :"numeric",
value: "toto"
}]);
it("should detect an error if field value 'numeric' is not numeric", function () {
this.validator.validate([
{
name: "numeric",
value: "toto"
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should not detect an error if field value 'numeric' is numeric", function() {
this.validator.validate([{
name :"numeric",
value: "123"
}]);
it("should not detect an error if field value 'numeric' is numeric", function () {
this.validator.validate([
{
name: "numeric",
value: "123"
}
]);
this.validator.getErrors().length.should.equal(0);
});
it("should detect an error if field value 'integer' is not integer", function() {
this.validator.validate([{
name :"integer",
value: "3.44"
}]);
it("should detect an error if field value 'integer' is not integer", function () {
this.validator.validate([
{
name: "integer",
value: "3.44"
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should not detect an error if field value 'integer' is integer", function() {
this.validator.validate([{
name :"integer",
value: "123"
}]);
it("should not detect an error if field value 'integer' is integer", function () {
this.validator.validate([
{
name: "integer",
value: "123"
}
]);
this.validator.getErrors().length.should.equal(0);
});
it("should detect an error if field value 'decimal' is not decimal", function() {
this.validator.validate([{
name :"decimal",
value: "23a"
}]);
it("should detect an error if field value 'decimal' is not decimal", function () {
this.validator.validate([
{
name: "decimal",
value: "23a"
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should not detect an error if field value 'decimal' is decimal", function() {
this.validator.validate([{
name :"decimal",
value: "1.23"
}]);
it("should not detect an error if field value 'decimal' is decimal", function () {
this.validator.validate([
{
name: "decimal",
value: "1.23"
}
]);
this.validator.getErrors().length.should.equal(0);
this.validator.validate([{
name :"decimal",
value: "123"
}]);
this.validator.validate([
{
name: "decimal",
value: "123"
}
]);
this.validator.getErrors().length.should.equal(0);
});
it("should detect an error if field value 'natural' is not natural", function() {
this.validator.validate([{
name :"is_natural",
value: "-2"
}]);
it("should detect an error if field value 'natural' is not natural", function () {
this.validator.validate([
{
name: "is_natural",
value: "-2"
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should not detect an error if field value 'natural' is natural", function() {
this.validator.validate([{
name :"is_natural",
value: "0"
}]);
it("should not detect an error if field value 'natural' is natural", function () {
this.validator.validate([
{
name: "is_natural",
value: "0"
}
]);
this.validator.getErrors().length.should.equal(0);
});
it("should detect an error if field value 'is_natural_no_zero' is not a natural no zero", function() {
this.validator.validate([{
name :"is_natural_no_zero",
value: "0"
}]);
it("should detect an error if field value 'is_natural_no_zero' is not a natural no zero", function () {
this.validator.validate([
{
name: "is_natural_no_zero",
value: "0"
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should not detect an error if field value 'is_natural_no_zero' is a natural no zero", function() {
this.validator.validate([{
name :"is_natural_no_zero",
value: "1"
}]);
it("should not detect an error if field value 'is_natural_no_zero' is a natural no zero", function () {
this.validator.validate([
{
name: "is_natural_no_zero",
value: "1"
}
]);
this.validator.getErrors().length.should.equal(0);
});
it("should detect an error if field value 'valid_ip' is not a valid ip", function() {
this.validator.validate([{
name :"valid_ip",
value: "12.8.1.187.2"
}]);
it("should detect an error if field value 'valid_ip' is not a valid ip", function () {
this.validator.validate([
{
name: "valid_ip",
value: "12.8.1.187.2"
}
]);
this.validator.getErrors().length.should.equal(1);
this.validator.validate([{
name :"valid_ip",
value: "1234.12.12"
}]);
this.validator.validate([
{
name: "valid_ip",
value: "1234.12.12"
}
]);
this.validator.getErrors().length.should.equal(1);
this.validator.validate([{
name :"valid_ip",
value: "0.0"
}]);
this.validator.validate([
{
name: "valid_ip",
value: "0.0"
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should not detect an error if field value 'valid_ip' a valid ip", function() {
this.validator.validate([{
name :"valid_ip",
value: "127.0.0.1"
}]);
it("should not detect an error if field value 'valid_ip' a valid ip", function () {
this.validator.validate([
{
name: "valid_ip",
value: "127.0.0.1"
}
]);
this.validator.getErrors().length.should.equal(0);
this.validator.validate([{
name :"valid_ip",
value: "my.domain"
}]);
this.validator.validate([
{
name: "valid_ip",
value: "my.domain"
}
]);
this.validator.getErrors().length.should.equal(0);
});
it("should detect an error if field value 'valid_url' is not a valid http url", function() {
this.validator.validate([{
name :"valid_url",
value: "toto"
}]);
it("should detect an error if field value 'valid_url' is not a valid http url", function () {
this.validator.validate([
{
name: "valid_url",
value: "toto"
}
]);
this.validator.getErrors().length.should.equal(1);
this.validator.validate([{
name :"valid_url",
value: "toto.123s"
}]);
this.validator.validate([
{
name: "valid_url",
value: "toto.123s"
}
]);
this.validator.getErrors().length.should.equal(1);
this.validator.validate([{
name :"valid_url",
value: "http:/#toto.com"
}]);
this.validator.validate([
{
name: "valid_url",
value: "http:/#toto.com"
}
]);
this.validator.getErrors().length.should.equal(1);
this.validator.validate([{
name :"valid_url",
value: "htp:/toto.com"
}]);
this.validator.validate([
{
name: "valid_url",
value: "htp:/toto.com"
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should not detect an error if field value 'valid_url' is a valid http url", function() {
this.validator.validate([{
name :"valid_url",
value: "http://valid.url.com"
}]);
it("should not detect an error if field value 'valid_url' is a valid http url", function () {
this.validator.validate([
{
name: "valid_url",
value: "http://valid.url.com"
}
]);
this.validator.getErrors().length.should.equal(0);
this.validator.validate([{
name :"valid_url",
value: "https://valid.url.com"
}]);
this.validator.validate([
{
name: "valid_url",
value: "https://valid.url.com"
}
]);
this.validator.getErrors().length.should.equal(0);
this.validator.getErrors().length.should.equal(0);
this.validator.validate([{
name :"valid_url",
value: "http://valid.url.com/?test=3"
}]);
this.validator.validate([
{
name: "valid_url",
value: "http://valid.url.com/?test=3"
}
]);
this.validator.getErrors().length.should.equal(0);
this.validator.validate([{
name :"valid_url",
value: "http://valid.url.com/?test=3#salut"
}]);
this.validator.validate([
{
name: "valid_url",
value: "http://valid.url.com/?test=3#salut"
}
]);
this.validator.getErrors().length.should.equal(0);
});