[159] | 1 | import urllib |
---|
[161] | 2 | import re |
---|
[159] | 3 | |
---|
[45] | 4 | from Acquisition import aq_inner |
---|
| 5 | |
---|
[43] | 6 | from zope.interface import implements |
---|
[507] | 7 | from zope.component import getMultiAdapter |
---|
[135] | 8 | from zope.app.container.interfaces import INameChooser |
---|
[175] | 9 | from zope.viewlet.interfaces import IViewletManager, IViewlet |
---|
[43] | 10 | |
---|
[507] | 11 | from plone.app.layout.navigation.root import getNavigationRoot |
---|
| 12 | from plone.app.kss.plonekssview import PloneKSSView |
---|
| 13 | from kss.core import kssaction, KSSExplicitError |
---|
| 14 | |
---|
[43] | 15 | from Products.CMFCore.utils import getToolByName |
---|
[53] | 16 | from Products.CMFCore.interfaces import IAction, IActionCategory |
---|
| 17 | from Products.CMFCore.ActionInformation import Action, ActionCategory |
---|
[55] | 18 | from Products.CMFCore.Expression import Expression |
---|
[43] | 19 | from Products.CMFPlone import PloneMessageFactory as _ |
---|
| 20 | from Products.CMFPlone import utils |
---|
| 21 | from Products.CMFPlone.browser.navigation import get_view_url |
---|
| 22 | from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile |
---|
[53] | 23 | from Products.statusmessages.interfaces import IStatusMessage |
---|
[43] | 24 | |
---|
| 25 | from quintagroup.plonetabs.config import * |
---|
| 26 | from interfaces import IPloneTabsControlPanel |
---|
| 27 | |
---|
[138] | 28 | ACTION_ATTRS = ["id", "title", "url_expr", "available_expr", "visible"] |
---|
[151] | 29 | UI_ATTRS = {"id": "id", |
---|
| 30 | "title": "name", |
---|
| 31 | "url_expr": "action", |
---|
| 32 | "available_expr": "condition", |
---|
| 33 | "visible": "visible"} |
---|
[43] | 34 | |
---|
[159] | 35 | bad_id = re.compile(r'[^a-zA-Z0-9-_~,.$\(\)# @]').search |
---|
| 36 | |
---|
[43] | 37 | class PloneTabsControlPanel(PloneKSSView): |
---|
| 38 | |
---|
| 39 | implements(IPloneTabsControlPanel) |
---|
| 40 | |
---|
[53] | 41 | template = ViewPageTemplateFile("templates/plonetabs.pt") |
---|
[43] | 42 | actionslist_template = ViewPageTemplateFile("templates/actionslist.pt") |
---|
| 43 | autogenerated_template = ViewPageTemplateFile("templates/autogenerated.pt") |
---|
[162] | 44 | autogenerated_list = ViewPageTemplateFile("templates/autogeneratedlist.pt") |
---|
[135] | 45 | |
---|
| 46 | # custom templates used to update page sections |
---|
[46] | 47 | sections_template = ViewPageTemplateFile("templates/sections.pt") |
---|
[43] | 48 | |
---|
[149] | 49 | # configuration variables |
---|
| 50 | prefix = "tabslist_" |
---|
| 51 | sufix = "" |
---|
| 52 | |
---|
[53] | 53 | def __call__(self): |
---|
| 54 | """ Perform the update and redirect if necessary, or render the page """ |
---|
| 55 | postback = True |
---|
| 56 | errors = {} |
---|
| 57 | context = aq_inner(self.context) |
---|
| 58 | |
---|
| 59 | form = self.request.form |
---|
| 60 | action = form.get("action", "") |
---|
| 61 | submitted = form.get('form.submitted', False) |
---|
| 62 | |
---|
| 63 | # action handler def handler(self, form) |
---|
[135] | 64 | if submitted: |
---|
| 65 | if form.has_key('add.add'): |
---|
[53] | 66 | postback = self.manage_addAction(form, errors) |
---|
[135] | 67 | elif form.has_key("edit.save"): |
---|
[55] | 68 | postback = self.manage_editAction(form, errors) |
---|
[135] | 69 | elif form.has_key("edit.delete"): |
---|
| 70 | postback = self.manage_deleteAction(form, errors) |
---|
| 71 | elif form.has_key("edit.moveup"): |
---|
| 72 | postback = self.manage_moveUpAction(form, errors) |
---|
| 73 | elif form.has_key("edit.movedown"): |
---|
| 74 | postback = self.manage_moveDownAction(form, errors) |
---|
| 75 | elif form.has_key("autogenerated.save"): |
---|
[53] | 76 | postback = self.manage_setAutogeneration(form, errors) |
---|
[135] | 77 | else: |
---|
| 78 | postback = True |
---|
[53] | 79 | |
---|
| 80 | if postback: |
---|
| 81 | return self.template(errors=errors) |
---|
| 82 | |
---|
| 83 | ######################################## |
---|
| 84 | # Methods for processing configlet posts |
---|
| 85 | ######################################## |
---|
| 86 | |
---|
| 87 | def manage_setAutogeneration(self, form, errors): |
---|
| 88 | """ Process managing autogeneration settings """ |
---|
| 89 | |
---|
| 90 | # set excludeFromNav property for root objects |
---|
| 91 | portal = getMultiAdapter((aq_inner(self.context), self.request), name='plone_portal_state').portal() |
---|
| 92 | generated_tabs = form.get("generated_tabs", '0') |
---|
| 93 | nonfolderish_tabs = form.get("nonfolderish_tabs", '0') |
---|
| 94 | |
---|
| 95 | for item in self.getRootTabs(): |
---|
| 96 | obj = getattr(portal, item['id'], None) |
---|
| 97 | if obj is not None: |
---|
| 98 | checked = form.get(item['id'], None) |
---|
| 99 | if checked == '1': |
---|
| 100 | obj.update(excludeFromNav=False) |
---|
| 101 | else: |
---|
| 102 | obj.update(excludeFromNav=True) |
---|
| 103 | |
---|
| 104 | # set disable_folder_sections property |
---|
| 105 | if int(generated_tabs) == 1: |
---|
[146] | 106 | self.setSiteProperties(disable_folder_sections=False) |
---|
[53] | 107 | else: |
---|
[146] | 108 | self.setSiteProperties(disable_folder_sections=True) |
---|
[53] | 109 | |
---|
| 110 | # set disable_nonfolderish_sections property |
---|
| 111 | if int(nonfolderish_tabs) == 1: |
---|
[146] | 112 | self.setSiteProperties(disable_nonfolderish_sections=False) |
---|
[53] | 113 | else: |
---|
[146] | 114 | self.setSiteProperties(disable_nonfolderish_sections=True) |
---|
[53] | 115 | |
---|
[146] | 116 | # after successfull form processing make redirect with good message |
---|
[54] | 117 | IStatusMessage(self.request).addStatusMessage(_(u"Changes saved!"), type="info") |
---|
[53] | 118 | self.redirect() |
---|
| 119 | return False |
---|
| 120 | |
---|
[135] | 121 | def manage_addAction(self, form, errs): |
---|
[138] | 122 | """ Manage method to add a new action to given category, |
---|
| 123 | if category doesn't exist, create it """ |
---|
[139] | 124 | # extract posted data |
---|
| 125 | id, cat_name, data = self.parseAddForm(form) |
---|
[53] | 126 | |
---|
[138] | 127 | # validate posted data |
---|
[139] | 128 | errors = self.validateActionFields(cat_name, data) |
---|
[53] | 129 | |
---|
| 130 | # if not errors find (or create) category and set action to it |
---|
| 131 | if not errors: |
---|
[151] | 132 | action = self.addAction(cat_name, data) |
---|
[135] | 133 | IStatusMessage(self.request).addStatusMessage(_(u"'%s' action successfully added." % action.id), type="info") |
---|
| 134 | self.redirect(search="category=%s" % cat_name) |
---|
[53] | 135 | return False |
---|
| 136 | else: |
---|
[135] | 137 | errs.update(errors) |
---|
[53] | 138 | IStatusMessage(self.request).addStatusMessage(_(u"Please correct the indicated errors."), type="error") |
---|
| 139 | return True |
---|
| 140 | |
---|
[135] | 141 | def manage_editAction(self, form, errs): |
---|
[138] | 142 | """ Manage Method to update action """ |
---|
| 143 | # extract posted data |
---|
[139] | 144 | id, cat_name, data = self.parseEditForm(form) |
---|
[55] | 145 | |
---|
[138] | 146 | # get category and action to edit |
---|
| 147 | category = self.getActionCategory(cat_name) |
---|
| 148 | action = category[id] |
---|
[55] | 149 | |
---|
[138] | 150 | # validate posted data |
---|
[165] | 151 | errors = self.validateActionFields(cat_name, data, allow_dup=(id == data['id'])) |
---|
[138] | 152 | |
---|
| 153 | if not errors: |
---|
| 154 | action = self.updateAction(id, cat_name, data) |
---|
| 155 | IStatusMessage(self.request).addStatusMessage(_(u"'%s' action saved." % action.id), type="info") |
---|
| 156 | self.redirect(search="category=%s" % cat_name) |
---|
| 157 | return False |
---|
[55] | 158 | else: |
---|
[138] | 159 | errs.update(self.processErrors(errors, sufix='_%s' % id)) # add edit form sufix to error ids |
---|
| 160 | IStatusMessage(self.request).addStatusMessage(_(u"Please correct the indicated errors."), type="error") |
---|
| 161 | return True |
---|
[55] | 162 | |
---|
[138] | 163 | def manage_deleteAction(self, form, errs): |
---|
| 164 | """ Manage Method to delete action """ |
---|
| 165 | # extract posted data |
---|
[139] | 166 | id, cat_name, data = self.parseEditForm(form) |
---|
[53] | 167 | |
---|
[138] | 168 | # get category and action to delete |
---|
| 169 | category = self.getActionCategory(cat_name) |
---|
| 170 | if id in category.objectIds(): |
---|
| 171 | self.deleteAction(id, cat_name) |
---|
[141] | 172 | IStatusMessage(self.request).addStatusMessage(_(u"'%s' action deleted." % id), type="info") |
---|
[138] | 173 | self.redirect(search="category=%s" % cat_name) |
---|
| 174 | return False |
---|
[53] | 175 | else: |
---|
[138] | 176 | IStatusMessage(self.request).addStatusMessage(_(u"No '%s' action in '%s' category." % (id, cat_name)), type="error") |
---|
| 177 | return True |
---|
[53] | 178 | |
---|
[141] | 179 | def manage_moveUpAction(self, form, errs): |
---|
| 180 | """ Manage Method for moving up given action by one position """ |
---|
| 181 | # extract posted data |
---|
| 182 | id, cat_name, data = self.parseEditForm(form) |
---|
[54] | 183 | |
---|
[141] | 184 | # get category and action to move |
---|
| 185 | category = self.getActionCategory(cat_name) |
---|
| 186 | if id in category.objectIds(): |
---|
| 187 | self.moveAction(id, cat_name, steps=1) |
---|
| 188 | IStatusMessage(self.request).addStatusMessage(_(u"'%s' action moved up." % id), type="info") |
---|
| 189 | self.redirect(search="category=%s" % cat_name) |
---|
| 190 | return False |
---|
[54] | 191 | else: |
---|
[141] | 192 | IStatusMessage(self.request).addStatusMessage(_(u"No '%s' action in '%s' category." % (id, cat_name)), type="error") |
---|
| 193 | return True |
---|
[54] | 194 | |
---|
[141] | 195 | def manage_moveDownAction(self, form, errs): |
---|
| 196 | """ Manage Method for moving down given action by one position """ |
---|
| 197 | # extract posted data |
---|
| 198 | id, cat_name, data = self.parseEditForm(form) |
---|
[54] | 199 | |
---|
[141] | 200 | # get category and action to move |
---|
| 201 | category = self.getActionCategory(cat_name) |
---|
| 202 | if id in category.objectIds(): |
---|
| 203 | self.moveAction(id, cat_name, steps=-1) |
---|
| 204 | IStatusMessage(self.request).addStatusMessage(_(u"'%s' action moved down." % id), type="info") |
---|
| 205 | self.redirect(search="category=%s" % cat_name) |
---|
| 206 | return False |
---|
[54] | 207 | else: |
---|
[141] | 208 | IStatusMessage(self.request).addStatusMessage(_(u"No '%s' action in '%s' category." % (id, cat_name)), type="error") |
---|
| 209 | return True |
---|
[54] | 210 | |
---|
[147] | 211 | def redirect(self, url="", search="", url_hash=""): |
---|
[53] | 212 | """ Redirect to @@plonetabs-controlpanel configlet """ |
---|
[147] | 213 | portal_url = getMultiAdapter((self.context, self.request), name=u"plone_portal_state").portal_url() |
---|
| 214 | url = (url == "") and "%s/%s" % (portal_url, "@@plonetabs-controlpanel") or url |
---|
| 215 | search = (search != "") and "?%s" % search or search |
---|
| 216 | url_hash = (url_hash != "") and "#%s" % url_hash or url_hash |
---|
| 217 | self.request.response.redirect("%s%s%s" % (url, search, url_hash)) |
---|
[53] | 218 | |
---|
| 219 | ################################### |
---|
[138] | 220 | # |
---|
| 221 | # Methods - providers for templates |
---|
| 222 | # |
---|
[53] | 223 | ################################### |
---|
| 224 | |
---|
[43] | 225 | def getPageTitle(self, category="portal_tabs"): |
---|
| 226 | """ See interface """ |
---|
| 227 | portal_props = getToolByName(self.context, "portal_properties") |
---|
| 228 | default_title = "Plone '%s' Configuration" % category |
---|
| 229 | |
---|
| 230 | if not hasattr(portal_props, PROPERTY_SHEET): |
---|
| 231 | return default_title |
---|
| 232 | |
---|
| 233 | sheet = getattr(portal_props, PROPERTY_SHEET) |
---|
| 234 | if not hasattr(sheet, FIELD_NAME): |
---|
| 235 | return default_title |
---|
| 236 | |
---|
| 237 | field = sheet.getProperty(FIELD_NAME) |
---|
| 238 | dict = {} |
---|
| 239 | for line in field: |
---|
| 240 | cat, title = line.split("|", 2) |
---|
| 241 | dict[cat] = title |
---|
| 242 | |
---|
| 243 | return dict.get(category, None) or default_title |
---|
| 244 | |
---|
| 245 | def hasActions(self, category="portal_tabs"): |
---|
| 246 | """ See interface """ |
---|
| 247 | return len(getToolByName(self.context, "portal_actions").listActions(categories=[category,])) > 0 |
---|
| 248 | |
---|
| 249 | def getPortalActions(self, category="portal_tabs"): |
---|
| 250 | """ See interface """ |
---|
[45] | 251 | portal_actions = getToolByName(self.context, "portal_actions") |
---|
| 252 | |
---|
| 253 | if category not in portal_actions.objectIds(): |
---|
| 254 | return [] |
---|
| 255 | |
---|
| 256 | actions = [] |
---|
| 257 | for item in portal_actions[category].objectValues(): |
---|
| 258 | if IAction.providedBy(item): |
---|
| 259 | actions.append(item) |
---|
| 260 | |
---|
| 261 | return actions |
---|
[43] | 262 | |
---|
| 263 | def isGeneratedTabs(self): |
---|
| 264 | """ See interface """ |
---|
| 265 | site_properties = getToolByName(self.context, "portal_properties").site_properties |
---|
| 266 | return not site_properties.getProperty("disable_folder_sections", False) |
---|
| 267 | |
---|
| 268 | def isNotFoldersGenerated(self): |
---|
| 269 | """ See interface """ |
---|
| 270 | site_properties = getToolByName(self.context, "portal_properties").site_properties |
---|
| 271 | return not site_properties.getProperty("disable_nonfolderish_sections", False) |
---|
| 272 | |
---|
[151] | 273 | def getActionsList(self, category="portal_tabs", errors={}, tabs=[]): |
---|
[43] | 274 | """ See interface """ |
---|
[151] | 275 | kw = {'category': category, 'errors': errors} |
---|
| 276 | if tabs: |
---|
| 277 | kw['tabs'] = tabs |
---|
| 278 | return self.actionslist_template(**kw) |
---|
[43] | 279 | |
---|
[162] | 280 | def getAutoGenereatedSection(self, cat_name, errors={}): |
---|
| 281 | """ See interface """ |
---|
| 282 | return self.autogenerated_template(category=cat_name, errors=errors) |
---|
| 283 | |
---|
[43] | 284 | def getGeneratedTabs(self): |
---|
| 285 | """ See interface """ |
---|
[162] | 286 | return self.autogenerated_list() |
---|
[43] | 287 | |
---|
| 288 | def getRootTabs(self): |
---|
| 289 | """ See interface """ |
---|
| 290 | context = aq_inner(self.context) |
---|
| 291 | |
---|
| 292 | portal_catalog = getToolByName(context, 'portal_catalog') |
---|
| 293 | portal_properties = getToolByName(context, 'portal_properties') |
---|
| 294 | navtree_properties = getattr(portal_properties, 'navtree_properties') |
---|
| 295 | |
---|
| 296 | # Build result dict |
---|
| 297 | result = [] |
---|
| 298 | |
---|
[147] | 299 | # check whether tabs autogeneration is turned on |
---|
[43] | 300 | if not self.isGeneratedTabs(): |
---|
| 301 | return result |
---|
| 302 | |
---|
| 303 | query = {} |
---|
| 304 | rootPath = getNavigationRoot(context) |
---|
| 305 | query['path'] = {'query' : rootPath, 'depth' : 1} |
---|
| 306 | query['portal_type'] = utils.typesToList(context) |
---|
| 307 | |
---|
| 308 | sortAttribute = navtree_properties.getProperty('sortAttribute', None) |
---|
| 309 | if sortAttribute is not None: |
---|
| 310 | query['sort_on'] = sortAttribute |
---|
| 311 | |
---|
| 312 | sortOrder = navtree_properties.getProperty('sortOrder', None) |
---|
| 313 | if sortOrder is not None: |
---|
| 314 | query['sort_order'] = sortOrder |
---|
| 315 | |
---|
| 316 | if navtree_properties.getProperty('enable_wf_state_filtering', False): |
---|
| 317 | query['review_state'] = navtree_properties.getProperty('wf_states_to_show', []) |
---|
| 318 | |
---|
| 319 | query['is_default_page'] = False |
---|
| 320 | |
---|
| 321 | if not self.isNotFoldersGenerated(): |
---|
| 322 | query['is_folderish'] = True |
---|
| 323 | |
---|
| 324 | # Get ids not to list and make a dict to make the search fast |
---|
| 325 | idsNotToList = navtree_properties.getProperty('idsNotToList', ()) |
---|
| 326 | excludedIds = {} |
---|
| 327 | for id in idsNotToList: |
---|
| 328 | excludedIds[id]=1 |
---|
| 329 | |
---|
| 330 | rawresult = portal_catalog.searchResults(**query) |
---|
| 331 | |
---|
| 332 | # now add the content to results |
---|
| 333 | for item in rawresult: |
---|
| 334 | if not excludedIds.has_key(item.getId): |
---|
| 335 | id, item_url = get_view_url(item) |
---|
| 336 | data = {'name' : utils.pretty_title_or_id(context, item), |
---|
| 337 | 'id' : id, |
---|
| 338 | 'url' : item_url, |
---|
| 339 | 'description': item.Description, |
---|
| 340 | 'exclude_from_nav' : item.exclude_from_nav} |
---|
| 341 | result.append(data) |
---|
| 342 | |
---|
| 343 | return result |
---|
| 344 | |
---|
| 345 | def getCategories(self): |
---|
| 346 | """ See interface """ |
---|
| 347 | portal_actions = getToolByName(self.context, "portal_actions") |
---|
| 348 | return portal_actions.objectIds() |
---|
| 349 | |
---|
[138] | 350 | # |
---|
| 351 | # Methods to make this class looks like global sections viewlet |
---|
| 352 | # |
---|
| 353 | |
---|
[43] | 354 | def test(self, condition, ifTrue, ifFalse): |
---|
| 355 | """ See interface """ |
---|
| 356 | if condition: |
---|
| 357 | return ifTrue |
---|
| 358 | else: |
---|
| 359 | return ifFalse |
---|
| 360 | |
---|
[46] | 361 | # methods for rendering global-sections viewlet via kss, |
---|
| 362 | # due to bug in macroContent when global-section list is empty, |
---|
| 363 | # ul have condition |
---|
| 364 | def portal_tabs(self): |
---|
| 365 | """ See global-sections viewlet """ |
---|
| 366 | actions = context_state = getMultiAdapter((self.context, self.request), name=u"plone_context_state").actions() |
---|
| 367 | portal_tabs_view = getMultiAdapter((self.context, self.request), name="portal_tabs_view") |
---|
| 368 | |
---|
| 369 | return portal_tabs_view.topLevelTabs(actions=actions) |
---|
| 370 | |
---|
| 371 | def selected_portal_tab(self): |
---|
| 372 | """ See global-sections viewlet """ |
---|
| 373 | selectedTabs = self.context.restrictedTraverse('selectedTabs') |
---|
| 374 | selected_tabs = selectedTabs('index_html', self.context, self.portal_tabs()) |
---|
| 375 | |
---|
| 376 | return selected_tabs['portal'] |
---|
| 377 | |
---|
[43] | 378 | ########################## |
---|
[138] | 379 | # |
---|
| 380 | # KSS Server Actions |
---|
| 381 | # |
---|
[43] | 382 | ########################## |
---|
| 383 | |
---|
[478] | 384 | @kssaction |
---|
[162] | 385 | def kss_changeCategory(self, cat_name): |
---|
| 386 | """ Change action category to manage """ |
---|
| 387 | ksscore = self.getCommandSet('core') |
---|
| 388 | |
---|
| 389 | # update actions list |
---|
| 390 | actionslist = self.getActionsList(category=cat_name) |
---|
| 391 | ksscore.replaceInnerHTML(ksscore.getHtmlIdSelector('tabslist'), actionslist) |
---|
| 392 | |
---|
| 393 | # update autogenerated sections |
---|
| 394 | section = self.getAutoGenereatedSection(cat_name) |
---|
| 395 | ksscore.replaceHTML(ksscore.getHtmlIdSelector('autogeneration_section'), section) |
---|
[507] | 396 | # and title |
---|
| 397 | ksscore.replaceInnerHTML(ksscore.getHtmlIdSelector('plonetabs-form-title'), |
---|
| 398 | self.getPageTitle(cat_name)) |
---|
[162] | 399 | |
---|
| 400 | # update category hidden field on adding form |
---|
| 401 | ksscore.setAttribute(ksscore.getCssSelector('#addaction input[name=category]'), 'value', cat_name) |
---|
| 402 | |
---|
| 403 | # update state variable 'plonetabs-category' on client |
---|
| 404 | ksscore.setStateVar('plonetabs-category', cat_name) |
---|
[478] | 405 | |
---|
| 406 | # hide portal status message |
---|
[507] | 407 | self.kss_hideStatusMessage(ksscore) |
---|
| 408 | |
---|
| 409 | # hide adding form |
---|
| 410 | self.kss_hideAddForm() |
---|
[162] | 411 | |
---|
[43] | 412 | @kssaction |
---|
[151] | 413 | def kss_toggleGeneratedTabs(self, field, checked='0'): |
---|
[43] | 414 | """ Toggle autogenaration setting on configlet """ |
---|
[45] | 415 | if checked == '1': |
---|
[161] | 416 | self.setSiteProperties(**{field: False}) |
---|
[43] | 417 | else: |
---|
[161] | 418 | self.setSiteProperties(**{field: True}) |
---|
[43] | 419 | |
---|
[161] | 420 | # update client |
---|
[43] | 421 | ksscore = self.getCommandSet("core") |
---|
| 422 | content = self.getGeneratedTabs() |
---|
[161] | 423 | ksscore.replaceInnerHTML(ksscore.getHtmlIdSelector('roottabs'), content) |
---|
[43] | 424 | |
---|
[45] | 425 | # update global-sections viewlet |
---|
[161] | 426 | self.updatePortalTabsPageSection() |
---|
[45] | 427 | |
---|
| 428 | @kssaction |
---|
[151] | 429 | def kss_toggleRootsVisibility(self, id, checked='0'): |
---|
[45] | 430 | """ Toggle visibility for portal root objects (exclude_from_nav) """ |
---|
| 431 | portal = getMultiAdapter((aq_inner(self.context), self.request), name='plone_portal_state').portal() |
---|
| 432 | |
---|
| 433 | # remove prefix, added for making ids on configlet unique ("roottabs_") |
---|
| 434 | obj_id = id[len("roottabs_"):] |
---|
| 435 | |
---|
| 436 | if obj_id not in portal.objectIds(): |
---|
| 437 | raise KSSExplicitError, "Object with %s id doesn't exist in portal root" % obj_id |
---|
| 438 | |
---|
| 439 | if checked == '1': |
---|
| 440 | checked = True |
---|
| 441 | else: |
---|
| 442 | checked = False |
---|
| 443 | |
---|
| 444 | portal[obj_id].update(excludeFromNav=not checked) |
---|
| 445 | |
---|
[161] | 446 | # update client |
---|
[45] | 447 | ksscore = self.getCommandSet("core") |
---|
| 448 | if checked: |
---|
| 449 | ksscore.removeClass(ksscore.getHtmlIdSelector(id), value="invisible") |
---|
| 450 | else: |
---|
| 451 | ksscore.addClass(ksscore.getHtmlIdSelector(id), value="invisible") |
---|
| 452 | |
---|
| 453 | # update global-sections viewlet |
---|
[161] | 454 | self.updatePortalTabsPageSection() |
---|
[45] | 455 | |
---|
[47] | 456 | @kssaction |
---|
[150] | 457 | def kss_toggleActionsVisibility(self, id, checked='0', cat_name=None): |
---|
| 458 | """ Toggle visibility for portal actions """ |
---|
| 459 | # validate input |
---|
| 460 | act_id, category, action = self.kss_validateAction(id, cat_name) |
---|
| 461 | self.updateAction(act_id, cat_name, {'id': act_id, 'visible': (checked == '1') or False}) |
---|
| 462 | |
---|
| 463 | # update client |
---|
| 464 | ksscore = self.getCommandSet("core") |
---|
[151] | 465 | if checked == '1': |
---|
| 466 | ksscore.removeClass(ksscore.getHtmlIdSelector(id), value="invisible") |
---|
| 467 | else: |
---|
| 468 | ksscore.addClass(ksscore.getHtmlIdSelector(id), value="invisible") |
---|
[150] | 469 | self.updatePage(cat_name) |
---|
| 470 | |
---|
| 471 | @kssaction |
---|
[149] | 472 | def kss_deleteAction(self, id, cat_name): |
---|
[47] | 473 | """ Delete portal action with given id & category """ |
---|
[149] | 474 | # validate input |
---|
| 475 | act_id, category, action = self.kss_validateAction(id, cat_name) |
---|
| 476 | self.deleteAction(act_id, cat_name) |
---|
[47] | 477 | |
---|
[149] | 478 | # update client |
---|
[47] | 479 | ksscore = self.getCommandSet("core") |
---|
[150] | 480 | # XXX TODO: fade effect during removing, to do this we need kukit js action/command plugin |
---|
[47] | 481 | ksscore.deleteNode(ksscore.getHtmlIdSelector(id)) |
---|
[154] | 482 | |
---|
| 483 | # issue portal message |
---|
| 484 | self.getCommandSet('plone').issuePortalMessage(_(u"'%s' action successfully deleted." % act_id), msgtype="info") |
---|
| 485 | |
---|
| 486 | # update different sections of page depending on actions category |
---|
[149] | 487 | self.updatePage(cat_name) |
---|
[47] | 488 | |
---|
[153] | 489 | @kssaction |
---|
[154] | 490 | def kss_addAction(self): |
---|
[151] | 491 | """ KSS method to add new portal action """ |
---|
| 492 | # extract posted data |
---|
[154] | 493 | id, cat_name, data = self.parseAddForm(self.request.form) |
---|
[151] | 494 | |
---|
| 495 | # validate posted data |
---|
| 496 | errors = self.validateActionFields(cat_name, data) |
---|
| 497 | |
---|
| 498 | # if not errors find (or create) category and set action to it |
---|
[152] | 499 | ksscore = self.getCommandSet('core') |
---|
[151] | 500 | kssplone = self.getCommandSet('plone') |
---|
| 501 | if not errors: |
---|
| 502 | action = self.addAction(cat_name, data) |
---|
| 503 | |
---|
| 504 | # update client |
---|
| 505 | # add one more action to actions list |
---|
| 506 | content = self.getActionsList(category=cat_name, tabs=[action,]) |
---|
| 507 | ksscore.insertHTMLAsLastChild(ksscore.getHtmlIdSelector('tabslist'), content) |
---|
| 508 | |
---|
[152] | 509 | # update reorder controls |
---|
[160] | 510 | #self.kss_checkReorderControls(cat_name) |
---|
[152] | 511 | |
---|
[151] | 512 | # hide adding form |
---|
| 513 | ksscore.removeClass(ksscore.getHtmlIdSelector('addaction'), 'adding') |
---|
[507] | 514 | self.kss_toggleCollapsible(ksscore.getCssSelector('#addaction .headerAdvanced'), collapse='true') |
---|
[151] | 515 | |
---|
[154] | 516 | # set client state var 'plonetabs-addingTitle' to empty string for correct id autogeneration functionality |
---|
| 517 | ksscore.setStateVar('plonetabs-addingTitle', '') |
---|
| 518 | |
---|
[151] | 519 | # reset adding form |
---|
| 520 | self.kss_resetForm(ksscore.getHtmlIdSelector('addaction')) |
---|
| 521 | |
---|
| 522 | # issue portal message |
---|
| 523 | kssplone.issuePortalMessage(_(u"'%s' action successfully added." % action.id), msgtype="info") |
---|
| 524 | |
---|
| 525 | # update page |
---|
| 526 | self.updatePage(cat_name) |
---|
| 527 | else: |
---|
[152] | 528 | # expand advanced section if there are errors in id or condition |
---|
| 529 | if errors.has_key('id') or errors.has_key('available_expr'): |
---|
[507] | 530 | self.kss_toggleCollapsible(ksscore.getCssSelector('#addaction .headerAdvanced'), collapse='false') |
---|
[152] | 531 | |
---|
[151] | 532 | # send error message |
---|
| 533 | kssplone.issuePortalMessage(_(u"Please correct the indicated errors."), msgtype="error") |
---|
| 534 | |
---|
[154] | 535 | # update errors on client form |
---|
[151] | 536 | self.kss_issueErrors(errors) |
---|
[135] | 537 | |
---|
| 538 | @kssaction |
---|
[507] | 539 | def kss_hideAddForm(self): |
---|
| 540 | """"Hide Add form, reset it and remove error messages""" |
---|
| 541 | # no server changes, only update client |
---|
| 542 | ksscore = self.getCommandSet("core") |
---|
| 543 | # hide form itself |
---|
| 544 | ksscore.removeClass(ksscore.getHtmlIdSelector('addaction'), 'adding') |
---|
| 545 | # collapse advanced section |
---|
| 546 | self.kss_toggleCollapsible(ksscore.getCssSelector('#addaction .headerAdvanced'), collapse='true') |
---|
| 547 | # reset form inputs |
---|
| 548 | self.kss_resetForm(ksscore.getHtmlIdSelector('addaction')) |
---|
| 549 | # remove form errors if such exist |
---|
| 550 | self.kss_issueErrors({}) |
---|
| 551 | |
---|
| 552 | @kssaction |
---|
[154] | 553 | def kss_showEditForm(self, id, cat_name): |
---|
[507] | 554 | """Show edit form for given action""" |
---|
[154] | 555 | act_id, category, action = self.kss_validateAction(id, cat_name) |
---|
[48] | 556 | |
---|
[154] | 557 | # fetch data |
---|
| 558 | action_info = self.copyAction(action) |
---|
[48] | 559 | action_info["editing"] = True |
---|
| 560 | |
---|
[154] | 561 | # update client |
---|
[48] | 562 | ksscore = self.getCommandSet("core") |
---|
[162] | 563 | content = self.getActionsList(category=cat_name, tabs=[action_info,]) |
---|
[154] | 564 | ksscore.replaceHTML(ksscore.getHtmlIdSelector(id), content) |
---|
[48] | 565 | |
---|
| 566 | # focus name field |
---|
[154] | 567 | ksscore.focus(ksscore.getCssSelector("#%s input[name=title_%s]" % (id, act_id))) |
---|
[48] | 568 | |
---|
| 569 | @kssaction |
---|
[154] | 570 | def kss_hideEditForm(self, id, cat_name): |
---|
[507] | 571 | """Hide edit form for given action""" |
---|
[154] | 572 | act_id, category, action = self.kss_validateAction(id, cat_name) |
---|
[48] | 573 | |
---|
[154] | 574 | # update client |
---|
[48] | 575 | ksscore = self.getCommandSet("core") |
---|
[162] | 576 | content = self.getActionsList(category=cat_name, tabs=[action,]) |
---|
[154] | 577 | ksscore.replaceHTML(ksscore.getHtmlIdSelector(id), content) |
---|
| 578 | |
---|
| 579 | @kssaction |
---|
| 580 | def kss_editAction(self): |
---|
[159] | 581 | """ Update action's properties """ |
---|
[154] | 582 | id, cat_name, data = self.parseEditForm(self.request.form) |
---|
[48] | 583 | |
---|
[154] | 584 | # get category and action to edit |
---|
| 585 | category = self.getActionCategory(cat_name) |
---|
| 586 | action = category[id] |
---|
| 587 | |
---|
| 588 | # validate posted data |
---|
[165] | 589 | errors = self.validateActionFields(cat_name, data, allow_dup=(id == data['id'])) |
---|
[154] | 590 | |
---|
| 591 | html_id = '%s%s%s' % (self.prefix, id, self.sufix) |
---|
| 592 | ksscore = self.getCommandSet('core') |
---|
| 593 | kssplone = self.getCommandSet('plone') |
---|
| 594 | if not errors: |
---|
| 595 | action = self.updateAction(id, cat_name, data) |
---|
| 596 | |
---|
| 597 | # update client |
---|
| 598 | # replace action item with updated one |
---|
| 599 | content = self.getActionsList(category=cat_name, tabs=[action,]) |
---|
| 600 | ksscore.replaceHTML(ksscore.getHtmlIdSelector(html_id), content) |
---|
| 601 | |
---|
| 602 | # issue portal message |
---|
| 603 | kssplone.issuePortalMessage(_(u"'%s' action saved." % action.id), msgtype="info") |
---|
| 604 | |
---|
| 605 | # update page |
---|
| 606 | self.updatePage(cat_name) |
---|
| 607 | else: |
---|
| 608 | # issue error messages |
---|
| 609 | self.kss_issueErrors(errors, editform=id) |
---|
| 610 | |
---|
| 611 | # expand advanced section if there are errors in id, action url or condition |
---|
| 612 | if errors.has_key('id') or errors.has_key('available_expr') or errors.has_key('url_expr'): |
---|
| 613 | self.kss_toggleCollapsible(ksscore.getCssSelector('#%s .headerAdvanced' % html_id), collapse='false') |
---|
| 614 | |
---|
| 615 | # send error message |
---|
| 616 | kssplone.issuePortalMessage(_(u"Please correct the indicated errors."), msgtype="error") |
---|
[48] | 617 | |
---|
[159] | 618 | @kssaction |
---|
| 619 | def kss_orderActions(self): |
---|
| 620 | """ Update actions order in the given category """ |
---|
| 621 | form = self.request.form |
---|
| 622 | cat_name = form['cat_name'] |
---|
| 623 | category = self.getActionCategory(cat_name) |
---|
| 624 | |
---|
| 625 | # decode URI components and collect ids from request |
---|
| 626 | components = urllib.unquote(form['actions']).split('&') |
---|
| 627 | if self.sufix == '': |
---|
| 628 | ids = [component[len(self.prefix):] for component in components] |
---|
| 629 | else: |
---|
| 630 | ids = [component[len(self.prefix):-len(self.sufix)] for component in components] |
---|
| 631 | |
---|
| 632 | # do actual sorting |
---|
| 633 | category.moveObjectsByDelta(ids, -len(category.objectIds())) |
---|
| 634 | |
---|
| 635 | # update client |
---|
| 636 | self.updatePage(cat_name) |
---|
| 637 | |
---|
[138] | 638 | # |
---|
[48] | 639 | # Utility Methods |
---|
[138] | 640 | # |
---|
[48] | 641 | |
---|
[507] | 642 | def fixExpression(self, expr): |
---|
| 643 | """Fix expression appropriatly for tal format""" |
---|
| 644 | if expr.find('/') == 0: |
---|
| 645 | return 'string:${portal_url}%s' % expr |
---|
| 646 | elif re.compile('^(ht|f)tps?\:', re.I).search(expr): |
---|
| 647 | return 'string:%s' % expr |
---|
| 648 | #elif re.compile('^(python:|string:|not:|exists:|nocall:|path:)', re.I).search(expr): |
---|
| 649 | #return expr |
---|
| 650 | elif expr.find(':') != -1: |
---|
| 651 | return expr |
---|
| 652 | else: |
---|
| 653 | return 'string:${object_url}/%s' % expr |
---|
| 654 | |
---|
[48] | 655 | def copyAction(self, action): |
---|
[478] | 656 | """ Copy action to dictionary """ |
---|
[154] | 657 | action_info = {'description':action.description} |
---|
[48] | 658 | for attr in ACTION_ATTRS: |
---|
| 659 | action_info[attr] = getattr(action, attr) |
---|
| 660 | return action_info |
---|
| 661 | |
---|
[138] | 662 | def validateActionFields(self, cat_name, data, allow_dup=False): |
---|
[135] | 663 | """ Check action fields on validity """ |
---|
| 664 | errors = {} |
---|
| 665 | |
---|
[138] | 666 | if allow_dup: |
---|
| 667 | category = ActionCategory(cat_name) # create dummy category to avoid id duplication during action update |
---|
| 668 | else: |
---|
| 669 | category = self.getOrCreateCategory(cat_name) # get or create (if necessary) actions category |
---|
[135] | 670 | |
---|
| 671 | # validate action id |
---|
| 672 | chooser = INameChooser(category) |
---|
| 673 | try: |
---|
| 674 | chooser.checkName(data['id'], self.context) |
---|
| 675 | except Exception, e: |
---|
| 676 | errors['id'] = "%s" % str(e) |
---|
| 677 | |
---|
| 678 | # validate action name |
---|
| 679 | if not data['title'].strip(): |
---|
[138] | 680 | errors['title'] = 'Empty or invalid title specified' |
---|
[135] | 681 | |
---|
| 682 | # validate condition expression |
---|
| 683 | if data['available_expr']: |
---|
| 684 | try: |
---|
| 685 | Expression(data['available_expr']) |
---|
| 686 | except Exception, e: |
---|
| 687 | errors["available_expr"] = "%s" % str(e) |
---|
| 688 | |
---|
| 689 | # validate action expression |
---|
| 690 | if data['url_expr']: |
---|
| 691 | try: |
---|
| 692 | Expression(data['url_expr']) |
---|
| 693 | except Exception, e: |
---|
| 694 | errors["url_expr"] = "%s" % str(e) |
---|
| 695 | |
---|
| 696 | return errors |
---|
| 697 | |
---|
[138] | 698 | def processErrors(self, errors, prefix='', sufix=''): |
---|
| 699 | """ Add prefixes, sufixes to error ids |
---|
| 700 | This is necessary during edit form validation, |
---|
| 701 | because every edit form on the page has it's own sufix (id) """ |
---|
| 702 | if not (prefix or sufix): |
---|
| 703 | return errors |
---|
| 704 | |
---|
| 705 | result = {} |
---|
| 706 | for key, value in errors.items(): |
---|
| 707 | result['%s%s%s' % (prefix, key, sufix)] = value |
---|
| 708 | |
---|
| 709 | return result |
---|
| 710 | |
---|
[139] | 711 | def parseEditForm(self, form): |
---|
| 712 | """ Extract all needed fields from edit form """ |
---|
[138] | 713 | # get original id and category |
---|
| 714 | info = {} |
---|
| 715 | id = form['orig_id'] |
---|
| 716 | category = form['category'] |
---|
| 717 | |
---|
| 718 | # preprocess 'visible' field (checkbox needs special checking) |
---|
| 719 | if form.has_key('visible_%s' % id): |
---|
| 720 | form['visible_%s' % id] = True |
---|
| 721 | else: |
---|
| 722 | form['visible_%s' % id] = False |
---|
| 723 | |
---|
| 724 | # collect all action fields |
---|
| 725 | for attr in ACTION_ATTRS: |
---|
| 726 | info[attr] = form['%s_%s' % (attr, id)] |
---|
| 727 | |
---|
| 728 | return (id, category, info) |
---|
| 729 | |
---|
[139] | 730 | def parseAddForm(self, form): |
---|
| 731 | """ Extract all needed fields from add form """ |
---|
| 732 | info = {} |
---|
| 733 | id = form['id'] |
---|
| 734 | category = form['category'] |
---|
| 735 | |
---|
| 736 | # preprocess 'visible' field (checkbox needs special checking) |
---|
[151] | 737 | if form.has_key('visible') and form['visible']: |
---|
[139] | 738 | form['visible'] = True |
---|
| 739 | else: |
---|
| 740 | form['visible'] = False |
---|
| 741 | |
---|
[507] | 742 | # fix expression fields |
---|
| 743 | form['url_expr'] = self.fixExpression(form['url_expr']) |
---|
| 744 | |
---|
[139] | 745 | # collect all action fields |
---|
| 746 | for attr in ACTION_ATTRS: |
---|
| 747 | info[attr] = form[attr] |
---|
| 748 | |
---|
| 749 | return (id, category, info) |
---|
| 750 | |
---|
[138] | 751 | def getActionCategory(self, name): |
---|
| 752 | portal_actions = getToolByName(self.context, 'portal_actions') |
---|
| 753 | return portal_actions[name] |
---|
| 754 | |
---|
[135] | 755 | def getOrCreateCategory(self, name): |
---|
[138] | 756 | """ Get or create (if necessary) category """ |
---|
[135] | 757 | portal_actions = getToolByName(self.context, 'portal_actions') |
---|
| 758 | if name not in map(lambda x: x.id, filter(lambda x: IActionCategory.providedBy(x), portal_actions.objectValues())): |
---|
| 759 | portal_actions._setObject(name, ActionCategory(name)) |
---|
[138] | 760 | return self.getActionCategory(name) |
---|
[135] | 761 | |
---|
[147] | 762 | def setSiteProperties(self, **kw): |
---|
| 763 | """ Change site_properties """ |
---|
| 764 | site_properties = getToolByName(self.context, "portal_properties").site_properties |
---|
| 765 | site_properties.manage_changeProperties(**kw) |
---|
| 766 | return True |
---|
| 767 | |
---|
| 768 | # |
---|
[149] | 769 | # Utility methods for the kss actions management |
---|
| 770 | # |
---|
| 771 | |
---|
[507] | 772 | def kss_hideStatusMessage(self, ksscore): |
---|
| 773 | """Hide Portal Status Message""" |
---|
| 774 | ksscore.setStyle(ksscore.getHtmlIdSelector('kssPortalMessage'), 'display', 'none') |
---|
| 775 | |
---|
[149] | 776 | def kss_validateAction(self, id, cat_name): |
---|
| 777 | """ Check whether action with given id exists in cat_name category """ |
---|
| 778 | try: |
---|
| 779 | category = self.getActionCategory(cat_name) |
---|
| 780 | except Exception: |
---|
| 781 | raise KSSExplicitError, "'%s' action category does not exist" % cat_name |
---|
| 782 | |
---|
| 783 | # extract action id from given list item id on client |
---|
| 784 | action_id = self.sufix and id[len(self.prefix):-len(self.sufix)] or id[len(self.prefix):] |
---|
| 785 | try: |
---|
| 786 | action = category[action_id] |
---|
| 787 | except Exception: |
---|
| 788 | raise KSSExplicitError, "No '%s' action in '%s' category." % (action_id, cat_name) |
---|
| 789 | |
---|
| 790 | return (action_id, category, action) |
---|
| 791 | |
---|
[154] | 792 | def kss_issueErrors(self, errors, editform=False, fields=ACTION_ATTRS): |
---|
[151] | 793 | """ Display error messages on the client """ |
---|
| 794 | ksscore = self.getCommandSet('core') |
---|
| 795 | for field in fields: |
---|
[154] | 796 | self.kss_issueFieldError(ksscore, field, errors.get(field, False), editform) |
---|
[151] | 797 | |
---|
[154] | 798 | def kss_issueFieldError(self, ksscore, name, error, editform): |
---|
[151] | 799 | """ Issue this error message for the field """ |
---|
[154] | 800 | if editform: |
---|
| 801 | id = '%s%s%s' % (self.prefix, editform, self.sufix) |
---|
| 802 | field_selector = ksscore.getCssSelector('#%s .edit-field-%s' % (id, UI_ATTRS.get(name, name))) |
---|
| 803 | field_error_selector = ksscore.getCssSelector('#%s .edit-field-%s .error-container' % (id, UI_ATTRS.get(name, name))) |
---|
| 804 | else: |
---|
| 805 | field_selector = ksscore.getCssSelector('#addaction .field-%s' % UI_ATTRS.get(name, name)) |
---|
| 806 | field_error_selector = ksscore.getCssSelector('#addaction .field-%s .error-container' % UI_ATTRS.get(name, name)) |
---|
| 807 | |
---|
[151] | 808 | if error: |
---|
| 809 | ksscore.replaceInnerHTML(field_error_selector, _(error)) |
---|
| 810 | ksscore.addClass(field_selector, 'error') |
---|
| 811 | else: |
---|
| 812 | ksscore.clearChildNodes(field_error_selector) |
---|
| 813 | ksscore.removeClass(field_selector, 'error') |
---|
| 814 | |
---|
| 815 | def kss_toggleCollapsible(self, selector, collapsed=None, expanded=None, collapse=None): |
---|
| 816 | """ KSS Server command to add plonetabs-toggleCollapsible client action to response """ |
---|
| 817 | command = self.commands.addCommand('plonetabs-toggleCollapsible', selector) |
---|
| 818 | if collapsed is not None: |
---|
| 819 | data = command.addParam('collapsed', collapsed) |
---|
| 820 | if expanded is not None: |
---|
| 821 | data = command.addParam('expanded', expanded) |
---|
| 822 | if collapse is not None: |
---|
| 823 | data = command.addParam('collapse', collapse) |
---|
| 824 | |
---|
| 825 | def kss_resetForm(self, selector): |
---|
| 826 | """ KSS Server command to reset form on client """ |
---|
| 827 | command = self.commands.addCommand('plonetabs-resetForm', selector) |
---|
| 828 | |
---|
[175] | 829 | def kss_replaceOrInsert(self, selector, parentSelector, html, withKssSetup='True', alternativeHTML='', selectorType='', |
---|
| 830 | position='', positionSelector='', positionSelectorType=''): |
---|
| 831 | """ KSS Server command to execute replaceOrInsert client action """ |
---|
| 832 | command = self.commands.addCommand('plonetabs-replaceOrInsert', selector) |
---|
| 833 | data = command.addParam('selector', parentSelector) |
---|
| 834 | data = command.addHtmlParam('html', html) |
---|
| 835 | data = command.addParam('withKssSetup', withKssSetup) |
---|
| 836 | if alternativeHTML: |
---|
| 837 | data = command.addHtmlParam('alternativeHTML', alternativeHTML) |
---|
| 838 | if selectorType: |
---|
| 839 | data = command.addParam('selectorType', selectorType) |
---|
| 840 | if position: |
---|
| 841 | data = command.addParam('position', position) |
---|
| 842 | if positionSelector: |
---|
| 843 | data = command.addParam('positionSelector', positionSelector) |
---|
| 844 | if positionSelectorType: |
---|
| 845 | data = command.addParam('positionSelectorType', positionSelectorType) |
---|
| 846 | |
---|
| 847 | def renderViewlet(self, manager, name): |
---|
| 848 | if isinstance(manager, basestring): |
---|
| 849 | manager = getMultiAdapter((self.context, self.request, self,), IViewletManager, name=manager) |
---|
| 850 | renderer = getMultiAdapter((self.context, self.request, self, manager), IViewlet, name=name) |
---|
| 851 | renderer = renderer.__of__(self.context) |
---|
| 852 | renderer.update() |
---|
| 853 | return renderer.render() |
---|
| 854 | |
---|
[149] | 855 | # |
---|
[147] | 856 | # Basic API to work with portal actions tool in a more pleasent way |
---|
| 857 | # |
---|
| 858 | |
---|
[135] | 859 | def addAction(self, cat_name, data): |
---|
| 860 | """ Create and add new action to category with given name """ |
---|
| 861 | id = data.pop('id') |
---|
| 862 | category = self.getOrCreateCategory(cat_name) |
---|
| 863 | action = Action(id, **data) |
---|
| 864 | category._setObject(id, action) |
---|
| 865 | return action |
---|
| 866 | |
---|
[138] | 867 | def updateAction(self, id, cat_name, data): |
---|
| 868 | """ Update action with given id and category """ |
---|
| 869 | new_id = data.pop('id') |
---|
| 870 | category = self.getActionCategory(cat_name) |
---|
| 871 | |
---|
| 872 | # rename action if necessary |
---|
| 873 | if id != new_id: |
---|
| 874 | category.manage_renameObject(id, new_id) |
---|
| 875 | |
---|
| 876 | # get action |
---|
| 877 | action = category[new_id] |
---|
| 878 | |
---|
| 879 | # update action properties |
---|
[150] | 880 | for attr in data.keys(): |
---|
[138] | 881 | if data.has_key(attr): |
---|
| 882 | action._setPropValue(attr, data[attr]) |
---|
| 883 | |
---|
| 884 | return action |
---|
| 885 | |
---|
| 886 | def deleteAction(self, id, cat_name): |
---|
| 887 | """ Delete action with given id from given category """ |
---|
| 888 | category = self.getActionCategory(cat_name) |
---|
| 889 | category.manage_delObjects(ids=[id,]) |
---|
| 890 | return True |
---|
| 891 | |
---|
[141] | 892 | def moveAction(self, id, cat_name, steps=0): |
---|
| 893 | """ Move action by a given steps """ |
---|
| 894 | if steps != 0: |
---|
| 895 | category = self.getActionCategory(cat_name) |
---|
| 896 | if steps > 0: |
---|
| 897 | category.moveObjectsUp([id,], steps) |
---|
| 898 | else: |
---|
| 899 | category.moveObjectsDown([id,], abs(steps)) |
---|
| 900 | return True |
---|
| 901 | return False |
---|
| 902 | |
---|
[138] | 903 | # |
---|
[135] | 904 | # KSS Methods that are used to update different parts of the page |
---|
[147] | 905 | # accordingly to category |
---|
[138] | 906 | # |
---|
[135] | 907 | |
---|
| 908 | def updatePage(self, category): |
---|
| 909 | """ Seek for according method in class and calls it if found |
---|
| 910 | Example of making up method's name: |
---|
[161] | 911 | portal_tabs => updatePortalTabsPageSection """ |
---|
[135] | 912 | method_name = 'update%sPageSection' % ''.join(map(lambda x: x.capitalize(), category.split('_'))) |
---|
| 913 | if hasattr(self, method_name): |
---|
| 914 | getattr(self, method_name)() |
---|
| 915 | |
---|
| 916 | def updatePortalTabsPageSection(self): |
---|
| 917 | """ Method for updating global-sections on client """ |
---|
[175] | 918 | ksscore = self.getCommandSet("core") |
---|
| 919 | self.kss_replaceOrInsert(ksscore.getHtmlIdSelector("portal-header"), |
---|
| 920 | "portal-globalnav", |
---|
| 921 | self.sections_template(), |
---|
| 922 | withKssSetup='False', |
---|
| 923 | selectorType='htmlid') |
---|
[135] | 924 | |
---|
| 925 | def updateSiteActionsPageSection(self): |
---|
| 926 | """ Method for updating site action on client """ |
---|
[175] | 927 | ksscore = self.getCommandSet("core") |
---|
| 928 | self.kss_replaceOrInsert(ksscore.getHtmlIdSelector("portal-header"), |
---|
| 929 | "portal-siteactions", |
---|
| 930 | self.renderViewlet("plone.portalheader", "plone.site_actions"), |
---|
| 931 | withKssSetup='False', |
---|
| 932 | selectorType='htmlid', |
---|
| 933 | position="before", |
---|
| 934 | positionSelector="portal-searchbox", |
---|
| 935 | positionSelectorType="htmlid") |
---|
| 936 | |
---|
| 937 | #ksszope = self.getCommandSet("zope") |
---|
| 938 | #ksszope.refreshViewlet( |
---|
| 939 | #self.getCommandSet("core").getHtmlIdSelector("portal-siteactions"), |
---|
| 940 | #"plone.portalheader", |
---|
| 941 | #"plone.site_actions") |
---|
[135] | 942 | |
---|
| 943 | def updateUserPageSection(self): |
---|
| 944 | """ Method for updating site action on client """ |
---|
| 945 | ksszope = self.getCommandSet("zope") |
---|
| 946 | ksszope.refreshViewlet( |
---|
| 947 | self.getCommandSet("core").getHtmlIdSelector("portal-personaltools-wrapper"), |
---|
| 948 | "plone.portaltop", |
---|
| 949 | "plone.personal_bar") |
---|
[45] | 950 | |
---|
[47] | 951 | |
---|