Ext.namespace('GFactory.WritersCallStore');GFactory.WritersCallStore=Ext.extend(Ext.data.DirectStore,{constructor:function(config){DirectWorkflow.writercallRead.directCfg.method.len=1;this.store_error=false;Ext.apply(config,{root:'data',totalProperty:'count',idProperty:'id_content_external',fields:['id_content_external','author','title','tags','url','comments',{name:'close_date',type:'date',dateFormat:'Y-m-d G:i:s'},{name:'description',allowBlank:'false'}],baseParams:{uuid:document.profile_id_content_external},api:{read:DirectWorkflow.writercallRead,create:Ext.emptyFn,update:Ext.emptyFn,destroy:Ext.emptyFn},scope:this});GFactory.WritersCallStore.superclass.constructor.call(this,config);this.loadTask=new Ext.util.DelayedTask(GFactory.WritersCallStore.superclass.load,this);this.paginator=new Ext.uxp.data.store.Paginator({store:this,nb_per_page:5,renderTo:config.paginatorRenderTo});this.on('datachanged',this._updateDisplay,this);this.on('exception',this._exceptionHandler,this);this.on('beforeload',function(){Ext.get(this.displayTarget).update('<span class="loading">'+_('Loading data, please wait…')+'</span>');},this);this.on('load',function(){this.store_error=false;},this);},delayedLoad:function(){if(!Ext.isEmpty(Ext.get(this.displayTarget))){Ext.get(this.displayTarget).update('<span class="loading">'+_('Loading data, please wait…')+'</span>');this.paginator.hide();}
if(!Ext.isEmpty(this.loadTask)){this.loadTask.cancel();}
this.loadTask.delay(1000);},setDisplay:function(displayTarget,tpl,tpl_error){this.tpl=new jsontemplate.Template(tpl,{more_formatters:Ext.more_formatters});this.tpl_error=new Ext.XTemplate(tpl_error);this.displayTarget=displayTarget;},_updateDisplay:function(){if(this.tpl&&this.displayTarget){this.tdatas=[];if(this.store_error){this._html=this.tpl_error.applyTemplate({storeId:this.storeId});}
else{this.each(function(record,i){try{record.data.uuid=document.profile_id_content_external;this.tdatas.push(record.data);}
catch(e){Ext.log(e);}},this);Ext.get(this.displayTarget).update(this.tpl.expand(this.tdatas));setMPActions(this.displayTarget);this.tdatas=[];}}},_exceptionHandler:function(dataProxy,type,action,options,response,arg){var i,t,records;if(type=='remote'&&action=='read'){this.store_error=true;this.fireEvent('datachanged',this);this.fireEvent('readerror',this);}
else
if(type=='remote'&&action=='update'){t=response.getTransaction();records=this._recordsFromTransaction(t);for(i=0;i<records.length;i++){records[i].reject(true);}
for(i=0;i<records.length;i++){this.fireEvent('updatecanceled',this,records[i]);}
this.fireEvent('datachanged',this);Ext.log('updatecanceled');}
else
if(type=='remote'&&action=='destroy'){t=response.getTransaction();records=this._recordsFromTransaction(t);this.suspendEvents();for(i=0;i<records.length;i++){GFactory.CommentsStore.superclass.addSorted.call(this,records[i]);}
this.resumeEvents();for(i=0;i<records.length;i++){this.fireEvent('destroycanceled',this,records[i]);Ext.log('destroycanceled '+i);}
this.fireEvent('datachanged',this);Ext.log('destroycanceled');}
else
if(type=='remote'&&action=='create'){t=response.getTransaction();records=this._recordsFromTransaction(t);this.suspendEvents();for(i=0;i<records.length;i++){this.remove(records[i]);}
this.resumeEvents();for(i=0;i<records.length;i++){this.fireEvent('createcanceled',this,records[i]);}
this.fireEvent('datachanged',this);Ext.log('createcanceled');}}});Ext.namespace('GFactory.TranslationsCallStore');GFactory.TranslationsCallStore=Ext.extend(Ext.data.DirectStore,{constructor:function(config){this.uuid=config.uuid;DirectWorkflow.translationcallRead.directCfg.method.len=1;this.store_error=false;this.tpl=new Ext.XTemplate('<tpl for=".">','<div class="call-item clear">','   <h2>{title}</h2>','   <h5 class=\'label\'><tpl for="tags">{title}{[xindex < xcount ? ", " : ""]}</tpl>  |  VO : {lang:this._}</h5>','   <div class="call-text column span-2 border">','       <p>{description}</p>','        <div class="call-info">','           <tpl for="editor"><p><strong>'+_('In charge:')+' <a href="{url}">{display_name}</a> <a href="/profile/messages/sendTo/{id_content_external}/{display_name}/">@</a></strong></p></tpl>','           <tpl for="author">','           <p>'+_('Author:')+' <a href="{url}">{name}</a> <a href="/profile/messages/sendTo/{id_content_external}/{name}/">@</a>','           </tpl>','           <p>'+_('Publication date:')+' {publication_date:date}</p>','       </div>','       <p>','           <tpl if="is_public==1">','           <a href="{url}">'+_('Read original online')+'</a> | ','           </tpl>','           <a target="blank" href="/preview/{id_content_external}/">'+_('Download original text')+'</a>','       </p>','   <tpl if="translator !== null"> <!-- Translator section -->','   <tpl for="translator">','   <tpl if="id_content_external === parent.uuid"> <!-- Translator is user profile -->','       <p><strong><a target="blank" href="/preview/{parent.translation_id_content_external}/">'+_('Important : download the reference translation')+'</a></strong></p>','   </tpl>','   </tpl>','   </tpl>','   </div>','   <div class="column span-1 last">','   <tpl if="translator !== null"> <!-- Translator section -->','       <tpl for="translator">','           <tpl if="id_content_external === parent.uuid && parent.writing==1"> <!-- Translator is user profile -->','       <p>','           <a href="/profile/publish/{parent.uuid}/{parent.translation_id_content_external}/" class=" submit-input submit-orange">'+_('Submit the text!')+'</a>','       </p>','       <p>','           <a class="translation-giveup" href="#{parent.translation_id_content_external}" >'+_('Give up…')+'</a>','       </p>','           </tpl>','           <tpl if="id_content_external !== parent.uuid"> <!-- Translator is anyone else than user profile -->','               <p>','                   '+_('Translation taken by')+' <a href="{url}">{name}</a> <a href="/profile/messages/sendTo/{id_content_external}/{name}/">@</a>','               </p>','           </tpl>','       </tpl>','   </tpl>','   <tpl if="translator === null"> <!-- There is no translator-->','       <tpl if="translation_locked === 1">','           <p>','               <strong>'+_('Translation locked')+'</strong><br />','               '+_('You can apply for translating this text:')+' <a class="ask-for-translation" href="#{id_content_external}">'+_('Click here')+'</a>.','           </p>','       </tpl>','       <tpl if="is_public === 1">','          <p class="vote clear">','              <span class="comments-nb"><span>{comments}</span><em>'+_('comment(s)')+'</em></span>','              <span class=" votedisabled voteplus"><span>{votes}</span><em>'+_('vote(s)')+'</em></span>','          </p>','       </tpl>','       <tpl if="translation_locked === 0">','          <p>','               <a href="#{id_content_external}" class="translation-assign submit-input submit-green">'+_('Translate it!')+'</a>','          </p> ','       </tpl>','   </tpl>','   <tpl if="this.isStaff()">','           <p class="order-tools">','               <em>Order :</em> ','               <a class="move-up <tpl if="Ext.isEmpty(prev_id_content_external)">disabled</tpl>"  title="'+_('Move up')+'" href="#{index}">+</a>','               <a class="move-down <tpl if="Ext.isEmpty(next_id_content_external)">disabled</tpl>" href="#{index}" title="'+_('Move down')+'">-</a>','               <a class="move-last <tpl if="Ext.isEmpty(next_id_content_external)">disabled</tpl>" href="#{index}" title="'+_('Send at the end of the list')+'">x</a>','           </p>','       </tpl>','   </div>','</div>','</tpl>',{compiled:true,_:function(value){return _(value);},isStaff:function(){return GFactory.Session.user.get('is_staff');}});Ext.apply(config,{root:'data',totalProperty:'count',idProperty:'id_content_external',autoSave:false,fields:['translator','translation_id_content_external','prev_id_content_external','next_id_content_external','editor','author','comments','lang','tags','translation_relevance','translation_locked','is_public','votes','nb_links_on_parent','url','id_content_external','title','description',{name:'publication_date',type:'date',dateFormat:'Y-m-d H:i:s'},'writing'],baseParams:{uuid:document.profile_id_content_external},api:{read:DirectWorkflow.translationcallRead},scope:this});GFactory.TranslationsCallStore.superclass.constructor.call(this,config);this.loadTask=new Ext.util.DelayedTask(GFactory.TranslationsCallStore.superclass.load,this);if(!Ext.isEmpty(config.paginatorRenderTo)){this.paginator=new Ext.uxp.data.store.Paginator({store:this,nb_per_page:10,renderTo:config.paginatorRenderTo});}
this.on('update',this._updateDisplay,this);this.on('datachanged',this._updateDisplay,this);this.on('exception',this._exceptionHandler,this);this.on('beforeload',function(){if(!Ext.isEmpty(Ext.get(this.displayTarget))){Ext.get(this.displayTarget).update('<span class="loading">'+_('Loading data, please wait…')+'</span>');}},this);this.on('load',function(){this.store_error=false;},this);},delayedLoad:function(){if(!Ext.isEmpty(Ext.get(this.displayTarget))){Ext.get(this.displayTarget).update('<span class="loading">'+_('Loading data, please wait…')+'</span>');this.paginator.hide();}
if(!Ext.isEmpty(this.loadTask)){this.loadTask.cancel();}
this.loadTask.delay(1000);},setDisplay:function(displayTarget,tpl_error){this.tpl_error=new Ext.XTemplate(tpl_error);this.displayTarget=displayTarget;},_updateDisplay:function(){if(this.tpl&&this.displayTarget){this.tdatas=[];if(this.store_error){this._html=this.tpl_error.applyTemplate({storeId:this.storeId});}else{if(this.getCount()===0){Ext.get(this.displayTarget).update(_('No matching data'));}else{this.each(function(record,i){try{record.data.uuid=document.profile_id_content_external;record.data.index=i;this.tdatas.push(record.data);}
catch(e){Ext.log(e);}},this);this.tpl.overwrite(Ext.get(this.displayTarget),this.tdatas);setMPActions(this.displayTarget);Ext.get(this.displayTarget).select('.translation-giveup').each(function(el){el.on('click',function(event,target){event.preventDefault();this.giveupTranslation(target.href.split('#')[1]);return false;},this);},this);Ext.get(this.displayTarget).select('.translation-assign').each(function(el){el.on('click',function(event,target){event.preventDefault();this.assignTranslation(target.href.split('#')[1]);return false;},this);},this);Ext.get(this.displayTarget).select('.ask-for-translation').each(function(el){el.on('click',function(event,target){event.preventDefault();this.translationAskFor(target.href.split('#')[1]);return false;},this);},this);Ext.get(this.displayTarget).select('.move-up').each(function(el){el.on('click',function(event,target){event.preventDefault();this.moveUp(target.href.split('#')[1]);return false;},this);},this);Ext.get(this.displayTarget).select('.move-down').each(function(el){el.on('click',function(event,target){event.preventDefault();this.moveDown(target.href.split('#')[1]);return false;},this);},this);Ext.get(this.displayTarget).select('.move-last').each(function(el){el.on('click',function(event,target){event.preventDefault();this.moveLast(target.href.split('#')[1]);return false;},this);},this);}
this.tdatas=[];}}},moveUp:function(record_index){var record=this.getAt(record_index);DirectWorkflow.contribSetRelevance(record.get('id_content_external'),record.get('prev_id_content_external'),function(){this.reload();},this);},moveDown:function(record_index){var record=this.getAt(record_index);DirectWorkflow.contribSetRelevance(record.get('id_content_external'),record.get('next_id_content_external'),function(){this.reload();},this);},moveLast:function(record_index){var record=this.getAt(record_index);DirectWorkflow.contribSetRelevance(record.get('id_content_external'),0,function(){this.reload();},this);},translationAskFor:function(id_content_external){Ext.oxp.CGUTranslationLocked.show();Ext.oxp.CGUTranslationLocked.on('ok',function(){DirectWorkflow.translationAskFor(this.uuid,id_content_external,function(response){var record;if(response.success===true){Ext.oxp.Alert.success(_('Votre intérêt pour la traduction de cet article a bien été pris en compte. Vous serez averti par message privé des suites données à votre demande.'));}else{Ext.oxp.Alert.failure(_(response.error));}},this);},this);},giveupTranslation:function(id_content_external){Ext.oxp.Alert.confirm(_('Are you want to give up this translation ?'),_('Give up a translation'));Ext.oxp.Alert.on('ok',function(){DirectWorkflow.translationGiveup(this.uuid,id_content_external,function(response){if(response.success===true){this.getById(response.original_id).set('translator',null);}else{Ext.oxp.Alert.failure(_(response.error));}},this);},this);},assignTranslation:function(id_content_external){Ext.oxp.CGUTranslation.show();Ext.oxp.CGUTranslation.on('ok',function(){DirectWorkflow.translationAssign(this.uuid,id_content_external,function(response){var record;if(response.success===true){record=this.getById(response.original_id);record.beginEdit();record.set('translation_id_content_external',response.translation_id_content_external);record.set('translator',{'id_content_external':this.uuid});record.endEdit();}else{Ext.oxp.Alert.failure(_(response.error));}},this);},this);},_exceptionHandler:function(dataProxy,type,action,options,response,arg){var i,t,records;if(type=='remote'&&action=='read'){this.store_error=true;this.fireEvent('datachanged',this);this.fireEvent('readerror',this);}
else
if(type=='remote'&&action=='update'){t=response.getTransaction();records=this._recordsFromTransaction(t);for(i=0;i<records.length;i++){records[i].reject(true);}
for(i=0;i<records.length;i++){this.fireEvent('updatecanceled',this,records[i]);}
this.fireEvent('datachanged',this);Ext.log('updatecanceled');}
else
if(type=='remote'&&action=='destroy'){t=response.getTransaction();records=this._recordsFromTransaction(t);this.suspendEvents();for(i=0;i<records.length;i++){GFactory.CommentsStore.superclass.addSorted.call(this,records[i]);}
this.resumeEvents();for(i=0;i<records.length;i++){this.fireEvent('destroycanceled',this,records[i]);Ext.log('destroycanceled '+i);}
this.fireEvent('datachanged',this);Ext.log('destroycanceled');}
else
if(type=='remote'&&action=='create'){t=response.getTransaction();records=this._recordsFromTransaction(t);this.suspendEvents();for(i=0;i<records.length;i++){this.remove(records[i]);}
this.resumeEvents();for(i=0;i<records.length;i++){this.fireEvent('createcanceled',this,records[i]);}
this.fireEvent('datachanged',this);Ext.log('createcanceled');}}});Ext.namespace('GFactory.UserContribStore');GFactory.UserContribStore=Ext.extend(Ext.data.DirectStore,{constructor:function(config){DirectWorkflow.contribRead.directCfg.method.len=1;DirectWorkflow.contribUpdate.directCfg.method.len=2;this.store_error=false;Ext.apply(config,{root:'data',totalProperty:'count',idProperty:'id_content_external',fields:['title','description','notes','language','id_content_external','status','editor','is_original','original_author','original_id_content_external','original_is_public','original_url'],baseParams:{uuid:document.profile_id_content_external},storeId:Ext.id(null),api:{read:DirectWorkflow.contribRead,create:Ext.emptyFn,update:DirectWorkflow.contribUpdate,destroy:Ext.emptyFn},writer:new Ext.data.JsonWriter({writeAllFields:true}),scope:this});GFactory.UserContribStore.superclass.constructor.call(this,config);this.on('datachanged',this._updateDisplay,this);this.on('exception',this._exceptionHandler,this);this.on('update',function(){this.fireEvent('datachanged',this);},this);this.on('load',function(){this.store_error=false;},this);},setDisplay:function(displayTarget,tpl,tpl_error){this.tpl=new jsontemplate.Template(tpl,{more_formatters:Ext.more_formatters});this.tpl_error=new Ext.XTemplate(tpl_error);this.displayTarget=displayTarget;},deleteContrib:function(index){Ext.oxp.Alert.confirm(_('Are you sure you want to delete this text ?'));Ext.oxp.Alert.on('ok',function(){this.getAt(index).set('status','DELETED');},this);},giveupContrib:function(index){Ext.oxp.Alert.confirm(_('Are you sure you want to give up this translation ?'));Ext.oxp.Alert.on('ok',function(){DirectWorkflow.translationGiveup(document.profile_id_content_external,this.getAt(index).get('id_content_external'),function(response){if(response.success===true){this.reload();}else{Ext.oxp.Alert.failure(_(response.error));}},this);},this);},_updateDisplay:function(){if(this.tpl&&this.displayTarget){this.tdatas={proposals:[],waiting:[]};if(this.store_error){this._html=this.tpl_error.applyTemplate({storeId:this.storeId});}
else{this.each(function(record,i){try{record.data.store_id=this.storeId;record.data.index=i;record.data.uuid=document.profile_id_content_external;if(record.data.is_original===0){record.data.translation={index:i,original_author:record.data.original_author,'original_id_content_external':record.data.original_id_content_external};if(record.data.original_is_public){record.data.translation.original_is_public={'original_url':record.data.original_url};}}
if(record.data.status==='proposal'){this.tdatas.proposals.push(record.data);}else if(record.data.status==='draft'){this.tdatas.waiting.push({draft:record.data});}else if(record.data.status==='refused'){this.tdatas.waiting.push({refused:record.data});}}
catch(e){Ext.log(e);}},this);if(this.tdatas.waiting.length===0){}
Ext.get(this.displayTarget).update(this.tpl.expand(this.tdatas));setMPActions(this.displayTarget);this.tdatas=[];}}},_exceptionHandler:function(dataProxy,type,action,options,response,arg){var i,t,records;if(type=='remote'&&action=='read'){this.store_error=true;this.fireEvent('datachanged',this);this.fireEvent('readerror',this);}
else
if(type=='remote'&&action=='update'){t=response.getTransaction();records=this._recordsFromTransaction(t);for(i=0;i<records.length;i++){records[i].reject(true);}
for(i=0;i<records.length;i++){this.fireEvent('updatecanceled',this,records[i]);}
this.fireEvent('datachanged',this);Ext.log('updatecanceled');}
else
if(type=='remote'&&action=='destroy'){t=response.getTransaction();records=this._recordsFromTransaction(t);this.suspendEvents();for(i=0;i<records.length;i++){GFactory.UserContribStore.superclass.addSorted.call(this,records[i]);}
this.resumeEvents();for(i=0;i<records.length;i++){this.fireEvent('destroycanceled',this,records[i]);Ext.log('destroycanceled '+i);}
this.fireEvent('datachanged',this);Ext.log('destroycanceled');}
else
if(type=='remote'&&action=='create'){t=response.getTransaction();records=this._recordsFromTransaction(t);this.suspendEvents();for(i=0;i<records.length;i++){this.remove(records[i]);}
this.resumeEvents();for(i=0;i<records.length;i++){this.fireEvent('createcanceled',this,records[i]);}
this.fireEvent('datachanged',this);Ext.log('createcanceled');}}});
