diff --git a/app/assets/javascripts/app/controllers/_channel/email.js.coffee b/app/assets/javascripts/app/controllers/_channel/email.js.coffee index ccef65c00..d3f6e1a28 100644 --- a/app/assets/javascripts/app/controllers/_channel/email.js.coffee +++ b/app/assets/javascripts/app/controllers/_channel/email.js.coffee @@ -1,17 +1,24 @@ $ = jQuery.sub() +$.fn.item = (genericObject) -> + elementID = $(@).data('id') + elementID or= $(@).parents('[data-id]').data('id') + genericObject.find(elementID) + class App.ChannelEmail extends App.ControllerTabs constructor: -> super @tabs = [ { - name: 'Inbound', - target: 'c-inbound', + name: 'Inbound', + target: 'c-inbound', + controller: App.ChannelEmailInbound, }, { - name: 'Outbound', - target: 'c-outbound', + name: 'Outbound', + target: 'c-outbound', + controller: App.ChannelEmailOutbound, }, { name: 'Adresses', @@ -28,84 +35,197 @@ class App.ChannelEmail extends App.ControllerTabs }, ] -# App.Channel.bind 'refresh change', @render -# App.Channel.fetch() @render() - render2: => - settings = App.Setting.all() +class App.ChannelEmailInboundEdit extends App.ControllerModal + constructor: -> + super + @render(@object) + + render: (data = {}) -> + + configure_attributes = [ + { name: 'adapter', display: 'Type', tag: 'select', multiple: false, null: false, options: { IMAP: 'IMAP', POP3: 'POP3' } , class: 'span4', default: data['adapter'] }, + { name: 'host', display: 'Host', tag: 'input', type: 'text', limit: 120, null: false, class: 'span4', autocapitalize: false, default: (data['options']&&data['options']['host']) }, + { name: 'user', display: 'User', tag: 'input', type: 'text', limit: 120, null: false, class: 'span4', autocapitalize: false, default: (data['options']&&data['options']['user']) }, + { name: 'password', display: 'Password', tag: 'input', type: 'password', limit: 120, null: false, class: 'span4', autocapitalize: false, default: (data['options']&&data['options']['password']) }, + { name: 'ssl', display: 'SSL', tag: 'select', multiple: false, null: false, options: { true: 'yes', false: 'no' } , class: 'span4', default: (data['options']&&data['options']['ssl']) }, + { name: 'group_id', display: 'Group', tag: 'select', multiple: false, null: false, filter: @edit_form, nulloption: false, relation: 'Group', class: 'span4', default: data['group_id'] }, + { name: 'active', display: 'Active', tag: 'select', multiple: false, null: false, options: { true: 'yes', false: 'no' } , class: 'span4', default: data['active'] }, + ] + form = @formGen( model: { configure_attributes: configure_attributes, className: '' } ) + + @html App.view('generic/admin/new')( + form: form, + head: 'New Channel' + ) + @modalShow() + + submit: (e) => + e.preventDefault() + + # get params + params = @formParam(e.target) + + object = @object || new App.Channel + object.load( + area: 'Email::Inbound', + adapter: params['adapter'], + group_id: params['group_id'], + options: { + host: params['host'], + user: params['user'], + password: params['password'], + ssl: params['ssl'], + }, + host: params['host'], + user: params['user'], + password: params['password'], + active: params['active'], + ) + + # validate form + errors = object.validate() - html = $('
') - for setting in settings - if setting.area is @area - item = new App.SettingsAreaItem( setting: setting ) - html.append( item.el ) + # show errors in form + if errors + @log 'error new', errors + @validateForm( form: e.target, errors: errors ) + return false - @html html + # save object + object.save( + success: => + @modalHide() + error: => + @log 'errors' + @modalHide() + ) - -class App.SettingsAreaItem2 extends App.Controller +class App.ChannelEmailInbound extends App.Controller events: - 'submit form': 'update', + 'click [data-type=new]': 'new' + 'click [data-type=edit]': 'edit' constructor: -> super - @render() + + App.Channel.bind 'refresh change', @render + App.Channel.fetch() render: => - # defaults - for item in @setting.options['form'] - if typeof @setting.state.value is 'object' - item['default'] = @setting.state.value[item.name] - else - item['default'] = @setting.state.value + channels = App.Channel.all() + + html = $('
') + data = [] + for channel in channels + if channel.area is 'Email::Inbound' + channel.host = channel.options['host'] + channel.user = channel.options['user'] + data.push channel - # form - @configure_attributes = @setting.options['form'] - form = @formGen( model: { configure_attributes: @configure_attributes, className: '' }, autofocus: false ) + table = @table( + overview: ['host', 'user', 'adapter', 'active'], + model: App.Channel, + objects: data, + ) - # item - @html App.view('settings/item')( - setting: @setting, - form: form, - ) + html.append( table ) + html.append( 'new account' ) + @html html + + new: (e) => + e.preventDefault() + new App.ChannelEmailInboundEdit() + + edit: (e) => + e.preventDefault() + item = $(e.target).item( App.Channel ) + new App.ChannelEmailInboundEdit( object: item ) + + +class App.ChannelEmailOutbound extends App.Controller + events: + 'change #_adapter': 'toggle' + 'submit #mail_adapter': 'update' + + constructor: -> + super + + App.Channel.bind 'refresh change', @render + App.Channel.fetch() + + render: => + channels = App.Channel.all() + data = [] + adapters = {} + adapter_used = undefined + channel_used = undefined + for channel in channels + if channel.area is 'Email::Outbound' + + data.push channel + adapters[channel.adapter] = channel.adapter + if @adapter_used + if @adapter_used is channel.adapter + adapter_used = channel.adapter + channel_used = channel + else if channel.active is true + adapter_used = channel.adapter + channel_used = channel + + configure_attributes = [ + { name: 'adapter', display: 'Send Mails via', tag: 'select', multiple: false, null: false, options: adapters , class: 'span4', default: adapter_used }, + ] + form_adapter = @formGen( model: { configure_attributes: configure_attributes, className: '' } ) + + if adapter_used is 'SMTP' + configure_attributes = [ + { name: 'host', display: 'Host', tag: 'input', type: 'text', limit: 120, null: false, class: 'span4', autocapitalize: false, default: (channel_used['options']&&channel_used['options']['host']) }, + { name: 'user', display: 'User', tag: 'input', type: 'text', limit: 120, null: true, class: 'span4', autocapitalize: false, default: (channel_used['options']&&channel_used['options']['user']) }, + { name: 'password', display: 'Password', tag: 'input', type: 'password', limit: 120, null: true, class: 'span4', autocapitalize: false, default: (channel_used['options']&&channel_used['options']['password']) }, + { name: 'ssl', display: 'SSL', tag: 'select', multiple: false, null: false, options: { true: 'yes', false: 'no' } , class: 'span4', default: (channel_used['options']&&channel_used['options']['ssl']) }, + ] + form_adapter_settings = @formGen( model: { configure_attributes: configure_attributes, className: '' } ) + + html = App.view('channel/email_outbound')( + form_adapter: form_adapter, + form_adapter_settings: form_adapter_settings, + ) + html = $(html) + @html html + + toggle: (e) => + + # get params + params = @formParam(e.target) + + @adapter_used = params['adapter'] + + @render() update: (e) => e.preventDefault() - params = @formParam(e.target) - @log 'submit', @setting, params, e.target - if typeof @setting.state.value is 'object' - state = { - value: params - } - else - state = { - value: params[@setting.name] - } + params = @formParam(e.target) + channels = App.Channel.all() + for channel in channels + if channel.area is 'Email::Outbound' && channel.adapter is params['adapter'] + channel.updateAttributes( + options: { + host: params['host'], + user: params['user'], + password: params['password'], + ssl: params['ssl'], + }, + active: true, + ) - @setting['state'] = state - @setting.save( - success: => + # set all other to inactive + channels = App.Channel.all() + for channel in channels + if channel.area is 'Email::Outbound' && channel.adapter isnt params['adapter'] + channel.updateAttributes( active: false ) - # login check - auth = new App.Auth - auth.loginCheck() - ) - -class App.ChannelEmail2 extends App.Controller - events: - 'click [data-toggle="tabnav"]': 'toggle', - - constructor: -> - super - - # render page + # rerender @render() - - render: -> - - @html App.view('channel/email')( - head: 'some header' - ) - diff --git a/app/assets/javascripts/app/controllers/channel.js.coffee b/app/assets/javascripts/app/controllers/channel.js.coffee index f3bc38d35..fc8bcd41f 100644 --- a/app/assets/javascripts/app/controllers/channel.js.coffee +++ b/app/assets/javascripts/app/controllers/channel.js.coffee @@ -1,14 +1,15 @@ $ = jQuery.sub() class Index extends App.ControllerLevel2 - toggleable: true +# toggleable: true + toggleable: false menu: [ - { name: 'Web', 'target': 'web', controller: App.ChannelWeb }, - { name: 'Mail', 'target': 'email', controller: App.ChannelEmail }, - { name: 'Chat', 'target': 'chat', controller: App.ChannelChat }, - { name: 'Twitter', 'target': 'twitter', controller: App.ChannelTwitter }, - { name: 'Facebook', 'target': 'facebook', controller: App.ChannelFacebook }, + { name: 'Web', target: 'web', controller: App.ChannelWeb }, + { name: 'Mail', target: 'email', controller: App.ChannelEmail }, + { name: 'Chat', target: 'chat', controller: App.ChannelChat }, + { name: 'Twitter', target: 'twitter', controller: App.ChannelTwitter }, + { name: 'Facebook', target: 'facebook', controller: App.ChannelFacebook }, ] page: { title: 'Channels', @@ -24,5 +25,6 @@ class Index extends App.ControllerLevel2 # render page @render() +Config.Routes['channels/:target'] = Index Config.Routes['channels'] = Index diff --git a/app/assets/javascripts/app/controllers/settings.js.coffee b/app/assets/javascripts/app/controllers/settings.js.coffee index 29da305ff..a5c502855 100644 --- a/app/assets/javascripts/app/controllers/settings.js.coffee +++ b/app/assets/javascripts/app/controllers/settings.js.coffee @@ -2,7 +2,7 @@ $ = jQuery.sub() class Index extends App.ControllerLevel2 toggleable: false - toggleable: true +# toggleable: true constructor: -> super diff --git a/app/assets/javascripts/app/models/channel.js.coffee b/app/assets/javascripts/app/models/channel.js.coffee new file mode 100644 index 000000000..f7622169e --- /dev/null +++ b/app/assets/javascripts/app/models/channel.js.coffee @@ -0,0 +1,14 @@ +class App.Channel extends App.Model + @configure 'Channel', 'adapter', 'area', 'options', 'group_id', 'active' + @extend Spine.Model.Ajax + + @configure_attributes = [ + { name: 'adapter', display: 'Adapter', tag: 'input', type: 'text', limit: 100, null: false, 'class': 'xlarge' }, + { name: 'area', display: 'Area', tag: 'input', type: 'text', limit: 100, null: false, 'class': 'xlarge' }, +# { name: 'host', display: 'Host', tag: 'input', type: 'text', limit: 100, null: false, 'class': 'xlarge' }, +# { name: 'user', display: 'User', tag: 'input', type: 'text', limit: 100, null: false, 'class': 'xlarge' }, +# { name: 'password', display: 'Password', tag: 'input', type: 'text', limit: 100, null: fa, 'class': 'xlarge' }, + { name: 'options', display: 'Area', tag: 'input', type: 'text', limit: 100, null: false, 'class': 'xlarge' }, + { name: 'group_id', display: 'Group', tag: 'option', type: 'text', limit: 100, null: true, 'class': 'xlarge' }, + { name: 'active', display: 'Active', tag: 'boolean', type: 'boolean', 'default': true, null: true, 'class': 'xlarge' }, + ] \ No newline at end of file diff --git a/app/assets/javascripts/app/views/channel/email.jst.eco b/app/assets/javascripts/app/views/channel/email.jst.eco deleted file mode 100644 index 93f76beac..000000000 --- a/app/assets/javascripts/app/views/channel/email.jst.eco +++ /dev/null @@ -1,72 +0,0 @@ -
- - - - - - - - - - - - - - - - - - - - - - - -
HostUserTypeActiveDelete
lalal.example.comwpt234rwrIMAPtruex
l31alal.example.comwpt23dd4rwrPOP3truex
- -
-
- - - - - - - - - - - - - - - - - - - - - - - -
HostUserTypeActiveDelete
lalal.example.comwpt234rwrSMTPtruex
l31alal.example.comwpt23dd4rwrSendmailtruex
-
-
- - - - - - - - - - - - - - - - -
NameActiveDelete
lalal.example.comtruex
wpt23dd4rwrtruex
-
diff --git a/app/assets/javascripts/app/views/channel/email_outbound.jst.eco b/app/assets/javascripts/app/views/channel/email_outbound.jst.eco new file mode 100644 index 000000000..d76457b9f --- /dev/null +++ b/app/assets/javascripts/app/views/channel/email_outbound.jst.eco @@ -0,0 +1,5 @@ +
+ <%- @form_adapter %> + <%- @form_adapter_settings %> +