Display error and success messages for template saving and export
This commit is contained in:
@ -48,7 +48,7 @@
|
|||||||
.mailpoet_save_as_template_container,
|
.mailpoet_save_as_template_container,
|
||||||
.mailpoet_export_template_container
|
.mailpoet_export_template_container
|
||||||
border-radius(3px)
|
border-radius(3px)
|
||||||
float: left
|
display: inline-block
|
||||||
clear: both
|
clear: both
|
||||||
|
|
||||||
margin-top: 5px
|
margin-top: 5px
|
||||||
|
@ -146,20 +146,48 @@ define([
|
|||||||
},
|
},
|
||||||
saveAsTemplate: function() {
|
saveAsTemplate: function() {
|
||||||
var templateName = this.$('.mailpoet_save_as_template_name').val(),
|
var templateName = this.$('.mailpoet_save_as_template_name').val(),
|
||||||
templateDescription = this.$('.mailpoet_save_as_template_description').val();
|
templateDescription = this.$('.mailpoet_save_as_template_description').val(),
|
||||||
|
that = this;
|
||||||
|
|
||||||
|
if (templateName === '') {
|
||||||
|
MailPoet.Notice.error(
|
||||||
|
App.getConfig().get('translations.templateNameMissing'),
|
||||||
|
{
|
||||||
|
positionAfter: that.$el,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else if (templateDescription === '') {
|
||||||
|
MailPoet.Notice.error(
|
||||||
|
App.getConfig().get('translations.templateDescriptionMissing'),
|
||||||
|
{
|
||||||
|
positionAfter: that.$el,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
console.log('Saving template with ', templateName, templateDescription);
|
console.log('Saving template with ', templateName, templateDescription);
|
||||||
Module.saveTemplate({
|
Module.saveTemplate({
|
||||||
name: templateName,
|
name: templateName,
|
||||||
description: templateDescription,
|
description: templateDescription,
|
||||||
}).done(function() {
|
}).done(function() {
|
||||||
console.log('Template saved', arguments);
|
console.log('Template saved', arguments);
|
||||||
|
MailPoet.Notice.success(
|
||||||
|
App.getConfig().get('translations.templateSaved'),
|
||||||
|
{
|
||||||
|
positionAfter: that.$el,
|
||||||
|
}
|
||||||
|
);
|
||||||
}).fail(function() {
|
}).fail(function() {
|
||||||
// TODO: Handle error messages
|
|
||||||
console.log('Template save failed', arguments);
|
console.log('Template save failed', arguments);
|
||||||
|
MailPoet.Notice.error(
|
||||||
|
App.getConfig().get('translations.templateSaveFailed'),
|
||||||
|
{
|
||||||
|
positionAfter: that.$el,
|
||||||
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.hideOptionContents();
|
this.hideOptionContents();
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
toggleExportTemplate: function() {
|
toggleExportTemplate: function() {
|
||||||
this.$('.mailpoet_export_template_container').toggleClass('mailpoet_hidden');
|
this.$('.mailpoet_export_template_container').toggleClass('mailpoet_hidden');
|
||||||
@ -170,12 +198,23 @@ define([
|
|||||||
},
|
},
|
||||||
exportTemplate: function() {
|
exportTemplate: function() {
|
||||||
var templateName = this.$('.mailpoet_export_template_name').val(),
|
var templateName = this.$('.mailpoet_export_template_name').val(),
|
||||||
templateDescription = this.$('.mailpoet_export_template_description').val();
|
templateDescription = this.$('.mailpoet_export_template_description').val(),
|
||||||
|
that = this;
|
||||||
|
|
||||||
if (templateName === '') {
|
if (templateName === '') {
|
||||||
MailPoet.Notice.error(App.getConfig().get('translations.templateNameMissing'));
|
MailPoet.Notice.error(
|
||||||
|
App.getConfig().get('translations.templateNameMissing'),
|
||||||
|
{
|
||||||
|
positionAfter: that.$el,
|
||||||
|
}
|
||||||
|
);
|
||||||
} else if (templateDescription === '') {
|
} else if (templateDescription === '') {
|
||||||
MailPoet.Notice.error(App.getConfig().get('translations.templateDescriptionMissing'));
|
MailPoet.Notice.error(
|
||||||
|
App.getConfig().get('translations.templateDescriptionMissing'),
|
||||||
|
{
|
||||||
|
positionAfter: that.$el,
|
||||||
|
}
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
console.log('Exporting template with ', templateName, templateDescription);
|
console.log('Exporting template with ', templateName, templateDescription);
|
||||||
Module.exportTemplate({
|
Module.exportTemplate({
|
||||||
|
@ -49,6 +49,7 @@ define('notice', ['mailpoet', 'jquery'], function(MailPoet, jQuery) {
|
|||||||
static: false,
|
static: false,
|
||||||
hideClose: false,
|
hideClose: false,
|
||||||
id: null,
|
id: null,
|
||||||
|
positionAfter: false,
|
||||||
scroll: false,
|
scroll: false,
|
||||||
timeout: 2000,
|
timeout: 2000,
|
||||||
onOpen: null,
|
onOpen: null,
|
||||||
@ -69,7 +70,16 @@ define('notice', ['mailpoet', 'jquery'], function(MailPoet, jQuery) {
|
|||||||
this.element.removeAttr('id');
|
this.element.removeAttr('id');
|
||||||
|
|
||||||
// insert notice after its parent
|
// insert notice after its parent
|
||||||
jQuery('#mailpoet_notice_'+this.options.type).after(this.element);
|
var positionAfter;
|
||||||
|
if (typeof this.options.positionAfter === 'object') {
|
||||||
|
positionAfter = this.options.positionAfter;
|
||||||
|
} else if (typeof this.options.positionAfter === 'string') {
|
||||||
|
positionAfter = jQuery(this.options.positionAfter);
|
||||||
|
} else {
|
||||||
|
positionAfter = jQuery('#mailpoet_notice_'+this.options.type);
|
||||||
|
}
|
||||||
|
console.log('positionAfter', typeof this.options.positionAfter);
|
||||||
|
positionAfter.after(this.element);
|
||||||
|
|
||||||
// setup onClose callback
|
// setup onClose callback
|
||||||
var onClose = null;
|
var onClose = null;
|
||||||
|
@ -1247,6 +1247,10 @@
|
|||||||
'<%= __('Please add a template name') %>',
|
'<%= __('Please add a template name') %>',
|
||||||
templateDescriptionMissing:
|
templateDescriptionMissing:
|
||||||
'<%= __('Please add a template description') %>',
|
'<%= __('Please add a template description') %>',
|
||||||
|
templateSaved:
|
||||||
|
'<%= __('Template has been saved.') %>',
|
||||||
|
templateSaveFailed:
|
||||||
|
'<%= __('Template has not been saved, please try again.') %>',
|
||||||
},
|
},
|
||||||
sidepanelWidth: '331px',
|
sidepanelWidth: '331px',
|
||||||
validation: {
|
validation: {
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
<li class="mailpoet_save_option"><a href="javascript:;" class="mailpoet_save_template"><%= __('Save as template') %></a></li>
|
<li class="mailpoet_save_option"><a href="javascript:;" class="mailpoet_save_template"><%= __('Save as template') %></a></li>
|
||||||
<li class="mailpoet_save_option"><a href="javascript:;" class="mailpoet_save_export"><%= __('Export as template') %></a></li>
|
<li class="mailpoet_save_option"><a href="javascript:;" class="mailpoet_save_export"><%= __('Export as template') %></a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
<div class="clearfix"></div>
|
||||||
<div class="mailpoet_save_as_template_container mailpoet_hidden">
|
<div class="mailpoet_save_as_template_container mailpoet_hidden">
|
||||||
<p><b class="mailpoet_save_as_template_title"><%= __('Save as template') %></b></p>
|
<p><b class="mailpoet_save_as_template_title"><%= __('Save as template') %></b></p>
|
||||||
<p><input type="text" name="template_name" value="" placeholder="<%= __('Insert template name') %>" class="mailpoet_input mailpoet_save_as_template_name" /></p>
|
<p><input type="text" name="template_name" value="" placeholder="<%= __('Insert template name') %>" class="mailpoet_input mailpoet_save_as_template_name" /></p>
|
||||||
|
Reference in New Issue
Block a user