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

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

http://mobileshop.codeplex.com
JavaScript | 172 lines | 143 code | 27 blank | 2 comment | 12 complexity | 5a8fa39929136c26e08a82796badb2e6 MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause
  1. /// <reference path="../jquery.autocomplete.min.js" />
  2. /// <reference path="../jquery-1.7.js" />
  3. window.SearchList = Backbone.Collection.extend({
  4. model: Product,
  5. urlRoot: 'api/product/search/',
  6. url: function () {
  7. return this.urlRoot + localStorage.getItem('productcategoryid');
  8. }
  9. });
  10. window.SearchListView = Backbone.View.extend({
  11. el: "#jqt",
  12. initialize: function () {
  13. this.collection = new SearchList();
  14. this.template = $('#SearchListTemplate').html();
  15. },
  16. events: {
  17. 'click #SearchList .orderType ul li': 'changeOrderType',
  18. 'click #SearchList .searchSampleList li': 'renderDetail'
  19. },
  20. render: function () {
  21. var that = this;
  22. var partial = { header: $('#HeaderTemplate').html(), footer: $('#FooterTemplate').html(),
  23. innerFooter: $('#InnerFooterTemplate').html(), orderCheck: $('#ThreeCheckTemplate').html()
  24. };
  25. var data = { hasBack: true, title: "??", btnListR: [{ name: 'sort' }, { name: 'cart' }, { name: 'home'}] };
  26. this.$el.append(Mustache.render(this.template, data, partial));
  27. $('#SearchList #keyword').val(localStorage.getItem('keyword'));
  28. new Plugins.SearchPlugin('#SearchList .searchContainer', {
  29. id: 'keyword_searchlist'
  30. });
  31. this.setOrderCheck();
  32. this.searchProductList();
  33. return this;
  34. },
  35. searchProductList: function () {
  36. var that = this;
  37. this.collection.fetch({
  38. data: {
  39. sorts: localStorage.getItem('orderType'),
  40. isASC: localStorage.getItem('isASC'),
  41. pageIndex: localStorage.getItem('searchPageIndex'),
  42. pageCount: localStorage.getItem('pageCount'),
  43. name: localStorage.getItem('keyword')
  44. },
  45. success: function () {
  46. var template = $('#InnerListTemplate').html(),
  47. allCount = that.collection.models[0].get('Count');
  48. if (allCount == 0) {
  49. $('#SearchList .searchSampleList').html();
  50. $('#SearchList .filter #key').text(localStorage.getItem('keyword'));
  51. $('#SearchList .filter em').text(allCount);
  52. $('.footer').hide();
  53. $('.orderType').hide();
  54. return;
  55. }
  56. var data = { products: that.collection.models[0].get('Data') };
  57. $('#SearchList .searchSampleList').html(Mustache.render(template, data, []));
  58. $('#SearchList .filter #key').text(localStorage.getItem('keyword'));
  59. $('#SearchList .filter em').text(allCount);
  60. new Plugins.PagingPlugin('.foot-paging', {
  61. allCount: allCount,
  62. pageIndexKey: 'searchPageIndex',
  63. prevCall: function (e) { that.searchPrev(e); },
  64. nextCall: function (e) { that.searchNext(e) },
  65. numberClickCall: function (e) { that.searchSpecific(e) }
  66. });
  67. pageView.resizeScroll();
  68. }
  69. });
  70. },
  71. fetchPrev: function (e) {
  72. if ($(e.currentTarget).hasClass('disable')) return;
  73. var pageIndex = localStorage.getItem('searchPageIndex');
  74. localStorage.setItem('searchPageIndex', +pageIndex - 1);
  75. this.searchProductList();
  76. },
  77. fetchNext: function (e) {
  78. if ($(e.currentTarget).hasClass('disable')) return;
  79. var pageIndex = localStorage.getItem('searchPageIndex');
  80. localStorage.setItem('searchPageIndex', +pageIndex + 1);
  81. this.searchProductList();
  82. },
  83. fetchSpecific: function (e) {
  84. var target = $(e.currentTarget);
  85. if (target.hasClass('gray')) return;
  86. var index = +target.attr('index');
  87. localStorage.setItem('searchPageIndex', index);
  88. this.searchProductList();
  89. },
  90. renderDetail: function (e) {
  91. var target = $(e.currentTarget);
  92. var price = target.find('.pro-price').text(),
  93. productid = target.attr('productid');
  94. localStorage.setItem('productDetail', JSON.stringify({ productid: productid, price: price }));
  95. localStorage.setItem('productid', productid);
  96. localStorage.setItem('detailType', 'tab_intro');
  97. localStorage.setItem('commentPageIndex', 1);
  98. localStorage.setItem('ordercommentPageIndex', 1);
  99. pageView.goTo('ProductDetail');
  100. },
  101. setOrderCheck: function () {
  102. var orderType = localStorage.getItem('orderType'),
  103. isASC = localStorage.getItem('isASC'),
  104. priceClass = isASC == "true" ? 'up' : 'down',
  105. activeClass = 'selected',
  106. currentTarget = $('.orderType ').find('li[ordertype="' + orderType + '"]');
  107. currentTarget.addClass(activeClass).siblings().removeClass(activeClass);
  108. if (currentTarget.hasClass('price')) {
  109. currentTarget.find('a').removeClass('up down').addClass(priceClass);
  110. }
  111. },
  112. changeOrderType: function (e) {
  113. var target = $(e.currentTarget),
  114. activeClass = 'selected';
  115. if (target.hasClass(activeClass)) {
  116. this.changeAsc(e);
  117. return;
  118. }
  119. target.addClass(activeClass).siblings().removeClass(activeClass);
  120. if (!target.hasClass('price')) {
  121. $('.price').find('a').removeClass('down').addClass('up');
  122. }
  123. localStorage.setItem('orderType', target.attr('orderType'));
  124. localStorage.setItem('isASC', true);
  125. this.searchProductList();
  126. },
  127. changeAsc: function (e) {
  128. var target = $(e.currentTarget),
  129. activeClass = 'selected';
  130. if (target.hasClass('price')) {
  131. this.changePriceImg(target);
  132. }
  133. var orderAsc = localStorage.getItem('isASC');
  134. localStorage.setItem('isASC', orderAsc == "true" ? false : true);
  135. this.searchProductList();
  136. },
  137. changePriceImg: function (target) {
  138. var icon = $(target).find('a'),
  139. asc = icon.hasClass('up');
  140. if (asc) {
  141. icon.removeClass('up').addClass('down');
  142. } else
  143. icon.removeClass('down').addClass('up');
  144. }
  145. });