Type & Template

- fixed endpoint's name causing issues on case sensitive systems
- improved behaviour of delete
- added loading state for boxes
- added Breadcrumb ReactClass
- added common styles for breadcrumb
This commit is contained in:
Jonathan Labreuille
2015-09-30 11:44:06 +02:00
parent 9a16904389
commit 2e3b565e8a
6 changed files with 142 additions and 44 deletions

View File

@@ -0,0 +1,76 @@
define(
[
'react',
'react-router',
'classnames'
],
function(
React,
Router,
classNames
) {
var Link = Router.Link;
var Breadcrumb = React.createClass({
mixins: [
Router.Navigation
],
getInitialState: function() {
return {
step: null,
steps: [
{
name: 'type',
label: 'Select type',
link: '/new'
},
{
name: 'template',
label: 'Template'
},
{
name: 'editor',
label: 'Designer'
},
{
name: 'send',
label: 'Send'
}
]
};
},
render: function() {
var steps = this.state.steps.map(function(step, index) {
var stepClasses = classNames(
{ 'mailpoet_current': (this.props.step === step.name) }
);
var label = step.label;
if(step['link'] !== undefined && this.props.step !== step.name) {
label = (
<Link to={ step.link }>{ step.label }</Link>
);
}
return (
<span key={ 'step-'+index }>
<span className={ stepClasses }>
{ label }
</span>
{ (index < (this.state.steps.length - 1) ) ? ' > ' : '' }
</span>
);
}.bind(this));
return (
<p className="mailpoet_breadcrumb">
{ steps }
</p>
);
}
});
return Breadcrumb;
}
);

View File

@@ -1,13 +1,17 @@
define(
[
'react',
'mailpoet',
'react-router'
'react',
'mailpoet',
'react-router',
'classnames',
'newsletters/breadcrumb.jsx'
],
function(
React,
MailPoet,
Router
Router,
classNames,
Breadcrumb
) {
var NewsletterTemplates = React.createClass({
mixins: [
@@ -26,7 +30,7 @@ define(
this.setState({ loading: true });
MailPoet.Ajax.post({
endpoint: 'newslettertemplates',
endpoint: 'newsletterTemplates',
action: 'getAll',
}).done(function(response) {
if(this.isMounted()) {
@@ -37,22 +41,29 @@ define(
}
}.bind(this));
},
handleSelectTemplate: function(id) {
console.log('select '+id);
handleSelectTemplate: function(template) {
console.log('select '+template.id);
},
handlePreviewTemplate: function(id) {
console.log('preview '+id);
handlePreviewTemplate: function(template) {
console.log('preview '+template.id);
},
handleDeleteTemplate: function(id) {
handleDeleteTemplate: function(template) {
this.setState({ loading: true });
MailPoet.Ajax.post({
endpoint: 'newslettertemplates',
action: 'delete',
data: id
}).done(function(response) {
this.getTemplates();
}.bind(this));
if(
window.confirm(
'You are about to delete the template named "'+ template.name +'"'
)
) {
MailPoet.Ajax.post({
endpoint: 'newsletterTemplates',
action: 'delete',
data: template.id
}).done(function(response) {
this.getTemplates();
}.bind(this));
} else {
this.setState({ loading: false });
}
},
render: function() {
var templates = this.state.templates.map(function(template, index) {
@@ -69,14 +80,14 @@ define(
<div className="mailpoet_actions">
<a
className="button button-primary"
onClick={ this.handleSelectTemplate.bind(null, template.id) }
onClick={ this.handleSelectTemplate.bind(null, template) }
>
Select
</a>
&nbsp;
<a
className="button button-secondary"
onClick={ this.handlePreviewTemplate.bind(null, template.id) }
onClick={ this.handlePreviewTemplate.bind(null, template) }
>
Preview
</a>
@@ -84,7 +95,7 @@ define(
<div className="mailpoet_delete">
<a
href="javascript:;"
onClick={ this.handleDeleteTemplate.bind(null, template.id) }
onClick={ this.handleDeleteTemplate.bind(null, template) }
>
Delete
</a>
@@ -93,21 +104,19 @@ define(
);
}.bind(this));
var boxClasses = classNames(
'mailpoet_boxes',
'clearfix',
{ 'mailpoet_boxes_loading': this.state.loading }
);
return (
<div>
<h1>Select a template</h1>
<div className="mailpoet_breadcrumbs">
Select type
&nbsp;&gt;&nbsp;
<strong>Template</strong>
&nbsp;&gt;&nbsp;
Designer&nbsp;&gt;&nbsp;
Send
</div>
<Breadcrumb step="template" />
<ul className="mailpoet_boxes clearfix">
<ul className={ boxClasses }>
{ templates }
</ul>
</div>

View File

@@ -1,13 +1,15 @@
define(
[
'react',
'mailpoet',
'react-router'
'react',
'mailpoet',
'react-router',
'newsletters/breadcrumb.jsx'
],
function(
React,
MailPoet,
Router
Router,
Breadcrumb
) {
var NewsletterTypes = React.createClass({
mixins: [
@@ -23,14 +25,7 @@ define(
<div>
<h1>Pick a type of campaign</h1>
<div className="mailpoet_breadcrumbs">
<strong>Select type</strong>
&nbsp;&gt;&nbsp;
Template
&nbsp;&gt;&nbsp;
Designer&nbsp;&gt;&nbsp;
Send
</div>
<Breadcrumb step="type" />
<ul className="mailpoet_boxes clearfix">
<li data-type="standard">