/Src/WS.EKA.Portal/Scripts/models/category.js
JavaScript | 154 lines | 123 code | 31 blank | 0 comment | 4 complexity | 276b68a1aa85f505d359885ec8d3f1d0 MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause
- window.Category = Backbone.Model.extend({
- defaults: {
- Name: '',
- Keywords: '',
- Description: ''
- }
- });
- window.ProductCategoryCollection = Backbone.Collection.extend({
- model: Category,
- urlRoot: '/api/productcatagory/',
- url: function () {
- if (this.level !== undefined)
- return this.urlRoot + this.level;
- else
- return this.urlRoot + this.nextID;
- }
- });
- window.FirstLevelCollection = ProductCategoryCollection.extend({
- level: 0
- });
- window.SecondLevelCollection = ProductCategoryCollection.extend({
- });
- window.ThirdLevelCollection = ProductCategoryCollection.extend({
- });
- window.CategoryView = Backbone.View.extend({
- renderNext: function (e) {
- var target = $(e.currentTarget);
- var clickModel = _.find(this.collection.toArray(), function (model) {
- return model.get('ID') == target.attr('nextid');
- });
- var level = clickModel.get('CategoryLevel');
- localStorage.setItem('categorytitle' + level, clickModel.get('Name'));
- localStorage.setItem('nextid_' + level, target.attr('nextid'));
- if (target.attr('islast') === 'false') {
- pageView.goTo(this.NextPage);
- } else {
- localStorage.setItem('productcategoryid', target.attr('nextid'));
- localStorage.setItem('orderType', 'SaleNumber');
- localStorage.setItem('isASC', true);
- localStorage.setItem('pageIndex', 1);
- localStorage.setItem('pageCount', 5);
- pageView.goTo('ProductList');
- }
- }
- });
- window.FirstLevelView = CategoryView.extend({
- el: "#jqt",
- NextPage: 'SecondCategory',
- initialize: function () {
- this.collection = new FirstLevelCollection();
- this.template = $('#FirstCatagoryTemplate').html();
- },
- events: {
- 'click .firstCategoryList li': 'renderNext'
- },
- render: function () {
- var that = this;
- var partial = { header: $('#HeaderTemplate').html(), footer: $('#FooterTemplate').html(), innerFooter: $('#InnerFooterTemplate').html() };
- var data = { title: "????", btnListR: [{ name: 'sort' }, { name: 'cart' }, { name: 'home'}] };
- this.$el.append(Mustache.render(this.template, data, partial));
- this.collection.fetch({
- success: function () {
- var data = { products: that.collection.toJSON() };
- var template = $('#CategoryListTemplate').html();
- $('#FirstCategory .firstCategoryList').html(Mustache.render(template, data, []));
- pageView.resizeScroll();
- }
- });
- return this;
- }
- });
- window.SecondLevelView = CategoryView.extend({
- el: "#jqt",
- NextPage: 'ThirdCategory',
- initialize: function () {
- this.collection = new SecondLevelCollection();
- this.template = $('#SecondCatagoryTemplate').html();
- },
- events: {
- 'click .secondCategoryList li': 'renderNext'
- },
- render: function () {
- var that = this;
- var partial = { header: $('#HeaderTemplate').html(), footer: $('#FooterTemplate').html(), innerFooter: $('#InnerFooterTemplate').html() };
- var data = { hasBack: true, title: "????", btnListR: [{ name: 'sort' }, { name: 'cart' }, { name: 'home'}] };
- this.$el.append(Mustache.render(this.template, data, partial));
- this.collection.nextID = localStorage.getItem('nextid_1');
- this.collection.fetch({ success: function () {
- var data = { products: that.collection.toJSON() };
- var template = $('#CategoryListTemplate').html();
- $('#SecondCategory .secondCategoryList').html(Mustache.render(template, data, []));
- pageView.resizeScroll();
- }
- });
- return this;
- }
- });
- window.ThirdLevelView = CategoryView.extend({
- el: '#jqt',
- initialize: function () {
- this.collection = new ThirdLevelCollection();
- this.template = $('#ThirdCatagoryTemplate').html();
- },
- events: {
- 'click .thirdCategoryList li': 'renderNext'
- },
- render: function () {
- var that = this;
- var partial = { header: $('#HeaderTemplate').html(), footer: $('#FooterTemplate').html(), innerFooter: $('#InnerFooterTemplate').html() };
- var data = { hasBack: true, title: localStorage.getItem('categorytitle1'), btnListR: [{ name: 'sort' }, { name: 'cart' }, { name: 'home'}] };
- this.$el.append(Mustache.render(this.template, data, partial));
- this.collection.nextID = localStorage.getItem('nextid_2');
- this.collection.fetch({
- success: function () {
- var data = { products: that.collection.toJSON() };
- var template = $('#CategoryListTemplate').html();
- $('#ThirdCategory .thirdCategoryList').html(Mustache.render(template, data, []));
- pageView.resizeScroll();
- }
- });
- return this;
- }
- });