2013-07-24 04:15:58 +03:00
|
|
|
'use strict';
|
2013-05-28 03:19:07 +03:00
|
|
|
|
2013-06-25 02:41:59 +03:00
|
|
|
define(
|
|
|
|
[
|
2013-06-28 04:55:45 +03:00
|
|
|
'app',
|
2013-06-25 02:41:59 +03:00
|
|
|
'marionette',
|
2013-08-21 04:07:48 +03:00
|
|
|
'Mixins/AsModelBoundView',
|
|
|
|
'Mixins/AsValidatedView'
|
|
|
|
], function (App, Marionette, AsModelBoundView, AsValidatedView) {
|
2013-05-28 03:19:07 +03:00
|
|
|
|
2013-06-25 02:41:59 +03:00
|
|
|
var view = Marionette.ItemView.extend({
|
|
|
|
template: 'Settings/Indexers/EditTemplate',
|
2013-05-28 03:19:07 +03:00
|
|
|
|
2013-06-25 02:41:59 +03:00
|
|
|
events: {
|
2013-07-24 04:15:58 +03:00
|
|
|
'click .x-save' : '_save',
|
2013-06-28 04:55:45 +03:00
|
|
|
'click .x-save-and-add': '_saveAndAdd'
|
2013-06-25 02:41:59 +03:00
|
|
|
},
|
2013-05-28 03:19:07 +03:00
|
|
|
|
2013-06-25 02:41:59 +03:00
|
|
|
initialize: function (options) {
|
|
|
|
this.indexerCollection = options.indexerCollection;
|
|
|
|
},
|
2013-05-28 03:19:07 +03:00
|
|
|
|
2013-06-28 04:55:45 +03:00
|
|
|
_save: function () {
|
|
|
|
var self = this;
|
|
|
|
var promise = this.model.saveSettings();
|
|
|
|
|
|
|
|
if (promise) {
|
|
|
|
promise.done(function () {
|
|
|
|
self.indexerCollection.add(self.model, { merge: true });
|
2013-07-24 04:15:58 +03:00
|
|
|
App.vent.trigger(App.Commands.CloseModalCommand);
|
2013-06-28 04:55:45 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_saveAndAdd: function () {
|
|
|
|
var self = this;
|
|
|
|
var promise = this.model.saveSettings();
|
|
|
|
|
|
|
|
if (promise) {
|
|
|
|
promise.done(function () {
|
|
|
|
self.indexerCollection.add(self.model, { merge: true });
|
|
|
|
|
|
|
|
self.model.set({
|
2013-07-24 04:15:58 +03:00
|
|
|
id : undefined,
|
|
|
|
name : '',
|
2013-06-28 04:55:45 +03:00
|
|
|
enable: false
|
|
|
|
});
|
|
|
|
|
|
|
|
_.each(self.model.get('fields'), function (value, key, list) {
|
2013-07-24 04:15:58 +03:00
|
|
|
self.model.set('fields.' + key + '.value', '');
|
2013-06-28 04:55:45 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2013-06-25 02:41:59 +03:00
|
|
|
}
|
|
|
|
});
|
2013-06-19 04:02:23 +03:00
|
|
|
|
2013-08-21 04:07:48 +03:00
|
|
|
AsModelBoundView.call(view);
|
|
|
|
AsValidatedView.call(view);
|
|
|
|
|
|
|
|
return view;
|
2013-06-25 02:41:59 +03:00
|
|
|
});
|