Added App.Wizard controller to reduce lines of code.

This commit is contained in:
Martin Edenhofer 2015-08-30 00:01:38 +02:00
parent 71c774cb99
commit cd799f0d74
6 changed files with 97 additions and 177 deletions

View file

@ -596,4 +596,45 @@ class App.Sidebar extends App.Controller
@currentTab = name
# show sidebar if not shown
@showSidebar()
@showSidebar()
class App.Wizard extends App.Controller
goToSlide: (e) =>
e.preventDefault()
slide = $(e.target).data('slide')
@showSlide(slide)
showSlide: (name) =>
@hideAlert(name)
@$('.setup.wizard').addClass('hide')
@$(".setup.wizard.#{name}").removeClass('hide')
@$(".setup.wizard.#{name} input, .setup.wizard.#{name} select").first().focus()
showAlert: (screen, message) =>
@$(".#{screen}").find('.alert').removeClass('hide').text( App.i18n.translateInline( message ) )
hideAlert: (screen) =>
@$(".#{screen}").find('.alert').addClass('hide')
hideAlerts: =>
@$('.form-group').removeClass('has-error')
@$('.alert').addClass('hide')
disable: (e) =>
@formDisable(e)
@$('.wizard-controls .btn').attr('disabled', true)
enable: (e) =>
@formEnable(e)
@$('.wizard-controls .btn').attr('disabled', false)
hide: (e) =>
e.preventDefault()
@el.modal('hide')
showInvalidField: (screen, fields) =>
@$(".#{screen}").find('.form-group').removeClass('has-error')
return if !fields
for field, type of fields
if type
@$(".#{screen}").find("[name=\"options::#{field}\"]").closest('.form-group').addClass('has-error')

View file

@ -342,7 +342,7 @@ class App.ChannelEmailAccountOverview extends App.Controller
callback: @load
)
class App.ChannelEmailAccountWizard extends App.Controller
class App.ChannelEmailAccountWizard extends App.Wizard
elements:
'.modal-body': 'body'
@ -637,43 +637,11 @@ class App.ChannelEmailAccountWizard extends App.Controller
@showAlert('js-intro', 'Unable to verify sending and receiving. Please check your settings.')
)
goToSlide: (e) =>
e.preventDefault()
slide = $(e.target).data('slide')
@showSlide(slide)
showSlide: (name) =>
@hideAlert(name)
@$('.setup.wizard').addClass('hide')
@$(".setup.wizard.#{name}").removeClass('hide')
@$(".setup.wizard.#{name} input, .setup.wizard.#{name} select").first().focus()
showAlert: (screen, message) =>
@$(".#{screen}").find('.alert').removeClass('hide').text( App.i18n.translateInline( message ) )
hideAlert: (screen) =>
@$(".#{screen}").find('.alert').addClass('hide')
disable: (e) =>
@formDisable(e)
@$('.wizard-controls .btn').attr('disabled', true)
enable: (e) =>
@formEnable(e)
@$('.wizard-controls .btn').attr('disabled', false)
showInvalidField: (screen, fields) =>
@$(".#{screen}").find('.form-group').removeClass('has-error')
return if !fields
for field, type of fields
if type
@$(".#{screen}").find("[name=\"options::#{field}\"]").closest('.form-group').addClass('has-error')
hide: (e) =>
e.preventDefault()
@el.modal('hide')
class App.ChannelEmailNotificationWizard extends App.Controller
class App.ChannelEmailNotificationWizard extends App.Wizard
elements:
'.modal-body': 'body'
@ -788,33 +756,11 @@ class App.ChannelEmailNotificationWizard extends App.Controller
else
@showSlide('js-outbound')
@showAlert('js-outbound', data.message_human || data.message )
@showInvalidField('js-outbound', data.invalid_field)
@enable(e)
fail: =>
@showSlide('js-outbound')
@showAlert('js-outbound', data.message_human || data.message )
@showInvalidField('js-outbound', data.invalid_field)
@enable(e)
)
showSlide: (name) =>
@hideAlert(name)
@$('.setup.wizard').addClass('hide')
@$(".setup.wizard.#{name}").removeClass('hide')
@$(".setup.wizard.#{name} input, .setup.wizard.#{name} select").first().focus()
showAlert: (screen, message) =>
@$(".#{screen}").find('.alert').removeClass('hide').text( App.i18n.translateInline( message ) )
hideAlert: (screen) =>
@$(".#{screen}").find('.alert').addClass('hide')
disable: (e) =>
@formDisable(e)
@$('.wizard-controls .btn').attr('disabled', true)
enable: (e) =>
@formEnable(e)
@$('.wizard-controls .btn').attr('disabled', false)
hide: (e) =>
e.preventDefault()
@el.modal('hide')

View file

