Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Portal.Views.CustomerDevices ||= {}
- class Portal.Views.CustomerDevices.IndexView extends Portal.View
- template: "customer_devices/index"
- creditsTemplate: "customer_devices/_credits"
- devicesTemplate: "customer_devices/_devices"
- events:
- 'click a#register-submit': 'create',
- 'click a#edit-submit': 'edit',
- 'click .loadMe': 'presentInForm'
- initialize: () ->
- super()
- render: ->
- _credits = JST[@creditsTemplate]({credits: @currentUser.credits})
- _devices = JST[@devicesTemplate]({customerDevices: @currentUser.customerDevices})
- rendered = JST[@template]( {credits: _credits, devices: _devices})
- out = $(this.el).html(rendered)
- $container = $('#device-manager')
- $container.empty()
- $container.append(out)
- errorOnCreate: (model, resp) ->
- errorList = JSON.parse resp.responseText
- if errorList.errors
- if errorList.errors.unique_device_number
- $('#device-number-cg').addClass('error')
- original = $('#device-number-cg .help-block').text()
- $('#device-number-cg .help-block').text("It #{errorList.errors.unique_device_number[0]}. #{original}");
- if errorList.errors.name
- $('#device-name-cg').addClass('error')
- original = $('#device-number-cg .help-block').text()
- $('#device-number-cg .help-block').text("It #{errorList.errors.unique_device_number[0]}. #{original}");
- successOnCreate: (model, resp) ->
- console.log "success has been called!"
- @currentUser.customerDevices.add(model)
- $('#register').modal('hide')
- @render()
- create: ->
- attributes = @getFormAttributes(this.$('#register-form'))
- attributes.customer_id = @currentUser.attributes.id
- new Portal.Models.CustomerDevice().save attributes,
- success:
- (model, resp) => @successOnCreate(model, resp)
- error:
- (model, resp) => @errorOnCreate(model, resp)
- edit: ->
- console.log "transfer ..."
- console.log event
- attributes = @getFormAttributes(this.$('#transfer-form'))
- attributes.customer_id = @currentUser.attributes.id
- new Portal.Models.CustomerDevice().save attributes,
- success:
- (model, resp) => @successOnCreate(model, resp)
- error:
- (model, resp) => @errorOnCreate(model, resp)
- delete: (event) ->
- console.log event
- console.log "delete ..."
- presentInForm: (ev)->
- customer_device_id = ev.target.getAttribute('data-id')
- customer_device = @currentUser.customerDevices.get customer_device_id
- form = $('#register-form')
- $('#device-name-input').val('test!!!')
Add Comment
Please, Sign In to add comment