diff --git a/app/assets/javascripts/app/controllers/layout_ref.js.coffee b/app/assets/javascripts/app/controllers/layout_ref.js.coffee index 6a1e58096..749a86f68 100644 --- a/app/assets/javascripts/app/controllers/layout_ref.js.coffee +++ b/app/assets/javascripts/app/controllers/layout_ref.js.coffee @@ -1310,6 +1310,9 @@ App.Config.set( 'layout_ref/sla', slaRef, 'Routes' ) class schedulersRef extends App.ControllerContent + events: + 'click .select-value': 'select' + constructor: -> super @render() @@ -1317,6 +1320,52 @@ class schedulersRef extends App.ControllerContent render: -> @html App.view('layout_ref/schedulers')() + select: (event) => + target = $(event.currentTarget) + + if target.hasClass('is-selected') + # prevent zero selections + if target.siblings('.is-selected').size() > 0 + target.removeClass('is-selected') + else + target.addClass('is-selected') + + @createOutputString() + + createOutputString: -> + days = $.map(@$('[data-type=day]').filter('.is-selected'), (el) -> return $(el).text() ) + hours = $.map(@$('[data-type=hour]').filter('.is-selected'), (el) -> return $(el).text() ) + minutes = $.map(@$('[data-type=minute]').filter('.is-selected'), (el) -> return $(el).text() ) + + hours = @injectMinutes(hours, minutes) + + days = @joinItems days + hours = @joinItems hours + + @$('.js-timerResult').text("Run every #{ days } at #{ hours }") + + injectMinutes: (hours, minutes) -> + newHours = [] # hours.length x minutes.length long + + for hour in hours + # split off am/pm + [hour, suffix] = hour.split(" ") + + for minute in minutes + combined = "#{ hour }:#{ minute }" + combined += " #{suffix}" if suffix + + newHours.push combined + + return newHours + + joinItems: (items) -> + switch items.length + when 1 then return items[0] + when 2 then return "#{ items[0] } and #{ items[1] }" + else + return "#{ items.slice(0, -1).join(', ') } and #{ items[items.length-1] }" + App.Config.set( 'layout_ref/schedulers', schedulersRef, 'Routes' ) diff --git a/app/assets/javascripts/app/views/layout_ref/schedulers.jst.eco b/app/assets/javascripts/app/views/layout_ref/schedulers.jst.eco index 1d498c5b5..1a909afb4 100644 --- a/app/assets/javascripts/app/views/layout_ref/schedulers.jst.eco +++ b/app/assets/javascripts/app/views/layout_ref/schedulers.jst.eco @@ -166,80 +166,61 @@
When should the job run?
Day - | Hour - | Minute - | ||
---|---|---|---|---|
- | - | - | - | - |
- | - | - | - | - |
- | - | - | - | - |
- | - | - | - | - |
- | - | - | - | - |
- | - | - | - | - |
- | - | - | - | - |
- | - | - | - | - |