2015-02-08 09:11:13 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
var
|
|
|
|
ko = require('ko'),
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
Translator = require('Common/Translator'),
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
TemplateStore = require('Stores/User/Template'),
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
Remote = require('Remote/User/Ajax');
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
/**
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
function TemplatesUserSettings()
|
|
|
|
{
|
|
|
|
this.templates = TemplateStore.templates;
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
this.processText = ko.computed(function() {
|
|
|
|
return TemplateStore.templates.loading() ? Translator.i18n('SETTINGS_TEMPLETS/LOADING_PROCESS') : '';
|
|
|
|
}, this);
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
this.visibility = ko.computed(function() {
|
|
|
|
return '' === this.processText() ? 'hidden' : 'visible';
|
|
|
|
}, this);
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
this.templateForDeletion = ko.observable(null).deleteAccessHelper();
|
|
|
|
}
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
TemplatesUserSettings.prototype.scrollableOptions = function(sWrapper)
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
handle: '.drag-handle',
|
|
|
|
containment: sWrapper || 'parent',
|
|
|
|
axis: 'y'
|
|
|
|
};
|
|
|
|
};
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
TemplatesUserSettings.prototype.addNewTemplate = function()
|
|
|
|
{
|
|
|
|
require('Knoin/Knoin').showScreenPopup(require('View/Popup/Template'));
|
|
|
|
};
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
TemplatesUserSettings.prototype.editTemplate = function(oTemplateItem)
|
|
|
|
{
|
|
|
|
if (oTemplateItem)
|
2015-02-08 09:11:13 +08:00
|
|
|
{
|
2016-06-30 08:02:45 +08:00
|
|
|
require('Knoin/Knoin').showScreenPopup(require('View/Popup/Template'), [oTemplateItem]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {AccountModel} oTemplateToRemove
|
|
|
|
*/
|
|
|
|
TemplatesUserSettings.prototype.deleteTemplate = function(oTemplateToRemove)
|
|
|
|
{
|
|
|
|
if (oTemplateToRemove && oTemplateToRemove.deleteAccess())
|
2015-02-08 09:11:13 +08:00
|
|
|
{
|
2016-06-30 08:02:45 +08:00
|
|
|
this.templateForDeletion(null);
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
var
|
|
|
|
self = this,
|
|
|
|
fRemoveAccount = function(oAccount) {
|
|
|
|
return oTemplateToRemove === oAccount;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (oTemplateToRemove)
|
2015-02-08 09:11:13 +08:00
|
|
|
{
|
2016-06-30 08:02:45 +08:00
|
|
|
this.templates.remove(fRemoveAccount);
|
|
|
|
|
|
|
|
Remote.templateDelete(function() {
|
|
|
|
self.reloadTemplates();
|
|
|
|
}, oTemplateToRemove.id);
|
2015-02-08 09:11:13 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
|
|
|
};
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
TemplatesUserSettings.prototype.reloadTemplates = function()
|
|
|
|
{
|
|
|
|
require('App/User').default.templates();
|
|
|
|
};
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
TemplatesUserSettings.prototype.onBuild = function(oDom)
|
|
|
|
{
|
|
|
|
var self = this;
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
oDom
|
|
|
|
.on('click', '.templates-list .template-item .e-action', function() {
|
|
|
|
var oTemplateItem = ko.dataFor(this);
|
|
|
|
if (oTemplateItem)
|
2015-02-08 09:11:13 +08:00
|
|
|
{
|
2016-06-30 08:02:45 +08:00
|
|
|
self.editTemplate(oTemplateItem);
|
2015-02-08 09:11:13 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
});
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
this.reloadTemplates();
|
|
|
|
};
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2016-07-16 03:54:37 +08:00
|
|
|
export {TemplatesUserSettings, TemplatesUserSettings as default};
|