Created
May 5, 2014 15:14
-
-
Save chukcha-wtf/f6889ff125d25cb4e745 to your computer and use it in GitHub Desktop.
Ember.js preview
This file contains 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
App.ApplicationAdapter = DS.RESTAdapter.extend({ | |
find: function(store, type, token) { | |
var service = new AuthServiceClient(new Thrift.Protocol(new Thrift.Transport(App.Config.url.auth))); | |
return new Ember.RSVP.Promise(function(resolve, reject) { | |
service.error = function(status) { | |
Ember.run(function(){ | |
reject(status.errorDescription); | |
}); | |
} | |
var json = service.refreshAuthSession(token); | |
Ember.run(null, resolve, json); | |
}); | |
}, | |
findQuery: function(store, type, query) { | |
var model_name = type.typeKey.replace("Contract", "") | |
if (query.fromDate) { | |
var service = new ContractOperationHistoryServiceClient(new Thrift.Protocol(new Thrift.Transport(App.Config.url.operationHistoryService))); | |
} else { | |
var service = new ContractsServiceClient(new Thrift.Protocol(new Thrift.Transport(App.Config.url.contractsService))); | |
} | |
var token = query.token | |
return new Ember.RSVP.Promise(function(resolve, reject) { | |
service.error = function(status) { | |
Ember.run(function(){ | |
reject(status.errorDescription); | |
}); | |
} | |
var data = null; | |
switch (model_name) { | |
case 'card': | |
data = service.findAllCardContracts(token); | |
break; | |
case 'account': | |
data = service.findAllAccountContracts(token); | |
break; | |
case 'credit': | |
data = service.findAllCreditContracts(token); | |
break; | |
case 'deposit': | |
data = service.findAllDepositContracts(token); | |
break; | |
case 'depositItem': | |
data = service.fetchDepositOperationHistoryItemsWithFromToDate(token, query.id, query.filter, query.fromDate, query.toDate) | |
break; | |
case 'accountItem': | |
data = service.fetchAccountOperationHistoryItemsWithFromToDate(token, query.id, query.filter, query.fromDate, query.toDate) | |
break; | |
case 'creditItem': | |
data = service.fetchCreditOperationHistoryItemsWithFromToDate(token, query.id, query.filter, query.fromDate, query.toDate) | |
break; | |
case 'cardItem': | |
data = service.fetchCardContractOperationHistoryItemsWithFromToDate(token, query.id, query.filter, query.fromDate, query.toDate, query.attr) | |
break; | |
} | |
Ember.run(null, resolve, data); | |
}); | |
} | |
}); |
This file contains 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
App.ContractsController = Ember.ArrayController.extend({ | |
token: this.get('session.access_token'), | |
fetchCards: function() { | |
var _this = this; | |
_this.store.find('card_contract', {token: _this.get('token')}).then(function(contracts){ | |
_this.set('card_contracts', contracts) | |
}); | |
}, | |
fetchDeposits: function() { | |
var _this = this; | |
_this.store.find('deposit_contract', {token: _this.get('token')}).then(function(contracts){ | |
_this.set('deposit_contracts', contracts) | |
}); | |
}, | |
fetchAccounts: function() { | |
var _this = this; | |
_this.store.find('account_contract', {token: _this.get('token')}).then(function(contracts){ | |
_this.set('account_contracts', contracts) | |
}); | |
}, | |
fetchCredits: function() { | |
var _this = this; | |
_this.store.find('credit_contract', {token: _this.get('token')}).then(function(contracts){ | |
_this.set('credit_contracts', contracts) | |
}); | |
} | |
}); |
This file contains 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
App.MyCardsController = Ember.ArrayController.extend({ | |
selectedCard: null, | |
actions: { | |
notImplemented: function() { | |
this.showNotice('Данная функция будет доступна в следующем релизе.') | |
}, | |
goToContract: function(card) { | |
this.set('selectedCard', card); | |
this.transitionToRoute('card', card.get('contract')); | |
} | |
}, | |
fetchCards: function() { | |
var _this = this; | |
_this.store.find('card_contract', {token: _this.get('session.access_token')}).then(function(contracts){ | |
var active_cards = [], | |
inactive_cards = []; | |
if (contracts.toArray().length) { | |
contracts.toArray().forEach(function(contract){ | |
if (contract.get('cards') && contract.get('cards').toArray().length) { | |
contract.get('cards').toArray().forEach(function(card){ | |
if (card.get('status')) { | |
card.get('booleanStatus') ? active_cards.push(card) : inactive_cards.push(card); | |
} else { | |
inactive_cards.push(card); | |
} | |
}); | |
} | |
}); | |
} | |
_this.set('cards', active_cards.concat(inactive_cards)); | |
}, function(error){ | |
_this.showError(error.errorMessageKey); | |
}); | |
}, | |
clearData: function() { | |
} | |
}) |
This file contains 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
App.MyCardsView = Ember.View.extend({ | |
didInsertElement: function() { | |
$('a.banking').addClass('active'); | |
this.$().on('click', ".collapse", function() { | |
$(this).toggleClass("opened"); | |
$(this).text() === "Дополнительно" ? $(this).text("Свернуть") : $(this).text("Дополнительно") | |
$(this).parents(".item").find(".collapse-inner").slideToggle(400); | |
return false; | |
}); | |
}, | |
willremoveElement: function() { | |
$('a.banking').removeClass('active'); | |
} | |
}); | |
App.CardInnerView = Ember.View.extend({ | |
didInsertElement: function() { | |
var _this = this; | |
_this.$('.cash-range').slider({ | |
value:0, | |
min: 0, | |
max: 25000, | |
step: 50, | |
create: function() { | |
var handle = $('.cash-range .ui-slider-handle'); | |
var bubble = $('<div class="valuebox"><span class="v"></span> грн</div>'); | |
handle.append(bubble); | |
}, | |
slide: function( event, ui ) { | |
var formattedValue = ui.value.toFixed(2); | |
_this.$( ".cash-num" ).val(formattedValue); | |
_this.$('.cash-range .valuebox').fadeIn().find(".v").text(formattedValue); | |
} | |
}); | |
_this.$(".cash-num").val($(".cash-range").slider("value")); | |
_this.$('.payments-range').slider({ | |
value:0, | |
min: 0, | |
max: 25000, | |
step: 50, | |
create: function() { | |
var handle = $('.payments-range .ui-slider-handle'); | |
var bubble = $('<div class="valuebox"><span class="v"></span> грн</div>'); | |
handle.append(bubble); | |
}, | |
slide: function( event, ui ) { | |
var formattedValue = ui.value.toFixed(2); | |
_this.$('.payment-num').val(formattedValue); | |
_this.$('.payments-range .valuebox').fadeIn().find(".v").text(formattedValue); | |
} | |
}); | |
_this.$(".payment-num").val($(".payments-range").slider("value")); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment