adding template to corresponding categories when saved

This commit is contained in:
Amine Ben hammou
2018-01-02 16:34:07 +00:00
parent 9b914a471b
commit fe2ab08a49

View File

@@ -93,29 +93,41 @@ define([
}; };
Module.saveTemplate = function (options) { Module.saveTemplate = function (options) {
var promise = jQuery.Deferred(); var categories = ['saved'];
promise.then(function (thumbnail) { return MailPoet.Ajax.post({
var data = _.extend(options || {}, { api_version: window.mailpoet_api_version,
thumbnail: thumbnail.toDataURL('image/jpeg'), endpoint: 'newsletters',
body: JSON.stringify(App.getBody()) action: 'get',
}); data: {
id: App.toJSON().id
}
}).then(function(response) {
var type = response.data.type;
if (type == 'welcome') {
categories.push('welcome_emails');
}
if (type == 'notification') {
categories.push('post_notifications');
}
}).then(function() {
return Module.getThumbnail(
jQuery('#mailpoet_editor_content > .mailpoet_block').get(0)
).then(function (thumbnail) {
var data = _.extend(options || {}, {
thumbnail: thumbnail.toDataURL('image/jpeg'),
body: JSON.stringify(App.getBody()),
categories: JSON.stringify(categories)
});
return MailPoet.Ajax.post({ return MailPoet.Ajax.post({
api_version: window.mailpoet_api_version, api_version: window.mailpoet_api_version,
endpoint: 'newsletterTemplates', endpoint: 'newsletterTemplates',
action: 'save', action: 'save',
data: data data: data
});
}); });
}); });
Module.getThumbnail(
jQuery('#mailpoet_editor_content > .mailpoet_block').get(0)
).then(function (thumbnail) {
promise.resolve(thumbnail);
});
return promise;
}; };
Module.exportTemplate = function (options) { Module.exportTemplate = function (options) {