(function(){var e=Backbone.Model.extend({defaults:{name:function(){return funcObj.langCon.getString("General_NotSpecified")},sourceType:""},initialize:function(){}}),t=Backbone.Collection.extend({model:e}),n=Backbone.View.extend({tagName:"li",local_source_template:_.template(local_source_xml_template),template:_.template(local_source_source_template),events:function(){var e={};return e[vup+" .row"]="onItemClick",e},initialize:function(){this.render()},render:function(){this.$el.html(this.template(this.model.toJSON()))},onItemClick:function(){var e=this.model.get("sourceType");if(!e)return null;this.trigger("click");if(e==="bluetooth")srcObj.bluetooth.getContent("BLUETOOTH",null,"bluetooth",this.model.get("uID"));else if(e==="aux")if(this.model.get("uID")!==funcObj.UIMain.getUID()||funcObj.play.getCurPlaySrc()!=="aux"){var t=$(this.local_source_template(this.model.toJSON()))[0],n=funcObj.wrkr_tools.xmlToJson(t);srcObj.aux.sendSelectContentItem(n,null,this.model.get("uID"))}var r="#"+this.model.get("sourceAccount")+".local_source_radio";$(r).prop("checked",!0),setTimeout(_.bind(function(){$("#"+this.model.get("parentEl")).close()},this),500)}});App.Models.LocalSourceModel=Backbone.Model.extend({defaults:{el:"#bbd",title:"",dismissable:!0,sourceType:""}}),App.Views.LocalSourceView=Backbone.View.extend({id:"child_content",el:"#child_content",template:_.template(local_source_drawer_template),collection:null,itemView:n,tagName:"ul",initialize:function(e){this.render(),this.setElement(e.el)},events:function(){},render:function(e){if(!this.model.get("deviceId"))return;this.$el.html(this.template({title:this.model.get("title"),closeAccessibility:funcObj.contentCon.getContent("ACCESSIBILITYATTR",{repl:{LABEL:funcObj.langCon.getString("AccessibilityMessages_Close")}})})),this.model.get("title")||this.$el.find("header").addClass("hide"),this.getLocalSources(this.model.get("deviceId")),this.collection.each(function(e){var t=new n({model:e});this.$el.find(this.tagName).append(t.el)},this),this.setSelectedSource(this.model.get("deviceId"))},getLocalSources:function(n){var r=this.model.get("sourceType");if(!r)return null;var i=new t,s=[],o=funcObj.groupCon.getGroupByUID(n);if(o)for(var u in o.roles){srcObj[r].clearAuxCount(o.roles[u]),srcObj[r].updateDevice(o.roles[u]);var a=funcObj.sources.getLocalSources(o.roles[u]);for(var f in a)a[f].uID=o.roles[u],a[f].role=u;s=s.concat(a)}else srcObj[r].clearAuxCount(n),srcObj[r].updateDevice(n),s=funcObj.sources.getLocalSources(n);for(var l=0,c=s.length-1;l<=c;l++){var h=s[l];if(h.sourceName!==r)continue;h.sourceType=r;var p=srcObj[h.sourceName],d=p.getFeature("transPath"),v=h.displayName||h.sourceName,m="";if(h.role)m=funcObj.langCon.getString(d+"_defaultNames_"+v.toLowerCase().replace(/\s/g,"")+h.role),h.name=m;else{var g=h.sourceAccount.match(/\d+/)[0],y="";g!=null&&g.match(/\S/)&&(y=" "+g),funcObj.UIMain.isValidXMLSelector(v)&&(m=funcObj.langCon.getString(d+"_defaultNames_"+v.toLowerCase().replace(/\s/g,"")));if(m.match(/\S/))h.name=m;else{var b=p.getFeature("sourceName")+y,w=funcObj.langCon.getString(d+"_defaultNames_"+b.toLowerCase().replace(/\s/g,""));h.name=v,h.sub=w}}h.useIcon=srcObj[h.sourceName].getFeature("sourceIcon"),h.parentEl=this.model.get("parentDrawer"),i.push(new e(h))}this.collection=i},setSelectedSource:function(e){e=e||funcObj.UIMain.getUID();var t=funcObj.devCon.getDevice(e),n=t&&t.sObj?t.sObj.getCache("nowPlaying"):"",r=n&&n.xmlDoc?n.xmlObj:"";if(r&&r.ContentItem){var i=r.ContentItem._sourceAccount,s=r.ContentItem._source;if(s){var o=funcObj.groupCon.getGroupByUID(e);if(o)for(var u in o.roles)if(o.roles[u]===e){i=s+u;break}}var a=s&&s.toLowerCase()==="aux";i&&a&&$("#"+i).prop("checked",!0)}}})})();