');
this.model.fetch({
data: query
});
},
/** This function is for portfolio to listen to the global event bus in order to re-fetch
*
* expecting attribute `data-product_type_id` from the event's currentTarget (aka the clicked item)
*
*/
prodTypeResponse: function(e){
var product_type_id = e.currentTarget.getAttribute("data-product_type_id");
//Reset data offset.
//Using HTML DOM attribute to store data is such a big brain move.
this.$el.attr({
'data-offset': 0,
//I guess two wrong does make one right...
'data-product_type_id': product_type_id, //data-product_type_id is predefined by edit modal, but can be changed on the fly and used to capture clicked product_type_id here
});
this.fetchModel();
},
initialize: function(options){
//workflow for product Type collapsible list
if (this.$el.hasClass("product_type")){
return this.initProductType(options);
//product Type collapsible list workflow cutoff here
}
var that = this;
this.options = options;
this._prodTypeResponse = _.bind(this.prodTypeResponse, this);
this.listenTo(event_bus, 'productType:click', this._prodTypeResponse); //listen to the global event_bus (emitted by prod type list). Should perform list refetch here.
this.fetchModel(); //this function build query from this.$el attributes, then fetch model
this.languagesList = $.parseJSON('[{"id":"1","name":"\u7e41\u9ad4\u4e2d\u6587","lang_key":"zh","enable":"1","created_at":"1534908864","updated_at":"1534908864"},{"id":"2","name":"\u7b80\u4f53\u4e2d\u6587","lang_key":"cn","enable":"1","created_at":"1534908864","updated_at":"1534908864"}]');
// this.render();
return this;
},
/**Separate init function workflow for productTypeList
*
*/
initProductType: function(options){
var that = this;
this.options = options;
this._renderProductType = _.bind(this.renderProductType, this);
//model for product_type list fetching
this.collection = new ProductTypeTreeList();
this.listenTo(this.collection, 'productType:init', this._renderProductType); //listen to custom event 'productType:init' to circumvent bombardment of 'add' events when fetching collection
var is_brand_flag = this.$el.attr('data-is_brand')=='1';
var limit = this.$el.attr('data-limit');
this.collection.fetch({
data: {
website_id: '94',
enable: '1',
is_brand: is_brand_flag?'1':{ne:'1'},
sort: "asc",
field: "ranking",
// limit: limit=='0'?null:limit,
},
success: function(collection){
//on success fetch, emit the custom event
collection.trigger("productType:init");
}
})
return this;
},
render: function(){
if (this.$el.hasClass("product_type")){ //product Type collapsible list workflow start
return this.renderProductType();
//product Type collapsible list workflow cutoff here
}
var that = this;
if (typeof this.model.get('data') == 'undefined' && this.model.get('data') == null && !_.isArray(this.model.get('data'))) {
// this.$container.append('