diff --git a/RoboFile.php b/RoboFile.php index 9612ce8552..47a51b6f3f 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -3,10 +3,8 @@ class RoboFile extends \Robo\Tasks { private $css_files = array( - 'assets/css/src/admin.styl', - 'assets/css/src/newsletter_editor/newsletter_editor.styl', - 'assets/css/src/public.styl', - 'assets/css/src/rtl.styl' + 'assets/css/src/*.styl', + 'assets/css/src/**/*.styl' ); private $js_files = array( @@ -33,11 +31,16 @@ class RoboFile extends \Robo\Tasks { $js_files = array_merge($js_files, glob($path)); }, $this->js_files); + $css_files = array(); + array_map(function($path) use(&$css_files) { + $css_files = array_merge($css_files, glob($path)); + }, $this->css_files); + $this->taskWatch() ->monitor($js_files, function() { $this->compileJs(); }) - ->monitor($this->css_files, function() { + ->monitor($css_files, function() { $this->compileCss(); }) ->run(); @@ -53,12 +56,19 @@ class RoboFile extends \Robo\Tasks { } function compileCss() { + $css_files = array( + 'assets/css/src/admin.styl', + 'assets/css/src/newsletter_editor/newsletter_editor.styl', + 'assets/css/src/public.styl', + 'assets/css/src/rtl.styl' + ); + $this->_exec(join(' ', array( './node_modules/stylus/bin/stylus', '--include ./node_modules', '--include-css', '-u nib', - join(' ', $this->css_files), + join(' ', $css_files), '-o assets/css/' ))); } diff --git a/assets/css/src/common.styl b/assets/css/src/common.styl index f0d4eba833..a2a1a7bb2f 100644 --- a/assets/css/src/common.styl +++ b/assets/css/src/common.styl @@ -6,3 +6,10 @@ // disable outline on link focus a:focus outline: 0 none !important + +// success and error messages +.mailpoet_success + color: #090 + +.mailpoet_error + color: #900 diff --git a/assets/css/src/modal.styl b/assets/css/src/modal.styl index 39dfedcf33..9ae9bcd290 100644 --- a/assets/css/src/modal.styl +++ b/assets/css/src/modal.styl @@ -176,17 +176,6 @@ body.mailpoet_modal_opened background-color: #00ccff color: #fff -// notices -.mailpoet_success, -.mailpoet_error - display: none - -.mailpoet_success - color: #090 - -.mailpoet_error - color: #900 - @media screen and (max-width: 782px) #mailpoet_modal_overlay.mailpoet_panel_overlay top: 46px diff --git a/assets/js/src/newsletters/form.jsx b/assets/js/src/newsletters/form.jsx index 15c458e2e3..119c842182 100644 --- a/assets/js/src/newsletters/form.jsx +++ b/assets/js/src/newsletters/form.jsx @@ -1,77 +1,76 @@ define( - 'form', + 'newsletters_form', [ 'react', + 'react-router', 'jquery', 'mailpoet' ], function( React, + Router, jQuery, MailPoet ) { var Form = React.createClass({ + mixins: [ + Router.Navigation + ], getInitialState: function() { return { - disabled: false + loading: false, + errors: [] }; }, + handleSubmit: function(e) { + e.preventDefault(); + + this.setState({ loading: true }); - post: function(data) { MailPoet.Ajax.post({ endpoint: 'newsletters', action: 'save', - data: data, - onSuccess: function(response) { - }.bind(this) - }) + data: { + subject: React.findDOMNode(this.refs.subject).value, + body: React.findDOMNode(this.refs.body).value + } + }).done(function(response) { + this.setState({ loading: false }); + + if(response === true) { + this.transitionTo('/'); + } else { + this.setState({ errors: response }); + } + }.bind(this)); }, - - handleSubmit: function(e) { - e.preventDefault(); - this.setState({ - disabled: true - }); - - var subject = - React.findDOMNode(this.refs.subject); - var body = - React.findDOMNode(this.refs.body); - - if (!subject.value || !body.value) { - return; - } - - this.post({ - subject: subject.value, - body: body.value - }); - - subject.value = ''; - body.value = ''; - this.setState({ - disabled: false - }); - - return; - }, - render: function() { + var errors = this.state.errors.map(function(error, index) { + return ( +

{ error }

+ ); + }); + return ( -
-

New

-
+ + { errors } +

-
-