2013-06-22 09:24:24 +03:00
|
|
|
'use strict';
|
2013-10-09 04:43:41 +03:00
|
|
|
define(
|
|
|
|
[
|
|
|
|
'vent',
|
|
|
|
'backbone.deepmodel',
|
|
|
|
'Mixins/AsChangeTrackingModel',
|
|
|
|
'Shared/Messenger'
|
|
|
|
], function (vent, DeepModel, AsChangeTrackingModel, Messenger) {
|
|
|
|
var model = DeepModel.DeepModel.extend({
|
2013-06-19 07:27:41 +03:00
|
|
|
|
2013-10-09 04:43:41 +03:00
|
|
|
initialize: function () {
|
|
|
|
this.listenTo(vent, vent.Commands.SaveSettings, this.saveSettings);
|
2014-01-30 08:52:50 +03:00
|
|
|
this.listenTo(this, 'destroy', this._stopListening);
|
2013-10-09 04:43:41 +03:00
|
|
|
},
|
2013-06-19 07:27:41 +03:00
|
|
|
|
2013-10-09 04:43:41 +03:00
|
|
|
saveSettings: function () {
|
2013-06-19 07:27:41 +03:00
|
|
|
|
2013-10-09 04:43:41 +03:00
|
|
|
if (!this.isSaved) {
|
2013-06-19 07:27:41 +03:00
|
|
|
|
2013-10-09 04:43:41 +03:00
|
|
|
var savePromise = this.save();
|
2013-06-19 07:27:41 +03:00
|
|
|
|
2013-10-09 04:43:41 +03:00
|
|
|
Messenger.monitor({
|
|
|
|
promise : savePromise,
|
|
|
|
successMessage: this.successMessage,
|
|
|
|
errorMessage : this.errorMessage
|
|
|
|
});
|
2013-06-19 07:27:41 +03:00
|
|
|
|
2013-10-09 04:43:41 +03:00
|
|
|
return savePromise;
|
|
|
|
}
|
|
|
|
|
|
|
|
return undefined;
|
2014-01-30 08:52:50 +03:00
|
|
|
},
|
2013-06-19 07:27:41 +03:00
|
|
|
|
2014-01-30 08:52:50 +03:00
|
|
|
_stopListening: function () {
|
|
|
|
this.stopListening(vent, vent.Commands.SaveSettings);
|
|
|
|
}
|
2013-10-09 04:43:41 +03:00
|
|
|
});
|
2013-06-19 07:27:41 +03:00
|
|
|
|
2013-10-09 04:43:41 +03:00
|
|
|
return AsChangeTrackingModel.call(model);
|
2013-06-19 07:27:41 +03:00
|
|
|
});
|