PageRenderTime 60ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/Src/WS.EKA.Portal/Scripts/models/order/coupon.js

http://mobileshop.codeplex.com
JavaScript | 96 lines | 87 code | 9 blank | 0 comment | 15 complexity | 9f3a47a90341da0046fa2a62cbbc63d4 MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause
  1. window.Activity = Backbone.Model.extend({});
  2. window.ActivityList = Backbone.Collection.extend({
  3. model: Activity,
  4. urlRoot: 'api/promotionbyprice/',
  5. url: function () {
  6. return this.urlRoot + localStorage.getItem('allPrice');
  7. }
  8. });
  9. window.CouponView = Backbone.View.extend({
  10. el: '#jqt',
  11. initialize: function () {
  12. this.template = $('#CouponTemplate').html();
  13. this.activities = new ActivityList();
  14. },
  15. events: {
  16. 'click .promotionList input[type="radio"]': 'toggleCouponInput',
  17. 'click .promotionList #CouponSubmit': 'saveCoupon',
  18. 'click .promotionList input[type="checkbox"]': 'toggleInputField'
  19. },
  20. render: function () {
  21. var partial = { header: $('#HeaderTemplate').html(), footer: $('#FooterTemplate').html(),
  22. innerFooter: $('#InnerFooterTemplate').html()
  23. };
  24. var data = { hasBack: true, title: "??", btnListR: [{ name: 'home'}] };
  25. this.$el.append(Mustache.render(this.template, data, partial));
  26. this.fetchActivities();
  27. return this;
  28. },
  29. fetchActivities: function () {
  30. var that = this;
  31. this.activities.fetch({
  32. success: function () {
  33. if (that.activities.length == 0) {
  34. var template = $('#EmptyPromotionListTemplate').html();
  35. $('.promotionList').html(Mustache.render(template, [], []));
  36. return;
  37. } else {
  38. var template = $('#PromotionListTemplate').html();
  39. $('.promotionList').html(Mustache.render(template, { coupons: that.activities.toJSON() }, []));
  40. $('.couponInput').hide();
  41. }
  42. pageView.resizeScroll();
  43. }
  44. });
  45. },
  46. toggleCouponInput: function (e) {
  47. var target = $(e.currentTarget),
  48. canUse = target.closest('ul').attr('canuse');
  49. if (canUse == '0') {
  50. $('.couponInput').hide();
  51. } else {
  52. $('.couponInput').show(); $('.couponInput input').val('');
  53. pageView.myScroll.scrollToElement('.couponInput', 100);
  54. }
  55. pageView.resizeScroll();
  56. },
  57. toggleInputField: function (e) {
  58. var checkbox = $('.promotionList input[type="checkbox"]')[0];
  59. if (checkbox.checked) {
  60. $('.couponInput p').show();
  61. } else {
  62. $('.couponInput p').hide();
  63. }
  64. pageView.resizeScroll();
  65. },
  66. saveCoupon: function (e) {
  67. var ticketcode = $('.promotionList #couponID').val().trim(),
  68. couponname = $('.promotionList input[type="radio"]:checked').next('label').find('.couponname').text(),
  69. activityGuid = $('.promotionList input[type="radio"]:checked').attr('id'),
  70. checkbox = $('.promotionList input[type="checkbox"]')[0],
  71. hascoupon = !($('.couponInput').css('display') == 'none');
  72. if (!hascoupon || !checkbox.checked) {
  73. localStorage.setItem('couponitem', JSON.stringify({ activityGuid: activityGuid, couponname: couponname}));
  74. pageView.goBack();
  75. } else {
  76. $.getJSON('api/FavourTicketVerify/', { ticketCode: ticketcode }, function (res) {
  77. if (res == true) {
  78. localStorage.setItem('couponitem', JSON.stringify({ activityGuid: activityGuid, ticketcode: ticketcode, couponname: couponname }));
  79. pageView.goBack();
  80. } else {
  81. alert('?????????????');
  82. $('.couponInput input').val('');
  83. }
  84. });
  85. }
  86. }
  87. });