fix modals

This commit is contained in:
yuri
2015-06-04 17:52:24 +03:00
parent bee44612e5
commit 2497e9bd88
8 changed files with 72 additions and 64 deletions
+3 -2
View File
@@ -51,6 +51,7 @@ Espo.define('Views.Modal', 'View', function (Dep) {
if (action) {
var method = 'action' + Espo.Utils.upperCaseFirst(action);
if (typeof this[method] == 'function') {
e.preventDefault();
this[method].call(this, data);
}
}
@@ -131,8 +132,8 @@ Espo.define('Views.Modal', 'View', function (Dep) {
});
},
actionCancel: function (dialog) {
dialog.close();
actionCancel: function () {
this.dialog.close();
},
close: function () {
@@ -17,32 +17,32 @@
*
* You should have received a copy of the GNU General Public License
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
************************************************************************/
************************************************************************/
Espo.define('Views.Modals.ArrayFieldAdd', 'Views.Modal', function (Dep) {
return Dep.extend({
cssName: 'add-modal',
template: 'modals.array-field-add',
data: function () {
return {
optionList: this.options.options,
translatedOptions: this.options.translatedOptions
};
},
events: {
'click button[data-action="add"]': function (e) {
var value = $(e.currentTarget).data('value');
this.trigger('add', value);
},
},
setup: function () {
this.buttons = [
{
name: 'cancel',
@@ -50,8 +50,8 @@ Espo.define('Views.Modals.ArrayFieldAdd', 'Views.Modal', function (Dep) {
onClick: function (dialog) {
dialog.close();
}
}
];
}
];
},
@@ -17,7 +17,7 @@
*
* You should have received a copy of the GNU General Public License
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
************************************************************************/
************************************************************************/
Espo.define('Views.Modals.ChangePassword', 'Views.Modal', function (Dep) {
@@ -25,10 +25,10 @@ Espo.define('Views.Modals.ChangePassword', 'Views.Modal', function (Dep) {
cssName: 'change-password',
template: 'modals.change-password',
template: 'modals.change-password',
setup: function () {
this.buttons = [
{
name: 'change',
@@ -45,15 +45,15 @@ Espo.define('Views.Modals.ChangePassword', 'Views.Modal', function (Dep) {
dialog.close();
}
}
];
];
this.header = this.translate('Change Password', 'labels', 'User');
this.wait(true);
this.getModelFactory().create('User', function (user) {
this.getModelFactory().create('User', function (user) {
this.model = user;
this.createView('password', 'Fields.Password', {
model: user,
mode: 'edit',
@@ -73,29 +73,29 @@ Espo.define('Views.Modals.ChangePassword', 'Views.Modal', function (Dep) {
name: 'passwordConfirm',
params: {
required: true,
}
}
}
});
this.wait(false);
}, this);
}, this);
},
changePassword: function () {
changePassword: function () {
this.getView('password').fetchToModel();
this.getView('passwordConfirm').fetchToModel();
this.getView('passwordConfirm').fetchToModel();
var notValid = this.getView('password').validate() || this.getView('passwordConfirm').validate();
if (notValid) {
return;
}
this.$el.find('button[data-name="change"]').addClass('disabled');
$.ajax({
$.ajax({
url: 'User/action/changeOwnPassword',
type: 'POST',
data: JSON.stringify({
@@ -103,12 +103,12 @@ Espo.define('Views.Modals.ChangePassword', 'Views.Modal', function (Dep) {
}),
error: function () {
this.$el.find('button[data-name="change"]').removeClass('disabled');
}.bind(this)
}).done(function () {
Espo.Ui.success(this.translate('passwordChanged', 'messages', 'User'));
}.bind(this)
}).done(function () {
Espo.Ui.success(this.translate('passwordChanged', 'messages', 'User'));
this.trigger('changed');
this.close();
}.bind(this));
}.bind(this));
},
});
@@ -52,7 +52,9 @@ Espo.define('Views.Modals.ComposeEmail', 'Views.Modals.Edit', function (Dep) {
this.header = this.getLanguage().translate('Compose Email');
},
actionSend: function (dialog) {
actionSend: function () {
var dialog = this.dialog;
var editView = this.getView('edit');
var model = editView.model;
@@ -77,7 +79,9 @@ Espo.define('Views.Modals.ComposeEmail', 'Views.Modals.Edit', function (Dep) {
editView.send();
},
actionSaveDraft: function (dialog) {
actionSaveDraft: function () {
var dialog = this.dialog;
var editView = this.getView('edit');
var model = editView.model;
+5 -6
View File
@@ -135,7 +135,7 @@ Espo.define('Views.Modals.Detail', 'Views.Modal', function (Dep) {
}.bind(this), 50);
},
actionEdit: function (dialog) {
actionEdit: function () {
this.createView('quickEdit', 'Modals.Edit', {
scope: this.scope,
id: this.id,
@@ -143,8 +143,8 @@ Espo.define('Views.Modals.Detail', 'Views.Modal', function (Dep) {
}, function (view) {
view.once('after:render', function () {
Espo.Ui.notify(false);
dialog.hide();
});
this.dialog.hide();
}, this);
this.listenToOnce(view, 'remove', function () {
this.close();
@@ -158,7 +158,7 @@ Espo.define('Views.Modals.Detail', 'Views.Modal', function (Dep) {
}.bind(this));
},
actionFullForm: function (dialog) {
actionFullForm: function () {
var url;
var router = this.getRouter();
@@ -179,8 +179,7 @@ Espo.define('Views.Modals.Detail', 'Views.Modal', function (Dep) {
this.trigger('leave');
dialog.close();
this.dialog.close();
}
});
});
@@ -17,7 +17,7 @@
*
* You should have received a copy of the GNU General Public License
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
************************************************************************/
************************************************************************/
Espo.define('Views.Modals.Duplicate', 'Views.Modal', function (Dep) {
@@ -42,9 +42,9 @@ Espo.define('Views.Modals.Duplicate', 'Views.Modal', function (Dep) {
name: 'save',
label: 'Save',
style: 'danger',
onClick: function (dialog) {
onClick: function (dialog) {
this.trigger('save');
dialog.close();
dialog.close();
}.bind(this),
},
{
+9 -5
View File
@@ -82,7 +82,11 @@ Espo.define('Views.Modals.Edit', 'Views.Modal', function (Dep) {
this.header += ' ' + this.getLanguage().translate(this.scope, 'scopeNames');
if (!this.fullFormDisabled) {
this.header = '<a href="#' + this.scope + '/edit/' + this.id+'" class="action" title="'+this.translate('Full Form')+'" data-action="fullForm">' + this.header + '</a>';
if (!this.id) {
this.header = '<a href="#' + this.scope + '/create" class="action" title="'+this.translate('Full Form')+'" data-action="fullForm">' + this.header + '</a>';
} else {
this.header = '<a href="#' + this.scope + '/edit/' + this.id+'" class="action" title="'+this.translate('Full Form')+'" data-action="fullForm">' + this.header + '</a>';
}
}
this.waitForView('edit');
@@ -122,16 +126,16 @@ Espo.define('Views.Modals.Edit', 'Views.Modal', function (Dep) {
this.createView('edit', viewName, options, callback);
},
actionSave: function (dialog) {
actionSave: function () {
var editView = this.getView('edit');
var model = editView.model;
editView.once('after:save', function () {
this.trigger('after:save', model);
dialog.close();
this.dialog.close();
}, this);
var $buttons = dialog.$el.find('.modal-footer button');
var $buttons = this.dialog.$el.find('.modal-footer button');
$buttons.addClass('disabled');
editView.once('cancel:save', function () {
@@ -177,7 +181,7 @@ Espo.define('Views.Modals.Edit', 'Views.Modal', function (Dep) {
}
this.trigger('leave');
dialog.close();
this.dialog.close();
}
});
});
@@ -17,7 +17,7 @@
*
* You should have received a copy of the GNU General Public License
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
************************************************************************/
************************************************************************/
Espo.define('Views.Modals.SaveFilters', 'Views.Modal', function (Dep) {
@@ -41,7 +41,7 @@ Espo.define('Views.Modals.SaveFilters', 'Views.Modal', function (Dep) {
label: 'Save',
style: 'primary',
onClick: function (dialog) {
this.save();
this.save();
}.bind(this)
},
{
@@ -52,30 +52,30 @@ Espo.define('Views.Modals.SaveFilters', 'Views.Modal', function (Dep) {
}
}
];
this.header = this.translate('Save Filters');
var model = new Espo.Model();
this.createView('name', 'Fields.Varchar', {
el: this.options.el + ' .field-name',
this.createView('name', 'Fields.Varchar', {
el: this.options.el + ' .field-name',
defs: {
name: 'name',
params: {
required: true
}
}
},
mode: 'edit',
model: model
});
},
save: function () {
save: function () {
var nameView = this.getView('name');
nameView.fetchToModel();
nameView.fetchToModel();
if (nameView.validate()) {
return;
}
this.trigger('save', nameView.model.get('name'));
}
this.trigger('save', nameView.model.get('name'));
return true;
},
});