?
Path : /home/admin/public_html/old/promice/components/com_linkr/assets/js/ |
Current File : /home/admin/public_html/old/promice/components/com_linkr/assets/js/tree.js |
var LinkrTree={options:{title:'Linkr',objName:'LinkrTree',cookieSettings:{duration:14,autoSave:false}},search:{sql:{}},tmpl:{setupTree:function(r){this.setMsg('No Tree setup method found!')},buildTree:function(is,el){var isChild=$type(el)=='element';if($type(is)!='object'){if(isChild)is={};else return this.setMsg('Invalid tree items')}if(isChild){var te=new Element('ul').injectInside(el)}else{var te=new Element('ul',{id:'tree'}).injectInside($('treeDiv'))}for(n in is){if(!$defined(is[n]))continue;var i=this.getItemObject(is[n]);i.id=n;i.element=new Element('li').injectInside(te);var ie=new Element('span').injectInside(i.element);i.icon=new Element('img',{src:i.expandIcon,align:'absmiddle'}).injectInside(ie);i.link=new Element('a',{href:'javascript:void(0)',events:{click:this.tmpl.toggle.bind(this,i)}}).setHTML(i.title).injectInside(ie);this.itemRef[n]=i}return te},toggle:function(i){i=this.getItemObject(i);if(i.list)this.tmpl.collapse(i);else this.tmpl.expand(i);this.selectItem(i)},expand:function(i){i=this.getItemObject(i);if(i.list)return;if(i.children){i.icon.setProperty('src',Linkr.loadingIcon);this.tmpl.children(i.children,i)}},expandAll:function(){var o=new Element('img',{src:Linkr.loadingIcon,alt:'...'});$('xt').replaceWith(o);var z;for(id in this.itemRef){z=id;this.tmpl.expand(this.itemRef[id])}this.timer=function(i,o){if(i.list){this.timer=$clear(this.timer);o.replaceWith(new Element('a',{id:'xt',href:'javascript:void(0);',styles:{'font-weight':'bold'},events:{click:this.tmpl.expandAll.bind(this)}}).setHTML(this._('EXPAND')))}}.periodical(50,this,[this.itemRef[z],o])},children:function(dbr,i){if($defined(i.treeItems)){i.list=this.tmpl.buildTree(i.treeItems,i.element);return i.icon.setProperty('src',i.collapseIcon)}if($type(dbr)=='array'){var q=this._buildSQL(dbr[0],$pick(dbr[1],false));return this.tmpl.dbList(q,0,0,this.tmpl.children.bind(this),i)}var err=this.tmpl.isError(dbr);if(err!==false)return this.setMsg(err);i.treeItems=this.tmpl.setupTree(dbr.result,i.level+1);i.list=this.tmpl.buildTree(i.treeItems,i.element);i.icon.setProperty('src',i.collapseIcon)},collapse:function(i){i=this.getItemObject(i);if(!i.list)return;i.list.remove();i.list=false;i.icon.setProperty('src',i.expandIcon)},collapseAll:function(){for(id in this.itemRef)this.tmpl.collapse(this.itemRef[id])},dbList:function(q,s,l,c,a){var d=Linkr.dbList(q,s,l,c,a);return d===false?this.home():null},dbObject:function(q,c,a){var d=Linkr.dbObject(q,c,a);return d===false?this.home():null},isError:function(o){if(!Linkr.isDBRO(o))return'Linkr Error: Invalid database object';if(Linkr.isError(o))return'Database Error: '+o.msg;return false}},icons:{expand:'administrator/images/expandall.png',collapse:'administrator/images/collapseall.png'},itemRef:{},getInstance:function(c,o,p,y){c=$type(c)=='object'?c:{};p=$type(p)=='object'?p:{};y=$type(y)=='object'?y:{};var copy=new Class(this);copy.implement(new Options,new Events);return new copy(c,o,p,y)},initialize:function(o,r,s,t){this.setOptions(o);this._tree=r;this.search=$merge(this.search,$pick(s,{}));this.tmpl=$merge(this.tmpl,$pick(t,{}));for(m in this.layout)this.layout[m]=this.layout[m].bind(this);for(m in this.tmpl)this.tmpl[m]=this.tmpl[m].bind(this);if(this.options.initialize)this.options.initialize.call(this)},setMsg:function(m,r){if(['array','string'].contains($type(m))&&m.length>0){var w=new Element('div').injectBefore($('tree'));Linkr.insertMsgDiv(m,w)}if($type(m)=='array')m=m.join('; ');Linkr.setError('['+this.objName+': message] '+m);return r},landing:function(){Linkr.delayIdleDiv('layout',this.home.bind(this))},home:function(){var tree=new Element('div',{id:'treeDiv'});Linkr.htmlLayout(this.options.title,tree);Linkr.htmlTBLinks([['xt',this._('EXPAND'),this.tmpl.expandAll.bind(this)],['tgls',this._('CONFIGURE_LINK')],[0,this._('GET_LINK'),this.insert.bind(this)]]).injectInside(tree);Linkr.htmlConfig('',[['linkText',this._('LC_TEXT'),Linkr.getSelectedText()],['target',this._('LC_TARGET'),[['_self',this._('LC_TARGET_SELF'),'selected'],['_blank',this._('LC_TARGET_BLANK')]]],['linkTitle',this._('LC_TITLE')],['linkClass',this._('LC_CLASS')],['linkRelation',this._('LC_RELATION')],['linkURL','URL',Linkr.htmlInput('linkURL','index.php',{'class':'inputbox value',disabled:true})]]).setStyles({'border-bottom':'2px solid #ccc'}).injectInside(tree);var is=this.tmpl.setupTree(this._tree,0);this.tmpl.buildTree(is);this._itemDiv=new Element('div',{styles:{position:'fixed',bottom:5,right:40,margin:0,padding:'3px 10px',width:'auto',border:'1px solid #aaa','border-left-width':5,'border-right-width':5,'background-color':'#eee'}}).setHTML('('+this._('NONE')+')').injectInside($('layout'));Linkr.createToggleLink('settings','tgls');Linkr.setReturnPage([this.options.objName,'home'])},getItemObject:function(o){if(['number','string'].contains($type(o)))o=$pick(this.itemRef[o],{});if($type(o)!='object')o={};var t=$pick(o.title,'');if($type(t)!='string'||t.length<1)o.title='...?';var d=$pick(o.description,'');if($type(d)!='string'||d.length<1)o.description=false;var u=$pick(o.url,'');if($type(u)!='string'||u.length<1)o.url=false;o.level=$pick(o.level,0);var e=$pick(o.expandIcon,'');if($type(e)!='string'||e.length<5)o.expandIcon=Linkr.siteRoot+this.icons.expand;var c=$pick(o.collapseIcon,'');if($type(c)!='string'||c.length<5)o.collapseIcon=Linkr.siteRoot+this.icons.collapse;var k=$pick(o.children,0);if($type(k)!='array'||k.length<1)o.children=false;return o},selectItem:function(i){i=this.getItemObject(i);if(i.url){var u=i.url,c='#ffd',t=i.title,h=Linkr.getDefaultText(i.title)}else{var u='index.php',c='#eee',t='('+this._('NONE')+')',h=Linkr.getSelectedText()}$('linkURL').value=u;$('linkText').value=h;this._itemDiv.setStyle('background-color',c).setHTML(t)},insert:function(){var te=$('linkText');if(!te)return this.setMsg('Missing "linkText" element');var ue=$('linkURL');if(!ue)return this.setMsg('Missing "linkURL" element');var txt=te.getValue();if(txt.trim().length==0)return alert(Linkr.missingText);var u=ue.getValue();var fe=$('format');if(fe){var f=fe.getValue();switch(f){case'rss':case'atom':u+='&format=feed&type='+f;break;default:if(f!=''&&f!='html')u+='&format='+f}}Linkr.link(u,txt)},link:function(){return this.insert()},_buildSQL:function(t,w){var wt=$type(w);if(wt=='string'&&w.length>0)w=Linkr.dbQuote(w);else if(wt!='number')w=false;var q=false;var qo=$pick(this.search.sql[t],false);var qot=$type(qo);if(qot!='string'&&qot!='function')return this.setMsg('Invalid SQL query type "'+t+'"','');if(qot=='function')q=qo.attempt(w,this);if(qot=='string')q=qo.replace(/\[query]/g,w).replace(/\[access]/g,Linkr.userAccessLevel);if($type(q)!='string'||q.length<1)return this.setMsg('Invalid SQL query type "'+t+'"','');return q},getCookie:function(rc){return Linkr.getCookie(this.options.objName,this.options.cookieSettings,rc)},setCookie:function(v){return Linkr.setCookie(this.options.objName,v,this.options.cookieSettings)},_:function(t,a){return Linkr.getL18N(t,a)},dump:function(a){var dump=Linkr.dump(a,false,true);dump=dump.replace(/\n/g,'<br/>').replace(/\s/g,' ');this.display(dump);return false}};