if(window.console==null)
window.console=
{
log:function(p){}
};
var send=false;
var ContentControler=Class.create(
{
init:function(template,element,data)
{
this.template=template;
this.element=element;
this.data=data;
this.plugins=new Array();
this.belongsTo=ContentList;
this.type="ContentControler";
this.urlPart='';
this.innerLoading=false;
},
initDI:function()
{
if(this.di==null)
{
this.di=new DataAccessInterface(this);
$(this.di).bind('data',createDelegate(this,this.onDataLoad));
}
},
montar:function()
{
with(this){
var t=getTemplate();
render(t);
PluginManager.attachPlugins(this);
}
},
render:function(t)
{
with(this){
element.append(t,getTemplateData());
}
},
getTemplate:function()
{
return $.template(this.template.content);
},
load:function(params)
{
with(this)
{
initDI();
var defaultParams=DataAccessInterface.getRequestParams(
$.getURLParam('o')==null?'Id':$.getURLParam('o'),
0,
0,
$.getURLParam('t')==null?TAGS_AREA_ATUAL:$.getURLParam('t'),
0,
null,
$.getURLParam('v')==null?null:$.getURLParam('v')
);
var request={};
$.extend(request,defaultParams,params);
di.getData('get',request);
}
},
onDataLoad:function(ev,data)
{
this.data=data;
this.montar();
},
getTemplateData:function()
{
with(this)
{
var pluginData=placePlugins(),
params=getSupportParameters(),
templateData={};
$.extend(templateData,this.data,params,pluginData);
return templateData;
}
},
getSupportParameters:function()
{
var r={
UrlArea:URL_AREA_ATUAL,
ContentLink:this.getContentLink()
};
if(this.data._index!=null)
r.Numero=this.data._index+1;
return r;
},
placePlugins:function()
{
with(this)
{
var pluginData={};
this.plugins=new Array();
if(data.Plugins!=null)
{
for(var k=0;k<data.Plugins.length;k++)
{
plugins[k]=PluginManager.createPlugin(data.Plugins[k].Tipo,data.Plugins[k],this);
pluginData["Plugin_"+data.Plugins[k].Tipo]=plugins[k].place();
}
}
return pluginData;
}
},
getContentLink:function()
{
return"";
}
});
var AjaxForm=Class.create(
{
init:function(element,externalInterface,action)
{
this.type="AjaxForm";
this.element=element;
this.externalInterface=externalInterface;
this.action=action;
this.formItens=$('[formName]');
this.setupInterface();
},
initDai:function(){
if(this.dai==null){
this.dai=new DataAccessInterface(this);
$(this.dai).bind('data',createDelegate(this,this.onData));
}
},
setupInterface:function(){
this.externalInterface.submit.bind("click.a",createDelegate(this,this.submit));
},
submit:function(){
if(!send&&this.validateForm()){
send=true
this.sendData();
}
},
sendData:function(){
with(this){
var params={pp:PessoaLogada==null?0:PessoaLogada.Id};
for(var k=0;k<formItens.length;k++){
params[formItens.eq(k).attr('formName')]=encodeURI(formItens.eq(k).val());
}
initDai();
dai.getData(action,params);
}
},
onData:function(ev,data){
if(data.Message==null){
Message.show("Informações enviadas com sucesso","success");
$(this).trigger('sucess');
}
else{
Message.show("Ocorreu um erro processo sua solicitação:<br />"+data.Message);
}
send=false;
},
validateForm:function(){
var r=true;
return r;
}
});
var ContentList=Class.create(
{
init:function(template,element,externalInterface,data)
{
this.initProperties(template,element,externalInterface,data);
this.connectExternalInterface();
},
initProperties:function(template,element,externalInterface,data)
{
this.element=element;
this.data=data;
this.type="ContentList";
this.hasMany=ContentControler;
this.template=template;
this.itens=new Array();
this.wrapper=null;
this.externalInterface=externalInterface;
this.noContent=false;
this.hideParent=false;
this.pageSize=8;
this.pageIndex=0;
},
initDI:function()
{
if(this.di==null)
{
this.di=new DataAccessInterface(this);
$(this.di).bind('data',createDelegate(this,this.onDataLoad));
}
},
montar:function()
{
this.verifyExternalInterface();
this.montarLista();
},
montarLista:function()
{
with(this)
{
if(data[type].length)
{
createWrapper(element.lista);
for(var k=0;k<data[type].length;k++)
{
data[type][k]._index=itens.length;
itens.push(new hasMany(template.listItem,wrapper,data[type][k]));
itens[itens.length-1].montar();
}
}
verifyEmpty();
}
},
verifyEmpty:function()
{
with(this)
{
if(!data[type].length&&!noContent)
{
if(hideParent&&externalInterface.parent.length)
{
externalInterface.parent.hide();
}
else
{
var t=template.noContent==null
?Templates.noContent
:template.noContent;
element.lista.append($.template(t),data);
noContent=true;
}
}
else
{
noContent=false;
$('.noContent',element.lista).hide();
}
}
},
createWrapper:function(el)
{
with(this)
{
if(this.wrapper==null)
{
var templateData={};
$.extend(templateData,data);
$(el).append(template.listWrapper,data);
this.wrapper=$(el).find('.listWrapper');
return this.wrapper;
}
}
},
load:function(params)
{
with(this)
{
this.initDI();
var defaultParams=DataAccessInterface.getRequestParams(
$.getURLParam('o')==null
?'Id'
:$.getURLParam('o'),
$.getURLParam('d')==null
?'Crescent'
:$.getURLParam('d'),
pageIndex,
pageSize,
$.getURLParam('t')==null
?TAGS_AREA_ATUAL
:$.getURLParam('t'),
100,
null,
$.getURLParam('v')==null
?null
:$.getURLParam('v')
),
request={};
$.extend(request,defaultParams,params);
di.getData('get',request);
}
},
onDataLoad:function(ev,data)
{
this.data=data;
this.montar();
},
connectExternalInterface:function()
{
this.externalInterface!=null&&this.externalInterface.nextPage!=null
&&this.externalInterface.nextPage.click(createDelegate(this,this.nextPageClick));
},
nextPageClick:function()
{
this.nextPage();
this.verifyExternalInterface();
return false;
},
verifyExternalInterface:function()
{
with(this)
{
if(externalInterface!=null)
{
if(data.Total-((pageIndex+1)*pageSize)<=0)
externalInterface.nextPage!=null
&&externalInterface.nextPage.hide();
else
externalInterface.nextPage!=null
&&externalInterface.nextPage.show();
}
}
},
nextPage:function()
{
this.pageIndex++;
this.load();
},
resetContent:function()
{
this.wrapper!=null
&&this.wrapper.html('');
this.itens=new Array();
},
limit:function(elem)
{
var element=$("strong.caracter"),
char=Number(element.text());
elem
.keyup(function()
{
var	texto=$(this).val(),
tamanho=texto.length,
line=texto.replace(/\s+$/g,""),
separate=line.split("\n"),
separateLength=separate.length;
if(tamanho>char)
{
elem.val(texto.substr(0,char));
return false;
}
else
{
element.html(char-tamanho);
return true;
}
})
.keypress(function(e)
{
if(e.keyCode==13)
return false;
});
}
});
var PluginManager=Class.create(true);
PluginManager.namespace('plugins');
PluginManager.createPlugin=function(name,data,controler){
var pluginClass=PluginManager.plugins[name]!=null?PluginManager.plugins[name]:PluginManager.plugins.Plugin;
var p=new pluginClass(data,controler);
return p;
};
PluginManager.attachPlugins=function(controler){
for(var k=0;k<controler.plugins.length;k++){
controler.plugins[k].render($('#'+controler.plugins[k].id,controler.element));
}
};
PluginManager.pluginCount=0;
PluginManager.registeredPlugins=new Array();
PluginManager.registerPlugin=function(plugin){
var id="__p_"+PluginManager.pluginCount++;
PluginManager.registeredPlugins[id]=plugin;
return id;
};
PluginManager.plugins.create('Plugin',
{
init:function(data,controler,element){
this.data=data;
this.controler=controler;
this.element=element;
this.type='Plugin';
this.template='';
this.id=PluginManager.registerPlugin(this);
this.initWebInterface();
},
initWebInterface:function(){
this.webInterface=new DataAccessInterface(this);
$(this.webInterface).bind('data',createDelegate(this,this.onResponse));
},
onResponse:function(ev){
alert('opa');
},
place:function(){
return'<span id="'+this.id+'"></span>';
},
render:function(ph)
{
with(this)
{
var t=$.template(getTemplate().content),
params=getSupportParameters(),
templateData={};
$.extend(templateData,controler.data,this.data,params,controler.getSupportParameters());
ph.append(t,templateData);
this.element=ph;
}
},
attachBehavior:function(ph){
},
getSupportParameters:function(){
var p={UrlArea:URL_AREA_ATUAL};
if(this.getTemplate().params!=null)$.extend(p,this.getTemplate().params);
return p;
},
getTemplate:function(){
with(this){
template=Templates.plugins[type];
if(controler.template.plugins!=null&&controler.template.plugins[type]!=null){
if(controler.template.plugins[type].content!=null){
template.content=controler.template.plugins[type].content;
}
if(controler.template.plugins[type].params!=null){
template.params=controler.template.plugins[type].params;
}
}
return template;
}
}
});
