snappymail/dev/Settings/User/Templates.jsx

99 lines
2.1 KiB
React
Raw Normal View History

2016-06-30 08:02:45 +08:00
var
ko = require('ko'),
2016-06-30 08:02:45 +08:00
Translator = require('Common/Translator'),
2016-06-30 08:02:45 +08:00
TemplateStore = require('Stores/User/Template'),
2016-06-30 08:02:45 +08:00
Remote = require('Remote/User/Ajax');
2016-06-30 08:02:45 +08:00
/**
* @constructor
*/
function TemplatesUserSettings()
{
this.templates = TemplateStore.templates;
2016-06-30 08:02:45 +08:00
this.processText = ko.computed(function() {
return TemplateStore.templates.loading() ? Translator.i18n('SETTINGS_TEMPLETS/LOADING_PROCESS') : '';
}, this);
2016-06-30 08:02:45 +08:00
this.visibility = ko.computed(function() {
return '' === this.processText() ? 'hidden' : 'visible';
}, this);
2016-06-30 08:02:45 +08:00
this.templateForDeletion = ko.observable(null).deleteAccessHelper();
}
2016-06-30 08:02:45 +08:00
TemplatesUserSettings.prototype.scrollableOptions = function(sWrapper)
{
return {
handle: '.drag-handle',
containment: sWrapper || 'parent',
axis: 'y'
};
};
2016-06-30 08:02:45 +08:00
TemplatesUserSettings.prototype.addNewTemplate = function()
{
require('Knoin/Knoin').showScreenPopup(require('View/Popup/Template'));
};
2016-06-30 08:02:45 +08:00
TemplatesUserSettings.prototype.editTemplate = function(oTemplateItem)
{
if (oTemplateItem)
{
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())
{
2016-06-30 08:02:45 +08:00
this.templateForDeletion(null);
2016-06-30 08:02:45 +08:00
var
self = this,
fRemoveAccount = function(oAccount) {
return oTemplateToRemove === oAccount;
};
if (oTemplateToRemove)
{
2016-06-30 08:02:45 +08:00
this.templates.remove(fRemoveAccount);
Remote.templateDelete(function() {
self.reloadTemplates();
}, oTemplateToRemove.id);
}
2016-06-30 08:02:45 +08:00
}
};
2016-06-30 08:02:45 +08:00
TemplatesUserSettings.prototype.reloadTemplates = function()
{
require('App/User').default.templates();
};
2016-06-30 08:02:45 +08:00
TemplatesUserSettings.prototype.onBuild = function(oDom)
{
var self = this;
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)
{
2016-06-30 08:02:45 +08:00
self.editTemplate(oTemplateItem);
}
2016-06-30 08:02:45 +08:00
});
2016-06-30 08:02:45 +08:00
this.reloadTemplates();
};
2016-07-16 03:54:37 +08:00
export {TemplatesUserSettings, TemplatesUserSettings as default};