app/assets/javascripts/formagic/inputs/datetime.coffee in formagic-0.3.4 vs app/assets/javascripts/formagic/inputs/datetime.coffee in formagic-0.3.7
- old
+ new
@@ -1,25 +1,18 @@
# -----------------------------------------------------------------------------
# Author: Alexander Kravets <alex@slatestudio.com>,
# Slate Studio (http://www.slatestudio.com)
-#
-# Coding Guide:
-# https://github.com/thoughtbot/guides/tree/master/style/coffeescript
# -----------------------------------------------------------------------------
-
-# -----------------------------------------------------------------------------
# INPUT DATE
# -----------------------------------------------------------------------------
-#
# Dependencies:
#= require vendor/datedropper
#= require vendor/moment
-#
# -----------------------------------------------------------------------------
class @InputDatetime extends InputDate
- # PRIVATE ===============================================
+ # PRIVATE ===================================================================
_update_value: ->
mt = moment(@$inputTime.val(), 'LT')
if @$inputDate.val() == '' && ! mt.isValid()
@@ -34,36 +27,31 @@
value = [ date_string, time_string ].join('T')
@$input.val(value)
-
_update_date_input: ->
m = moment(@$input.val()).utcOffset(@tzOffset)
@$inputDate.val ( if m.isValid() then m.format('YYYY-MM-DD') else '' )
-
_update_time_input: ->
m = moment(@$input.val()).utcOffset(@tzOffset)
@$inputTime.val ( if m.isValid() then m.format('h:mm a') else '' )
-
_update_date_label: ->
m = moment(@$inputDate.val()).utcOffset(@tzOffset)
label = if m.isValid() then m.format('dddd, MMM D, YYYY') else "<span class='placeholder'>Pick a date</span>"
@$dateLabel.html label
-
_normalized_value: ->
# -- use local timezone to represent time
@tzOffset = @config.timezoneOffset
@tzOffset ?= (new Date()).getTimezoneOffset() * -1
m = moment(@value).utcOffset(@tzOffset)
@value = if m.isValid() then m.format() else ''
-
_add_input: ->
@_normalized_value()
# -- hidden
@$input =$ "<input type='hidden' name='#{ @name }' value='#{ @value }' />"
@@ -95,32 +83,29 @@
@_update_time_input()
@_add_actions()
-
_add_actions: ->
@$actions =$ "<span class='input-actions'></span>"
@$label.append @$actions
- @_add_remove_button()
+ if not @config.disableClear
+ @_add_clear_button()
-
- _add_remove_button: ->
- @$removeBtn =$ "<a href='#' class='remove'>Remove</a>"
+ _add_clear_button: ->
+ @$removeBtn =$ "<button class='clear'>Clear</button>"
@$actions.append @$removeBtn
@$removeBtn.on 'click', (e) =>
- e.preventDefault()
@$inputTime.val('')
@$inputDate.val('')
@_update_date_label()
@_update_value()
+ # PUBLIC ====================================================================
- # PUBLIC ================================================
-
initialize: ->
@config.beforeInitialize?(this)
# http://felicegattuso.com/projects/datedropper/
@config.pluginConfig ?= {}
@@ -139,20 +124,14 @@
@$inputDate.dateDropper(config)
@config.onInitialize?(this)
-
updateValue: (@value) ->
@_normalized_value()
@$input.val(@value)
@_update_date_input()
@_update_date_label()
@_update_time_input()
-
chr.formInputs['datetime'] = InputDatetime
-
-
-
-