From fadbb57188d3818860f47819b683affb5b183826 Mon Sep 17 00:00:00 2001 From: zinyando Date: Wed, 27 Jul 2016 13:18:57 +0200 Subject: [PATCH] Refactor general settings route --- app/app/components/general-settings.js | 51 +++++++++++++++++++ app/app/pods/customize/general/controller.js | 21 +++----- app/app/pods/customize/general/template.hbs | 28 +--------- .../templates/components/general-settings.hbs | 27 ++++++++++ 4 files changed, 86 insertions(+), 41 deletions(-) create mode 100644 app/app/components/general-settings.js create mode 100644 app/app/templates/components/general-settings.hbs diff --git a/app/app/components/general-settings.js b/app/app/components/general-settings.js new file mode 100644 index 00000000..9a9028a6 --- /dev/null +++ b/app/app/components/general-settings.js @@ -0,0 +1,51 @@ +import Ember from 'ember'; + +const { + isEmpty, + isPresent, + computed, + get, + set +} = Ember; + +export default Ember.Component.extend({ + titleInputError: computed('titleError', 'model.title', { + get() { + let error = get(this, 'titleError'); + let title = this.get('model.title'); + if (isPresent(error) || isEmpty(title)) { + return `error`; + } + + return; + } + }), + messageInputError: computed('messageError', 'model.message', { + get() { + let error = get(this, 'messageError'); + let message = this.get('model.message'); + if (isPresent(error) || isEmpty(message)) { + return `error`; + } + + return; + } + }), + + actions: { + save() { + if (isEmpty(this.model.get('title'))) { + set(this, 'titleError', 'error'); + return $("#siteTitle").focus(); + } + + if (isEmpty(this.model.get('message'))) { + set(this, 'messageError', 'error'); + return $("#siteMessage").focus(); + } + + this.model.set('allowAnonymousAccess', Ember.$("#allowAnonymousAccess").prop('checked')); + this.get('save')(); + } + } +}); diff --git a/app/app/pods/customize/general/controller.js b/app/app/pods/customize/general/controller.js index 501c0d2b..af81a271 100644 --- a/app/app/pods/customize/general/controller.js +++ b/app/app/pods/customize/general/controller.js @@ -1,35 +1,28 @@ // Copyright 2016 Documize Inc. . All rights reserved. // -// This software (Documize Community Edition) is licensed under +// This software (Documize Community Edition) is licensed under // GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html // // You can operate outside the AGPL restrictions by purchasing // Documize Enterprise Edition and obtaining a commercial license -// by contacting . +// by contacting . // // https://documize.com import Ember from 'ember'; import NotifierMixin from "../../../mixins/notifier"; +const { + isEmpty +} = Ember; + export default Ember.Controller.extend(NotifierMixin, { orgService: Ember.inject.service('organization'), actions: { save() { - if (is.empty(this.model.get('title'))) { - $("#siteTitle").addClass("error").focus(); - return; - } - - if (is.empty(this.model.get('message'))) { - $("#siteMessage").addClass("error").focus(); - return; - } - - this.model.set('allowAnonymousAccess', Ember.$("#allowAnonymousAccess").prop('checked')); this.get('orgService').save(this.model); this.showNotification('Saved'); } } -}); \ No newline at end of file +}); diff --git a/app/app/pods/customize/general/template.hbs b/app/app/pods/customize/general/template.hbs index c161a5c8..adb167fa 100644 --- a/app/app/pods/customize/general/template.hbs +++ b/app/app/pods/customize/general/template.hbs @@ -1,29 +1,3 @@
-
-
-
General Settings
-
Tell people about this Documize instance
-
-
-
- -
Describe the title of this Documize instance
- {{focus-input id="siteTitle" type="text" value=model.title}} -
-
- -
Describe the purpose of this Documize instance
- {{textarea id="siteMessage" rows="3" value=model.message}} -
-
- -
Content within "Everyone" will be made available to anonymous users
-
- - -
-
-
save
-
-
+{{general-settings model=model save=(action 'save')}}
diff --git a/app/app/templates/components/general-settings.hbs b/app/app/templates/components/general-settings.hbs new file mode 100644 index 00000000..70b22638 --- /dev/null +++ b/app/app/templates/components/general-settings.hbs @@ -0,0 +1,27 @@ +
+
+
General Settings
+
Tell people about this Documize instance
+
+
+
+ +
Describe the title of this Documize instance
+ {{focus-input id="siteTitle" type="text" value=model.title class=titleInputError}} +
+
+ +
Describe the purpose of this Documize instance
+ {{textarea id="siteMessage" rows="3" value=model.message class=messageInputError}} +
+
+ +
Content within "Everyone" will be made available to anonymous users
+
+ + +
+
+
save
+
+