/Src/WS.EKA.Portal/Scripts/models/myOrder.js
http://mobileshop.codeplex.com · JavaScript · 101 lines · 93 code · 8 blank · 0 comment · 14 complexity · 07e586754e2b0e990936aa1ceff95922 MD5 · raw file
- window.Order = Backbone.Model.extend({
- urlRoot: 'api/order/',
- url: function () {
- return this.urlRoot + localStorage.getItem('orderCode');
- },
- parse: function (model) {
- model.PaymentName = (model.Payment) && (model.Payment.NAME);
- model.DispatchModeName = (model.DispatchMode) && (model.DispatchMode.NAME);
- model.HasInvoice = model.InvoiceType != '';
- if (model.OderStatus == 5) {
- model.NeedPay = false;
- model.Status = "??";
- } else {
- model.NeedPay = false;
- if (model.PaymentStatus == 2) {
- switch (model.ShipmentStatus) {
- case 0:
- model.Status = '???'; break;
- case 1:
- model.Status = '???'; break;
- case 2:
- model.Status = '???'; break;
- case 3:
- model.Status = '???'; break;
- case 4:
- model.Status = '???'; break;
- default:
- model.Status = '???'; break;
- }
- } else {
- switch (model.PaymentStatus) {
- case 0:
- model.Status = '???'; model.NeedPay = true; break;
- case 1:
- model.Status = '???'; break;
- case 3:
- model.Status = '??'; break;
- default:
- model.Status = '???'; break;
- }
- }
- }
- return model;
- }
- });
- window.OrderList = Backbone.Collection.extend({
- model: Order,
- urlRoot: 'api/order/member/',
- url: function () {
- return this.urlRoot + pageView.getCookieValue('uid');
- }
- });
- window.MyOrderListView = Backbone.View.extend({
- el: '#jqt',
- initialize: function () {
- this.template = $('#MyOrderTemplate').html();
- this.collection = new OrderList();
- },
- events: {
- 'click #MyOrder ul.orderItem': 'goToOrderDetail'
- },
- render: function () {
- var partial = { header: $('#HeaderTemplate').html(), footer: $('#FooterTemplate').html(),
- innerFooter: $('#InnerFooterTemplate').html()
- };
- var data = { hasBack: true, title: '??', btnListR: [{ name: 'avatar' }, { name: 'home'}] };
- this.$el.append(Mustache.render(this.template, data, partial));
- this.fetchOrders();
- return this;
- },
- fetchOrders: function () {
- var that = this;
- this.collection.fetch({
- success: function () {
- var template;
- if (that.collection.length == 0) {
- template = $('#EmptyOrderTemplate').html();
- $('.myOrder').html(Mustache.render(template, [], []));
- } else {
- template = $('#OrderListTemplate').html();
- var data = { orders: that.collection.toJSON() };
- $('.myOrder').html(Mustache.render(template, data, []));
- }
- pageView.resizeScroll();
- }
- });
- },
- goToOrderDetail: function (e) {
- var target = $(e.currentTarget);
- localStorage.setItem('orderCode', target.attr('orderCode'));
- pageView.goTo('OrderDetail');
- }
- });