@ -1,4 +1,4 @@
class Index extends App.ControllerContent
class Index extends App.Controller
className: 'getstarted fit'
constructor: ->
@ -61,7 +61,7 @@ class Index extends App.ControllerContent
App.Config.set( 'getting_started', Index, 'Routes' )
class AutoWizard extends App.ControllerContent
class AutoWizard extends App.Controller
className: 'getstarted fit'
constructor: ->
@ -130,7 +130,7 @@ App.Config.set( 'getting_started/auto_wizard', AutoWizard, 'Routes' )
App.Config.set( 'getting_started/auto_wizard/:token', AutoWizard, 'Routes' )
class Admin extends App.ControllerContent
class Admin extends App.Controller
className: 'getstarted fit'
events:
'submit form': 'submit'
@ -247,7 +247,7 @@ class Admin extends App.ControllerContent
App.Config.set( 'getting_started/admin', Admin, 'Routes' )
class Base extends App.ControllerContent
class Base extends App.Wizard
className: 'getstarted fit'
elements:
'.logo-preview': 'logoPreview'
@ -376,25 +376,10 @@ class Base extends App.ControllerContent
# add resized image
App.ImageService.resizeForApp( @params.logo, @logoPreview.width(), @logoPreview.height(), store )
hideAlerts: =>
@$('.form-group').removeClass('has-error')
@$('.alert').addClass('hide')
showAlert: (field, message) =>
@$("[name=#{field}]").closest('.form-group').addClass('has-error')
@$("[name=#{field}]").closest('.form-group').find('.alert').removeClass('hide').text( App.i18n.translateInline( message ) )
disable: (e) =>
@formDisable(e)
@$('.wizard-controls .btn').attr('disabled', true)
enable: (e) =>
@formEnable(e)
@$('.wizard-controls .btn').attr('disabled', false)
App.Config.set( 'getting_started/base', Base, 'Routes' )
class EmailNotification extends App.ControllerContent
class EmailNotification extends App.Wizard
className: 'getstarted fit'
events:
'change .js-outbound [name=adapter]': 'toggleOutboundAdapter'
@ -504,42 +489,20 @@ class EmailNotification extends App.ControllerContent
else
@showSlide('js-outbound')
@showAlert('js-outbound', data.message_human || data.message )
@showInvalidField('js-outbound', data.invalid_field)
@enable(e)
fail: =>
@showSlide('js-outbound')
@showAlert('js-outbound', data.message_human || data.message )
@showInvalidField('js-outbound', data.invalid_field)
@enable(e)
)
goToSlide: (e) =>
e.preventDefault()
slide = $(e.target).data('slide')
@showSlide(slide)
showSlide: (name) =>
@hideAlert(name)
@$('.setup.wizard').addClass('hide')
@$(".setup.wizard.#{name}").removeClass('hide')
@$(".setup.wizard.#{name} input, .setup.wizard.#{name} select").first().focus()
showAlert: (screen, message) =>
@$(".#{screen}").find('.alert').removeClass('hide').text( App.i18n.translateInline( message ) )
hideAlert: (screen) =>
@$(".#{screen}").find('.alert').addClass('hide')
disable: (e) =>
@formDisable(e)
@$('.wizard-controls .btn').attr('disabled', true)
enable: (e) =>
@formEnable(e)
@$('.wizard-controls .btn').attr('disabled', false)
App.Config.set( 'getting_started/email_notification', EmailNotification, 'Routes' )
class Channel extends App.ControllerContent
class Channel extends App.Controller
className: 'getstarted fit'
constructor: ->
@ -592,7 +555,7 @@ class Channel extends App.ControllerContent
App.Config.set( 'getting_started/channel', Channel, 'Routes' )
class ChannelEmailPreConfigured extends App.ControllerContent
class ChannelEmailPreConfigured extends App.Controller
className: 'getstarted fit'
constructor: ->
@ -637,7 +600,7 @@ class ChannelEmailPreConfigured extends App.ControllerContent
App.Config.set( 'getting_started/channel/email_pre_configured', ChannelEmailPreConfigured, 'Routes' )
class ChannelEmail extends App.ControllerContent
class ChannelEmail extends App.Wizard
className: 'getstarted fit'
events:
'submit .js-intro': 'probeBasedOnIntro'
@ -896,42 +859,9 @@ class ChannelEmail extends App.ControllerContent
@showAlert('js-intro', 'Unable to verify sending and receiving. Please check your settings.' )
)
goToSlide: (e) =>
e.preventDefault()
slide = $(e.target).data('slide')
@showSlide(slide)
showSlide: (name) =>
@hideAlert(name)
@$('.setup.wizard').addClass('hide')
@$(".setup.wizard.#{name}").removeClass('hide')
@$(".setup.wizard.#{name} input, .setup.wizard.#{name} select").first().focus()
showAlert: (screen, message) =>
@$(".#{screen}").find('.alert').removeClass('hide').text( App.i18n.translateInline( message ) )
hideAlert: (screen) =>
@$(".#{screen}").find('.alert').addClass('hide')
disable: (e) =>
@formDisable(e)
@$('.wizard-controls .btn').attr('disabled', true)
enable: (e) =>
@formEnable(e)
@$('.wizard-controls .btn').attr('disabled', false)
showInvalidField: (screen, fields) =>
@$(".#{screen}").find('.form-group').removeClass('has-error')
return if !fields
for field, type of fields
if type
@$(".#{screen}").find("[name=\"options::#{field}\"]").closest('.form-group').addClass('has-error')
App.Config.set( 'getting_started/channel/email', ChannelEmail, 'Routes' )
class Agent extends App.ControllerContent
class Agent extends App.Controller
className: 'getstarted fit'
events:
'submit form': 'submit'
@ -1031,7 +961,7 @@ class Agent extends App.ControllerContent
App.Config.set( 'getting_started/agents', Agent, 'Routes' )
class Channel extends App.ControllerContent
class Channel extends App.Controller
className: 'getstarted fit'
constructor: ->

View file

@ -69,35 +69,37 @@
<a data-type="new" class="btn btn--success"><%- @T('New') %></a>
<h1><%- @T('Notification Account') %></h1>
<% if @channel && !App.Config.get('system_online_service'): %>
<h1><%- @T('Notification Account') %></h1>
<table class="table table-hover user-list">
<thead>
<tr>
<th><%- @T('Outbound') %></th>
</tr>
</thead>
<tbody>
<tr data-id="<%- @channel.id %>">
<td class="<% if @channel.status_out is 'ok': %>success<% else if @channel.status_out is 'error': %>danger<% else: %>warning<% end %>">
<%- @T('State') %>: <%- @T(@channel.status_out || 'unknown') %><br>
<a href="#" data-type="edit-notification-outbound">
<% if @channel.options.outbound && @channel.options.outbound.options: %>
<%= @channel.options.outbound.options.user %><br>
<%= @channel.options.outbound.options.host %>
<% end %>
(<%= @channel.options.outbound.adapter %>)</a>
</td>
</tr>
<% if @channel.status_in is 'error': %>
<tr>
<td colspan="1"><%= @channel.last_log_in %></td>
</tr>
<% end %>
<% if @channel.status_out is 'error': %>
<tr>
<td colspan="1"><%= @channel.last_log_out %></td>
</tr>
<% end %>
</tbody>
</table>
<table class="table table-hover user-list">
<thead>
<tr>
<th><%- @T('Outbound') %></th>
</tr>
</thead>
<tbody>
<tr data-id="<%- @channel.id %>">
<td class="<% if @channel.status_out is 'ok': %>success<% else if @channel.status_out is 'error': %>danger<% else: %>warning<% end %>">
<%- @T('State') %>: <%- @T(@channel.status_out || 'unknown') %><br>
<a href="#" data-type="edit-notification-outbound">
<% if @channel.options.outbound && @channel.options.outbound.options: %>
<%= @channel.options.outbound.options.user %><br>
<%= @channel.options.outbound.options.host %>
<% end %>
(<%= @channel.options.outbound.adapter %>)</a>
</td>
</tr>
<% if @channel.status_in is 'error': %>
<tr>
<td colspan="1"><%= @channel.last_log_in %></td>
</tr>
<% end %>
<% if @channel.status_out is 'error': %>
<tr>
<td colspan="1"><%= @channel.last_log_out %></td>
</tr>
<% end %>
</tbody>
</table>
<% end %>

View file

@ -2,6 +2,7 @@
<svg class="wizard-logo icon-full-logo"><use xlink:href="#icon-full-logo" /></svg>
<form class="setup wizard js-outbound">
<input type="password" style="display:none"/><!-- dummy to prevent chrome to ask for password save -->
<div class="wizard-slide">
<h2><%- @T('Email Notification') %></h2>
<div class="wizard-body vertical justified">

View file

@ -216,14 +216,14 @@ curl http://localhost/api/v1/channels.json -v -u #{login}:#{password} -H "Conten
def email_index
return if deny_if_not_role(Z_ROLENAME_ADMIN)
system_online_service = Setting.get('system_online_service')
assets = {}
Channel.all.each {|channel|
next if channel.preferences && channel.preferences[:online_service_disable]
next if system_online_service && channel.preferences && channel.preferences[:online_service_disable]
assets = channel.assets(assets)
}
EmailAddress.all.each {|email_address|
next if email_address.preferences && email_address.preferences[:online_service_disable]
next if system_online_service && email_address.preferences && email_address.preferences[:online_service_disable]
assets = email_address.assets(assets)
}
render json: {