Created
August 31, 2016 19:51
-
-
Save oleglukashev/5b971ee1330c0014a4801aef7eebe079 to your computer and use it in GitHub Desktop.
backbone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Cooking.Views.CashPositions ||= {} | |
class Cooking.Views.CashPositions.CashPositionView extends Backbone.View | |
template: JST["backbone/templates/cash_positions/cash_position"] | |
initialize: () -> | |
@model.on('change:status', (cash_position) -> | |
Backbone.trigger 'CashPositionsIndex:cash_position:change', cash_position | |
, @) | |
@model.on('remove', (cash_position) -> | |
Backbone.trigger 'CashPositionsIndex:cash_position:remove', cash_position | |
, @) | |
@model.on('add', (cash_position) -> | |
Backbone.trigger 'CashPositionsIndex:cash_position:add', cash_position | |
, @) | |
@cash_mods_views = {} | |
events: | |
"click .cash-position__button .cash-position-processing": "processing" | |
"click .cash-position__button .cash-position-finishing": "finishing" | |
"click .cash-position__button .cash-position-giving": "giving" | |
processing: () -> | |
that = @ | |
$.ajax | |
url: '/cash_positions/' + @model.get('id') + '/processing' | |
type: 'patch' | |
dateType: 'json' | |
data: | |
cash_shift_date: @model.get('cash_shift_date') | |
success: () -> | |
that.model.set({ | |
status: 'process' | |
update_at: moment().format() | |
}) | |
@addSendingStatus() | |
finishing: () -> | |
that = @ | |
$.ajax | |
url: '/cash_positions/' + @model.get('id') + '/finishing' | |
type: 'patch' | |
dateType: 'json' | |
data: | |
cash_shift_date: @model.get('cash_shift_date') | |
success: () -> | |
that.model.set({ | |
status: 'finished' | |
update_at: moment().format() | |
}) | |
@addSendingStatus() | |
giving: () -> | |
that = @ | |
$.ajax | |
url: '/cash_positions/' + @model.get('id') + '/giving' | |
type: 'patch' | |
dateType: 'json' | |
data: | |
cash_shift_date: @model.get('cash_shift_date') | |
success: () -> | |
that.model.set({ | |
status: 'given' | |
update_at: moment().format() | |
}) | |
@addSendingStatus() | |
removeCashMods: () => | |
_(@cash_mods_views).each (value, key) -> value.remove() | |
buildCashMods: () => | |
that = @ | |
unless $(@el).find('.cash-position__cash-mods').length | |
$(@el).find('.cash-position__main-info').append('<div class="cash-position__cash-mods"></div>') | |
@model.get('cash_mods').each((cash_mod) -> | |
that.cash_mods_views[cash_mod.get('id')] = new Cooking.Views.CashMods.CashModView({model : cash_mod}) | |
$(that.el).find('.cash-position__cash-mods').append that.cash_mods_views[cash_mod.get('id')].render().el | |
) | |
addSendingStatus: -> | |
$cash_position = $('.cash-position[data-cash-position-id="' + @model.get('id') + '"]') | |
unless $cash_position.hasClass('cash-position--sending') | |
$cash_position | |
.addClass('cash-position--sending') | |
.removeClass('cash-position--not-sended') | |
setTimeout -> | |
if $cash_position.length | |
$cash_position | |
.removeClass('cash-position--sending') | |
.addClass('cash-position--not-sended') | |
, 10000 | |
render: -> | |
@setElement(@template(@model.toJSON())) | |
@removeCashMods() | |
@buildCashMods() | |
return this |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment