Your IP : 3.138.156.155
(function(){"use strict";BX.namespace("BX.im.list");BX.im.list=function(t){t=t||{};this.const={DEFAULT_SECTION_CODE:"_default",POSITION_NEW:"new"};this.sections=[];this.sectionItems={};this.items={};this.itemCount=0;this._defaultSectionAdd();this.eventThrow=function(t,e){};this.drawFunction=function(t){};this.queue=t.queue===true?new BX.im.list.queue({list:this}):null;t.markup=t.markup||{};t.markup.list=this;t.markup.container=t.container;this.markup=new BX.im.list.markup(t.markup)};BX.im.list.supportNaturalSort=function(){try{"a".localeCompare("b","i")}catch(t){return t.name==="RangeError"}return false};BX.im.list.prototype.setItems=function(t,e){this.removeAllItems();if(e){this.setSections(e)}this.addItems(t,{incrementPosition:true,skipStub:true,skipRender:true});this.markup.drawItemsStub();if(this.queue){this.queue.worker()}return true};BX.im.list.prototype.findItem=function(t){if(!BX.type.isPlainObject(t))return false;var e=this.findItems(t);return e.length>0?e[0]:null};BX.im.list.prototype.findItems=function(t){if(!BX.type.isPlainObject(t))return false;var e=[];if(typeof t.id!="undefined"){if(this.items[t.id]){e.push(this.items[t.id])}}else if(typeof t.title!="undefined"){for(var i in this.items){if(!this.items.hasOwnProperty(i))continue;if(this.items[i].title.toUpperCase().indexOf(t.title.toUpperCase())==0){e.push(this.items[i])}}}else{for(var s in t){if(!t.hasOwnProperty(s))continue;var o=s.split(".")[0];for(var i in this.items){if(!this.items.hasOwnProperty(i))continue;if(this.items[i][o]&&this.items[i][o]["_"+s]&&this.items[i][o]["_"+s]==t[s]){e.push(this.items[i])}}break}}return e};BX.im.list.prototype.addItem=function(t){return this.addItems([t])};BX.im.list.prototype.addItems=function(t,e){e=e||{};if(!this.queue||e.skipQueue){var i=[];var s={};t.forEach(function(t){t=this._prepareAdd(t);if(!t||this.items[t.id]){return false}if(t._options){e=BX.util.objectClone(t._options);delete t._options}if(!s[t.sectionCode]){var o=this.sections.find(function(t){return t.id==this.sectionCode},t);if(o&&o.sort.enable){s[t.sectionCode]=o.sort}}if(s[t.sectionCode]&&s[t.sectionCode].enable){i.push(t.sectionCode)}this.items[t.id]=t;this.itemCount++;t._position=!e.incrementPosition?this.const.POSITION_NEW:this.sectionItems[t.sectionCode].length;this.sectionItems[t.sectionCode].push(t);return true}.bind(this));i.forEach(function(t){this._sortItems(t)},this)}else{t.forEach(function(t){t._options=BX.util.objectClone(e);this.queue.add(t)}.bind(this))}};BX.im.list.prototype.updateItem=function(t,e){return this.updateItems([{filter:t,element:e}])};BX.im.list.prototype.updateItems=function(t){var e=[];var i={};t.forEach(function(t){this.findItems(t.filter).forEach(function(s){if(BX.type.isPlainObject(t.element)){if(t.element.sectionCode&&t.element.sectionCode!=s.sectionCode){e.push(s.sectionCode);e.push(t.element.sectionCode)}else if(!i[s.sectionCode]){var o=this.sections.find(function(t){return t.id==this.sectionCode},s);if(o&&o.sort.enable){i[s.sectionCode]=o.sort}if(i[s.sectionCode]&&i[s.sectionCode].enable&&typeof t.element[i[s.sectionCode].field]!="undefined"){e.push(s.sectionCode)}}this.items[s.id]=BX.util.objectMerge(s,this._prepareItem(t.element))}},this)}.bind(this));e.forEach(function(t){this._sortItems(t)},this)};BX.im.list.prototype.removeItem=function(t){return this.removeItems([t])};BX.im.list.prototype.removeItems=function(t){var e=[];var i={};t.forEach(function(t){this.findItems(t).forEach(function(t){if(!i[t.sectionCode]){var s=this.sections.find(function(t){return t.id==this.sectionCode},t);if(s&&s.sort.enable){i[t.sectionCode]=s.sort}}if(i[t.sectionCode]&&i[t.sectionCode].enable){e.push(t.sectionCode)}this.markup.change(this.markup.const.TYPE_DELETE,{item:t,section:i[t.sectionCode],position:{current:-1,previous:t._position,diff:0}});this.sectionItems[t.sectionCode].splice(this.sectionItems[t.sectionCode].indexOf(t),1);delete this.items[t.id];this.itemCount--},this)}.bind(this));e.forEach(function(t){this._sortItems(t)},this)};BX.im.list.prototype.removeAllItems=function(){this.sectionItems={};this.items={};this.itemCount=0};BX.im.list.prototype.setSections=function(t){if(typeof t=="undefined"){return false}else if(typeof t=="boolean"&&t===false){this.sections.forEach(function(t,e){if(t.id!=this.const.DEFAULT_SECTION_CODE){this.sections.splice(e,1)}},this);if(this.sections.length==0){this._defaultSectionAdd()}return true}var e=[];t.forEach(function(t){if(!t.id)return false;var i=this.sections.find(function(t){return t.id==this.id},t);if(i){if(typeof t.title!="undefined"){i.title=t.title}if(t.backgroundColor&&t.backgroundColor.match(/^#([a-fA-F0-9]){3}(([a-fA-F0-9]){3})?\b$/)){}else if(typeof t.backgroundColor!="undefined"){i.backgroundColor="transparent"}if(typeof t.sortItemParams!="undefined"){this.setSectionSort(t.id,t.sortItemParams)}}else{this.sections.push({id:t.id,title:t.title.toString(),backgroundColor:t.backgroundColor&&t.backgroundColor.match(/^#([a-fA-F0-9]){3}(([a-fA-F0-9]){3})?\b$/)?t.backgroundColor:"transparent",sort:false,_nodes:{}});this.setSectionSort(t.id,t.sortItemParams)}e.push(t.id);return true},this);this.sections=this.sections.filter(function(t){return e.indexOf(t.id)>-1},e);if(this.sections.length==0){this._defaultSectionAdd()}this.markup.drawSections();return true};BX.im.list.prototype.setListener=function(t){if(typeof t!="function")return false;this.throwEventFunction=t;return true};BX.im.list.prototype.setSectionSort=function(t,e){return this.setSort(e,t)};BX.im.list.prototype.setSort=function(t,e){e=e||this.const.DEFAULT_SECTION_CODE;var i=this.sections.find(function(t){return t.id==this},e);if(!i){return false}if(typeof t=="boolean"&&t===false||!t){i.sort=this._defaultSortParams();return true}for(var s in t){if(t.hasOwnProperty(s)){i.sort={enable:true,field:s,order:t[s].toString().toLowerCase()=="desc"?"desc":"asc"};this._sortItems(e);return true}}return true};BX.im.list.prototype._defaultSectionAdd=function(){this.sections.push({id:this.const.DEFAULT_SECTION_CODE,title:"",backgroundColor:"transparent",sort:this._defaultSortParams(),_nodes:{}});return true};BX.im.list.prototype._defaultSortParams=function(){return{enable:false,field:"id",order:"asc"}};BX.im.list.prototype._sortItems=function(t){if(!this.sectionItems[t]||this.sectionItems[t].length<=0)return true;var e=this.sections.find(function(t){return t.id==this},t);if(!e||!e.sort.enable)return true;e._positionChanged=false;this.sectionItems[t].sort(function(t,i){var s;if(!t.sortValues[e.sort.field]||!t.sortValues[e.sort.field]){s=0}else if(BX.im.list.supportNaturalSort()){s=t.sortValues[e.sort.field].toString().localeCompare(i.sortValues[e.sort.field].toString(),undefined,{numeric:true,sensitivity:"base"});if(!this.sectionItemsPositionChanged&&s!=0){this.sectionItemsPositionChanged=true}s=e.sort.order=="asc"?s:s*-1}else if(t.sortValues[e.sort.field]>i.sortValues[e.sort.field]){s=e.sort.order=="asc"?1:-1}else if(t.sortValues[e.sort.field]<i.sortValues[e.sort.field]){s=e.sort.order=="asc"?-1:1}else{if(e.sort.field!="id"){if(t.sortValues.id>i.sortValues.id){s=e.sort.order=="asc"?1:-1}else if(t.sortValues.id<i.sortValues.id){s=e.sort.order=="asc"?-1:1}else{s=0}}else{s=0}}if(!this._positionChanged&&s!=0){this._positionChanged=true}return s}.bind(e));if(e._positionChanged){this._indexItems(t)}delete e._positionChanged;return true};BX.im.list.prototype._indexItems=function(t){if(!this.sectionItems[t]||this.sectionItems[t].length<=0)return true;var e=this.sections.find(function(t){return t.id==this},t);this.sectionItems[t].forEach(function(t,i){if(t._position!=i){var s=0;var o=this.markup.const.TYPE_UPDATE;if(t._position==this.const.POSITION_NEW){o=this.markup.const.TYPE_ADD}else{s=i-t._position}this.markup.change(o,{item:t,section:e,position:{current:i,previous:t._position,diff:s}});t._position=i}},this);return true};BX.im.list.prototype._prepareAdd=function(t){t=this._prepareItem(t,false);return t};BX.im.list.prototype._prepareItem=function(t,e){e=e!==false;if(t.title){t.title=t.title.toString()}if(t.subtitle){t.subtitle=t.subtitle.toString()}if(!t.sectionCode&&!e){t.sectionCode=this.const.DEFAULT_SECTION_CODE}if(t.sectionCode){if(!this.sectionItems[t.sectionCode]){this.sectionItems[t.sectionCode]=[]}}if(t.backgroundColor&&t.backgroundColor.match(/^#([a-fA-F0-9]){3}(([a-fA-F0-9]){3})?\b$/)){}else if(t.backgroundColor||!e){t.backgroundColor="#556574"}if(!t.imageUrl&&!e){t.imageUrl=""}if(t.params&&BX.type.isPlainObject(t.params)){for(var i in t.params){if(t.params.hasOwnProperty(i)){t.params["_params."+i]=t.params[i]}}}else if(t.params&&e){delete t.params}else if(!e){t.params={}}if(t.sortValues&&BX.type.isPlainObject(t.sortValues)){if(!t.sortValues.id){t.sortValues.id=t.id}}else if(t.sortValues&&e){delete t.sortValues}else if(!e){t.sortValues={id:t.id}}if(t.styles&&BX.type.isPlainObject(t.styles)){for(var i in t.styles){if(!t.styles.hasOwnProperty(i))continue;if(!BX.type.isPlainObject(t.styles[i])){delete t.styles[i]}}}else if(t.styles&&e){delete t.styles}else if(!e){t.styles={}}return t}})();