[js utils] backport some generic code from comments cube
to handle inline ajax form as you get to add comment to entities.
Following stuff has been generalized and backported to ease such things:
* lazy_view_holder() method on EntityCtxComponent class, to build
place holder where the form will be inserted
* ajax_composite_form() function in cw.web.views.ajaxedit, to build
the form itself
* reload() and reloadCtxComponentsSection() javascript function in
cubicweb.ajax.js for the javascript processing side
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr## This file is part of CubicWeb.## CubicWeb is free software: you can redistribute it and/or modify it under the# terms of the GNU Lesser General Public License as published by the Free# Software Foundation, either version 2.1 of the License, or (at your option)# any later version.## CubicWeb is distributed in the hope that it will be useful, but WITHOUT# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more# details.## You should have received a copy of the GNU Lesser General Public License along# with CubicWeb. If not, see <http://www.gnu.org/licenses/>."""Some views used to help to the edition process"""__docformat__="restructuredtext en"_=unicodefromlogilab.common.decoratorsimportcachedfromlogilab.mtconverterimportxml_escapefromcubicwebimporttyped_eidfromcubicweb.viewimportEntityView,StartupViewfromcubicweb.selectorsimport(one_line_rset,non_final_entity,match_search_state)fromcubicweb.webimporthttpcachefromcubicweb.web.viewsimportbaseviews,linksearch_select_urlclassSearchForAssociationView(EntityView):"""view called by the edition view when the user asks to search for something to link to the edited eid """__regid__='search-associate'__select__=(one_line_rset()&match_search_state('linksearch')&non_final_entity())title=_('search for association')defcell_call(self,row,col):rset,vid,divid,paginate=self.filter_box_context_info()self.cw_rset=rsetself.w(u'<div id="%s">'%divid)self.paginate()self.wview(vid,rset,'noresult')self.w(u'</div>')@cacheddeffilter_box_context_info(self):entity=self.cw_rset.get_entity(0,0)role,eid,rtype,etype=self._cw.search_state[1]assertentity.eid==typed_eid(eid)# the default behaviour is to fetch all unrelated entities and display# them. Use fetch_order and not fetch_unrelated_order as sort method# since the latter is mainly there to select relevant items in the combo# box, it doesn't give interesting result in this contextrql,args=entity.cw_unrelated_rql(rtype,etype,role,ordermethod='fetch_order',vocabconstraints=False)rset=self._cw.execute(rql,args)returnrset,'list',"search-associate-content",TrueclassOutOfContextSearch(EntityView):__regid__='outofcontext-search'defcell_call(self,row,col):entity=self.cw_rset.get_entity(row,col)erset=entity.as_rset()ifself._cw.match_search_state(erset):self.w(u'<a href="%s" title="%s">%s</a> <a href="%s" title="%s">[...]</a>'%(xml_escape(linksearch_select_url(self._cw,erset)),self._cw._('select this entity'),xml_escape(entity.view('textoutofcontext')),xml_escape(entity.absolute_url(vid='primary')),self._cw._('view detail for this entity')))else:entity.view('outofcontext',w=self.w)classComboboxView(EntityView):"""the view used in combobox (unrelated entities) THIS IS A TEXT VIEW. DO NOT HTML_ESCAPE """__regid__='combobox'title=Nonedefcell_call(self,row,col,**kwargs):"""the combo-box view for an entity: same as text out of context view by default """self.wview('textoutofcontext',self.cw_rset,row=row,col=col)classEditableFinalView(baseviews.FinalView):"""same as FinalView but enables inplace-edition when possible"""__regid__='editable-final'defcell_call(self,row,col,props=None):entity,rtype=self.cw_rset.related_entity(row,col)ifentityisnotNone:self.w(entity.view('reledit',rtype=rtype))else:super(EditableFinalView,self).cell_call(row,col,props)try:fromcubicweb.webimportcaptchaexceptImportError:# PIL not installedpasselse:classCaptchaView(StartupView):__regid__='captcha'http_cache_manager=httpcache.NoHTTPCacheManagerbinary=Truetemplatable=Falsecontent_type='image/jpg'defcall(self):text,data=captcha.captcha(self._cw.vreg.config['captcha-font-file'],self._cw.vreg.config['captcha-font-size'])key=self._cw.form.get('captchakey','captcha')self._cw.session.data[key]=textself.w(data.read())