diff --git a/app/models/rule.rb b/app/models/rule.rb index e485deb..44c0125 100644 --- a/app/models/rule.rb +++ b/app/models/rule.rb @@ -61,21 +61,14 @@ class DiscourseChat::Rule < DiscourseChat::PluginModel end end - # Don't want this to end up as anything other than an integer - def category_id=(val) - if val.nil? or val.blank? - super(nil) - else - super(val.to_i) - end - end - - # Don't want this to end up as anything other than an integer - def channel_id=(val) - if val.nil? or val.blank? - super(nil) - else - super(val.to_i) + # These are only allowed to be integers + %w(channel_id category_id group_id).each do |name| + define_method "#{name}=" do |val| + if val.nil? or val.blank? + super(nil) + else + super(val.to_i) + end end end diff --git a/assets/javascripts/admin/components/channel-data.js.es6 b/assets/javascripts/admin/components/channel-data.js.es6 new file mode 100644 index 0000000..259fb6c --- /dev/null +++ b/assets/javascripts/admin/components/channel-data.js.es6 @@ -0,0 +1,3 @@ +export default Ember.Component.extend({ + classNames: ['channel-info'], +}); \ No newline at end of file diff --git a/assets/javascripts/admin/components/channel-details.js.es6 b/assets/javascripts/admin/components/channel-details.js.es6 index 08fcd1b..3b9195c 100644 --- a/assets/javascripts/admin/components/channel-details.js.es6 +++ b/assets/javascripts/admin/components/channel-details.js.es6 @@ -26,8 +26,11 @@ export default Ember.Component.extend({ }, createRule(channel){ - var newRule = this.get('store').createRecord('rule',{channel_id: channel.id}); - channel.rules.pushObject(newRule) + this.sendAction('createRule', channel) + }, + + editRule(rule){ + this.sendAction('editRule', rule, this.get('channel')) }, showError(error_key){ diff --git a/assets/javascripts/admin/components/rule-row.js.es6 b/assets/javascripts/admin/components/rule-row.js.es6 index 7622fa1..9782507 100644 --- a/assets/javascripts/admin/components/rule-row.js.es6 +++ b/assets/javascripts/admin/components/rule-row.js.es6 @@ -2,37 +2,21 @@ import { popupAjaxError } from 'discourse/lib/ajax-error'; export default Ember.Component.extend({ tagName: 'tr', - editing: false, - - autoEdit: function(){ - if(!this.get('rule').id){ - this.set('editing', true); - } - }.on('init'), actions: { edit: function(){ - this.set('editing', true); + this.sendAction('edit', this.get('rule')) }, - - cancel: function(){ - this.send('refresh'); - }, - - save: function(){ - this.get('rule').save().then(result => { - this.send('refresh'); - }).catch(popupAjaxError); - }, - delete(rule){ rule.destroyRecord().then(() => { this.send('refresh'); }).catch(popupAjaxError) }, - refresh: function(){ this.sendAction('refresh'); } + + + } }); \ No newline at end of file diff --git a/assets/javascripts/admin/controllers/admin-plugins-chat-provider.js.es6 b/assets/javascripts/admin/controllers/admin-plugins-chat-provider.js.es6 index f52965c..c3f90e6 100644 --- a/assets/javascripts/admin/controllers/admin-plugins-chat-provider.js.es6 +++ b/assets/javascripts/admin/controllers/admin-plugins-chat-provider.js.es6 @@ -35,6 +35,17 @@ export default Ember.Controller.extend({ showModal('admin-plugins-chat-test', { model: model, admin: true }); }, + createRule(channel){ + this.set('modalShowing', true); + var model = {rule: this.store.createRecord('rule',{channel_id: channel.id}), channel:channel, provider:this.get('model.provider')}; + showModal('admin-plugins-chat-edit-rule', { model: model, admin: true }); + }, + editRule(rule, channel){ + this.set('modalShowing', true); + var model = {rule: rule, channel:channel, provider:this.get('model.provider')}; + showModal('admin-plugins-chat-edit-rule', { model: model, admin: true }); + }, + } }); \ No newline at end of file diff --git a/assets/javascripts/admin/controllers/modals/admin-plugins-chat-edit-rule.js.es6 b/assets/javascripts/admin/controllers/modals/admin-plugins-chat-edit-rule.js.es6 new file mode 100644 index 0000000..220d525 --- /dev/null +++ b/assets/javascripts/admin/controllers/modals/admin-plugins-chat-edit-rule.js.es6 @@ -0,0 +1,42 @@ +import Rule from 'discourse/plugins/discourse-chat-integration/admin/models/rule' +import ModalFunctionality from 'discourse/mixins/modal-functionality'; +import { ajax } from 'discourse/lib/ajax'; +import { extractError } from 'discourse/lib/ajax-error'; +import InputValidation from 'discourse/models/input-validation'; + +export default Ember.Controller.extend(ModalFunctionality, { + + setupKeydown: function() { + Ember.run.schedule('afterRender', () => { + $('#chat_integration_edit_channel_modal').keydown(e => { + if (e.keyCode === 13) { + this.send('save'); + } + }); + }); + }.on('init'), + + + saveDisabled: function(){ + return false; + }.property(), + + actions: { + cancel: function(){ + this.send('closeModal'); + }, + + save: function(){ + if(this.get('saveDisabled')){return}; + + const self = this; + + this.get('model.rule').save().then(function(result) { + self.send('closeModal'); + }).catch(function(error) { + self.flash(extractError(error), 'error'); + }); + + } + } +}); \ No newline at end of file diff --git a/assets/javascripts/admin/models/rule.js.es6 b/assets/javascripts/admin/models/rule.js.es6 index 44fe2c8..f225d45 100644 --- a/assets/javascripts/admin/models/rule.js.es6 +++ b/assets/javascripts/admin/models/rule.js.es6 @@ -30,12 +30,12 @@ export default RestModel.extend({ }, updateProperties() { - var prop_names = ['category_id','tags','filter']; + var prop_names = ['category_id','group_id','tags','filter']; return this.getProperties(prop_names); }, createProperties() { - var prop_names = ['channel_id', 'category_id','tags','filter']; + var prop_names = ['channel_id', 'category_id','group_id','tags','filter']; return this.getProperties(prop_names); } diff --git a/assets/javascripts/admin/templates/modal/admin-plugins-chat-edit-rule.hbs b/assets/javascripts/admin/templates/modal/admin-plugins-chat-edit-rule.hbs new file mode 100644 index 0000000..d7e4c68 --- /dev/null +++ b/assets/javascripts/admin/templates/modal/admin-plugins-chat-edit-rule.hbs @@ -0,0 +1,81 @@ +{{#d-modal-body id="chat_integration_edit_rule_modal" title="chat_integration.edit_rule_modal.title"}} +