PageRenderTime 36ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/Src/WS.EKA.Portal/Scripts/models/category.js

http://mobileshop.codeplex.com
JavaScript | 154 lines | 123 code | 31 blank | 0 comment | 4 complexity | 276b68a1aa85f505d359885ec8d3f1d0 MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause
  1. window.Category = Backbone.Model.extend({
  2. defaults: {
  3. Name: '',
  4. Keywords: '',
  5. Description: ''
  6. }
  7. });
  8. window.ProductCategoryCollection = Backbone.Collection.extend({
  9. model: Category,
  10. urlRoot: '/api/productcatagory/',
  11. url: function () {
  12. if (this.level !== undefined)
  13. return this.urlRoot + this.level;
  14. else
  15. return this.urlRoot + this.nextID;
  16. }
  17. });
  18. window.FirstLevelCollection = ProductCategoryCollection.extend({
  19. level: 0
  20. });
  21. window.SecondLevelCollection = ProductCategoryCollection.extend({
  22. });
  23. window.ThirdLevelCollection = ProductCategoryCollection.extend({
  24. });
  25. window.CategoryView = Backbone.View.extend({
  26. renderNext: function (e) {
  27. var target = $(e.currentTarget);
  28. var clickModel = _.find(this.collection.toArray(), function (model) {
  29. return model.get('ID') == target.attr('nextid');
  30. });
  31. var level = clickModel.get('CategoryLevel');
  32. localStorage.setItem('categorytitle' + level, clickModel.get('Name'));
  33. localStorage.setItem('nextid_' + level, target.attr('nextid'));
  34. if (target.attr('islast') === 'false') {
  35. pageView.goTo(this.NextPage);
  36. } else {
  37. localStorage.setItem('productcategoryid', target.attr('nextid'));
  38. localStorage.setItem('orderType', 'SaleNumber');
  39. localStorage.setItem('isASC', true);
  40. localStorage.setItem('pageIndex', 1);
  41. localStorage.setItem('pageCount', 5);
  42. pageView.goTo('ProductList');
  43. }
  44. }
  45. });
  46. window.FirstLevelView = CategoryView.extend({
  47. el: "#jqt",
  48. NextPage: 'SecondCategory',
  49. initialize: function () {
  50. this.collection = new FirstLevelCollection();
  51. this.template = $('#FirstCatagoryTemplate').html();
  52. },
  53. events: {
  54. 'click .firstCategoryList li': 'renderNext'
  55. },
  56. render: function () {
  57. var that = this;
  58. var partial = { header: $('#HeaderTemplate').html(), footer: $('#FooterTemplate').html(), innerFooter: $('#InnerFooterTemplate').html() };
  59. var data = { title: "????", btnListR: [{ name: 'sort' }, { name: 'cart' }, { name: 'home'}] };
  60. this.$el.append(Mustache.render(this.template, data, partial));
  61. this.collection.fetch({
  62. success: function () {
  63. var data = { products: that.collection.toJSON() };
  64. var template = $('#CategoryListTemplate').html();
  65. $('#FirstCategory .firstCategoryList').html(Mustache.render(template, data, []));
  66. pageView.resizeScroll();
  67. }
  68. });
  69. return this;
  70. }
  71. });
  72. window.SecondLevelView = CategoryView.extend({
  73. el: "#jqt",
  74. NextPage: 'ThirdCategory',
  75. initialize: function () {
  76. this.collection = new SecondLevelCollection();
  77. this.template = $('#SecondCatagoryTemplate').html();
  78. },
  79. events: {
  80. 'click .secondCategoryList li': 'renderNext'
  81. },
  82. render: function () {
  83. var that = this;
  84. var partial = { header: $('#HeaderTemplate').html(), footer: $('#FooterTemplate').html(), innerFooter: $('#InnerFooterTemplate').html() };
  85. var data = { hasBack: true, title: "????", btnListR: [{ name: 'sort' }, { name: 'cart' }, { name: 'home'}] };
  86. this.$el.append(Mustache.render(this.template, data, partial));
  87. this.collection.nextID = localStorage.getItem('nextid_1');
  88. this.collection.fetch({ success: function () {
  89. var data = { products: that.collection.toJSON() };
  90. var template = $('#CategoryListTemplate').html();
  91. $('#SecondCategory .secondCategoryList').html(Mustache.render(template, data, []));
  92. pageView.resizeScroll();
  93. }
  94. });
  95. return this;
  96. }
  97. });
  98. window.ThirdLevelView = CategoryView.extend({
  99. el: '#jqt',
  100. initialize: function () {
  101. this.collection = new ThirdLevelCollection();
  102. this.template = $('#ThirdCatagoryTemplate').html();
  103. },
  104. events: {
  105. 'click .thirdCategoryList li': 'renderNext'
  106. },
  107. render: function () {
  108. var that = this;
  109. var partial = { header: $('#HeaderTemplate').html(), footer: $('#FooterTemplate').html(), innerFooter: $('#InnerFooterTemplate').html() };
  110. var data = { hasBack: true, title: localStorage.getItem('categorytitle1'), btnListR: [{ name: 'sort' }, { name: 'cart' }, { name: 'home'}] };
  111. this.$el.append(Mustache.render(this.template, data, partial));
  112. this.collection.nextID = localStorage.getItem('nextid_2');
  113. this.collection.fetch({
  114. success: function () {
  115. var data = { products: that.collection.toJSON() };
  116. var template = $('#CategoryListTemplate').html();
  117. $('#ThirdCategory .thirdCategoryList').html(Mustache.render(template, data, []));
  118. pageView.resizeScroll();
  119. }
  120. });
  121. return this;
  122. }
  123. });