Changeset 1188

Show
Ignore:
Timestamp:
07/29/08 07:18:47
Author:
piv
Message:

ajax: delete updated

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • qPloneTabs/branches/quintagroup.plonetabs/trunk/quintagroup/plonetabs/browser/plonetabs.py

    r1186 r1188  
    4242    # custom templates used to update page sections 
    4343    sections_template = ViewPageTemplateFile("templates/sections.pt") 
     44     
     45    # configuration variables 
     46    prefix = "tabslist_" 
     47    sufix = "" 
    4448     
    4549    def __call__(self): 
     
    367371    ########################## 
    368372     
    369     def validateAction(self, id, category, prefix="tabslist_"): 
    370         """ If action with given id and category doesn't exist - raise kss exception """ 
    371         portal_actions = getToolByName(self.context, "portal_actions") 
    372          
    373         # remove prefix, added for making ids on configlet unique ("tabslist_") 
    374         act_id = id[len("tabslist_"):] 
    375          
    376         if category not in portal_actions.objectIds(): 
    377             raise KSSExplicitError, "Unexistent root portal actions category %s" % category 
    378          
    379         cat_container = portal_actions[category] 
    380         if act_id not in map(lambda x: x.id, filter(lambda x: IAction.providedBy(x), cat_container.objectValues())): 
    381             raise KSSExplicitError, "%s action does not exist in %s category" % (act_id, category) 
    382          
    383         return (cat_container, act_id) 
    384      
    385373    @kssaction 
    386374    def toggleGeneratedTabs(self, field, checked='0'): 
     
    421409            ksscore.addClass(ksscore.getHtmlIdSelector(id), value="invisible") 
    422410         
    423         self.updatePage(category
     411        self.updatePage(cat_name
    424412     
    425413    @kssaction 
     
    451439     
    452440    @kssaction 
    453     def kss_deleteAction(self, id, category): 
     441    def kss_deleteAction(self, id, cat_name): 
    454442        """ Delete portal action with given id & category """ 
    455         portal_actions = getToolByName(self.context, "portal_actions") 
    456         cat_container, act_id = self.validateAction(id, category) 
    457          
    458         cat_container.manage_delObjects(ids=[act_id,]) 
    459          
    460         # update action list on client 
     443        # validate input 
     444        act_id, category, action = self.kss_validateAction(id, cat_name) 
     445        self.deleteAction(act_id, cat_name) 
     446         
     447        # update client 
    461448        ksscore = self.getCommandSet("core") 
    462          
    463449        ksscore.deleteNode(ksscore.getHtmlIdSelector(id)) 
    464          
    465         # add "noitems" class to Reorder controls to hide it 
    466         if not filter(lambda x: IAction.providedBy(x), cat_container.objectValues()): 
    467             ksscore.addClass(ksscore.getHtmlIdSelector("reorder"), value="noitems") 
    468          
     450        self.kss_checkReorderControls(category) 
    469451        # XXX TODO: fade effect during removing, for this kukit js action/command plugin needed 
    470          
    471         self.updatePage(category) 
     452        self.updatePage(cat_name) 
    472453     
    473454    @kssaction 
     
    617598        site_properties.manage_changeProperties(**kw) 
    618599        return True 
     600     
     601    # 
     602    # Utility methods for the kss actions management 
     603    # 
     604     
     605    def kss_checkReorderControls(self, category): 
     606        """ Add "noitems" class to Reorder controls to hide them if category is empty """ 
     607        if not filter(lambda x: IAction.providedBy(x), category.objectValues()): 
     608            ksscore = self.getCommandSet('core') 
     609            ksscore.addClass(ksscore.getHtmlIdSelector("reorder"), value="noitems") 
     610     
     611    def kss_validateAction(self, id, cat_name): 
     612        """ Check whether action with given id exists in cat_name category """ 
     613        try: 
     614            category = self.getActionCategory(cat_name) 
     615        except Exception: 
     616            raise KSSExplicitError, "'%s' action category does not exist" % cat_name 
     617         
     618        # extract action id from given list item id on client 
     619        action_id = self.sufix and id[len(self.prefix):-len(self.sufix)] or id[len(self.prefix):] 
     620        try: 
     621            action = category[action_id] 
     622        except Exception: 
     623            raise KSSExplicitError, "No '%s' action in '%s' category." % (action_id, cat_name) 
     624         
     625        return (action_id, category, action) 
     626     
     627    def validateAction(self, id, category, prefix="tabslist_"): 
     628        """ If action with given id and category doesn't exist - raise kss exception """ 
     629        portal_actions = getToolByName(self.context, "portal_actions") 
     630         
     631        # remove prefix, added for making ids on configlet unique self.prefix 
     632        act_id = id[len(self.prefix):] 
     633         
     634        if category not in portal_actions.objectIds(): 
     635            raise KSSExplicitError, "Unexistent root portal actions category %s" % category 
     636         
     637        cat_container = portal_actions[category] 
     638        if act_id not in map(lambda x: x.id, filter(lambda x: IAction.providedBy(x), cat_container.objectValues())): 
     639            raise KSSExplicitError, "%s action does not exist in %s category" % (act_id, category) 
     640         
     641        return (cat_container, act_id) 
    619642     
    620643    # 
  • qPloneTabs/branches/quintagroup.plonetabs/trunk/quintagroup/plonetabs/browser/resources/plonetabs.kss

    r1174 r1188  
    7272    action-server: plonetabs-deleteAction; 
    7373    plonetabs-deleteAction-id: nodeAttr(id, true); 
    74     plonetabs-deleteAction-category: stateVar(plonetabs-category); 
     74    plonetabs-deleteAction-cat_name: stateVar(plonetabs-category); 
     75    plonetabs-deleteAction-error: plonetabs-handleServerError; 
    7576} 
    7677 
  • qPloneTabs/branches/quintagroup.plonetabs/trunk/quintagroup/plonetabs/browser/templates/actionslist.pt

    r1179 r1188  
    99                klass python:test(visible, [], ['invisible']); 
    1010                klass python:test(editing, klass + ['editing'], klass)" 
    11     tal:attributes="id string:tabslist_${id}; 
     11    tal:attributes="id string:${view/prefix}${id}; 
    1212                    title tab/description; 
    1313                    class python:' '.join(klass)"> 
    1414 
    1515  <img class="drag-handle" src="++resource++drag.gif" alt="" height="11" width="25" /> 
    16  
    17   <a class="delete" href="#" 
    18      tal:attributes="href string:${context/portal_url}/@@plonetabs-controlpanel?action=delete_action&category=${category}&id=${id}">Delete</a> 
     16  <a class="delete" href="#">Delete</a> 
    1917 
    2018  <span class="url-helper" tal:content="tab/url_expr">Tab Action</span> 
  • qPloneTabs/branches/quintagroup.plonetabs/trunk/quintagroup/plonetabs/plugins/configure.zcml

    r1174 r1188  
    2424        params_optional="collapsed expanded" 
    2525        /> 
     26 
     27    <kss:action 
     28        name="plonetabs-handleServerError" 
     29        jsfile="plugin.js" 
     30        params_mandatory="" 
     31        params_optional="message" 
     32        />         
    2633     
    2734</configure> 
  • qPloneTabs/branches/quintagroup.plonetabs/trunk/quintagroup/plonetabs/plugins/plugin.js

    r1174 r1188  
    5858kukit.commandsGlobalRegistry.registerFromAction("plonetabs-toggleCollapsible", kukit.cr.makeSelectorCommand); 
    5959 
    60  
     60kukit.actionsGlobalRegistry.register("plonetabs-handleServerError", function(oper) { 
     61    oper.componentName = "[plonetabs-handleServerError] action"; 
     62    oper.evaluateParameters([], {"message" : kukit.E}); 
     63    alert(oper.parms.message); 
     64});