Changeset 3081 in products for quintagroup.plonetabs
- Timestamp:
- Mar 28, 2011 2:27:47 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.plonetabs/branches/plone4/quintagroup/plonetabs/browser/plonetabs.py
r874 r3081 40 40 41 41 class PloneTabsControlPanel(PloneKSSView): 42 42 43 43 implements(IPloneTabsControlPanel) 44 44 45 45 template = ViewPageTemplateFile("templates/plonetabs.pt") 46 46 actionslist_template = ViewPageTemplateFile("templates/actionslist.pt") … … 48 48 autogenerated_list = ViewPageTemplateFile("templates/autogeneratedlist.pt") 49 49 link_template = ViewPageTemplateFile("templates/changemodelink.pt") 50 50 51 51 # custom templates used to update page sections 52 52 sections_template = ViewPageTemplateFile("templates/sections.pt") 53 53 54 54 # configuration variables 55 55 prefix = "tabslist_" 56 56 sufix = "" 57 57 58 58 def __call__(self): 59 59 """Perform the update and redirect if necessary, or render the page""" … … 61 61 errors = {} 62 62 context = aq_inner(self.context) 63 63 64 64 form = self.request.form 65 65 action = form.get("action", "") 66 66 submitted = form.get('form.submitted', False) 67 67 68 68 # action handler def handler(self, form) 69 69 if submitted: … … 82 82 else: 83 83 postback = True 84 84 85 85 mode = self.request.get(cookie_name, False) 86 86 if mode in ('plain', 'rich'): … … 89 89 self.request.response.setCookie(cookie_name, mode, path='/', 90 90 expires=expires) 91 91 92 92 if postback: 93 93 return self.template(errors=errors) 94 94 95 95 ######################################## 96 96 # Methods for processing configlet posts 97 97 ######################################## 98 98 99 99 def manage_setAutogeneration(self, form, errors): 100 100 """Process managing autogeneration settings""" 101 101 102 102 # set excludeFromNav property for root objects 103 103 portal = getMultiAdapter((aq_inner(self.context), self.request), … … 105 105 generated_tabs = form.get("generated_tabs", '0') 106 106 nonfolderish_tabs = form.get("nonfolderish_tabs", '0') 107 107 108 108 for item in self.getRootTabs(): 109 109 obj = getattr(portal, item['id'], None) … … 120 120 else: 121 121 self.setSiteProperties(disable_folder_sections=True) 122 122 123 123 # set disable_nonfolderish_sections property 124 124 if int(nonfolderish_tabs) == 1: … … 126 126 else: 127 127 self.setSiteProperties(disable_nonfolderish_sections=True) 128 128 129 129 # after successfull form processing make redirect with good message 130 130 IStatusMessage(self.request).addStatusMessage(_(u"Changes saved!"), … … 132 132 self.redirect() 133 133 return False 134 134 135 135 def manage_addAction(self, form, errs): 136 136 """Manage method to add a new action to given category, … … 139 139 # extract posted data 140 140 id, cat_name, data = self.parseAddForm(form) 141 141 142 142 # validate posted data 143 143 errors = self.validateActionFields(cat_name, data) 144 144 145 145 # if not errors find (or create) category and set action to it 146 146 if not errors: … … 156 156 _(u"Please correct the indicated errors."), type="error") 157 157 return True 158 158 159 159 def manage_editAction(self, form, errs): 160 160 """Manage Method to update action""" 161 161 # extract posted data 162 162 id, cat_name, data = self.parseEditForm(form) 163 163 164 164 # get category and action to edit 165 165 category = self.getActionCategory(cat_name) 166 166 action = category[id] 167 167 168 168 # validate posted data 169 169 errors = self.validateActionFields(cat_name, data, 170 170 allow_dup=(id == data['id'])) 171 171 172 172 if not errors: 173 173 action = self.updateAction(id, cat_name, data) … … 183 183 _(u"Please correct the indicated errors."), type="error") 184 184 return True 185 185 186 186 def manage_deleteAction(self, form, errs): 187 187 """Manage Method to delete action""" 188 188 # extract posted data 189 189 id, cat_name, data = self.parseEditForm(form) 190 190 191 191 # get category and action to delete 192 192 category = self.getActionCategory(cat_name) … … 203 203 type="error") 204 204 return True 205 205 206 206 def manage_moveUpAction(self, form, errs): 207 207 """Manage Method for moving up given action by one position""" 208 208 # extract posted data 209 209 id, cat_name, data = self.parseEditForm(form) 210 210 211 211 # get category and action to move 212 212 category = self.getActionCategory(cat_name) … … 222 222 mapping={'id': id, 'cat_name': cat_name}), type="error") 223 223 return True 224 224 225 225 def manage_moveDownAction(self, form, errs): 226 226 """Manage Method for moving down given action by one position""" 227 227 # extract posted data 228 228 id, cat_name, data = self.parseEditForm(form) 229 229 230 230 # get category and action to move 231 231 category = self.getActionCategory(cat_name) … … 243 243 type="error") 244 244 return True 245 245 246 246 def redirect(self, url="", search="", url_hash=""): 247 247 """Redirect to @@plonetabs-controlpanel configlet""" … … 255 255 url_hash = '#%s' % url_hash 256 256 self.request.response.redirect("%s%s%s" % (url, search, url_hash)) 257 257 258 258 ################################### 259 259 # … … 261 261 # 262 262 ################################### 263 263 264 264 def _charset(self): 265 265 pp = getToolByName(self.context, 'portal_properties', None) … … 269 269 return site_properties.getProperty('default_charset', 'utf-8') 270 270 return 'utf-8' 271 271 272 272 def getPageTitle(self, category="portal_tabs"): 273 273 """See interface""" … … 275 275 default_title = _(u"Plone '${cat_name}' Configuration", 276 276 mapping={'cat_name': category}) 277 277 278 278 if not hasattr(portal_props, PROPERTY_SHEET): 279 279 return default_title 280 280 281 281 sheet = getattr(portal_props, PROPERTY_SHEET) 282 282 if not hasattr(sheet, FIELD_NAME): 283 283 return default_title 284 284 285 285 field = sheet.getProperty(FIELD_NAME) 286 286 dict = {} … … 288 288 cat, title = line.split("|", 2) 289 289 dict[cat] = title 290 290 291 291 title = dict.get(category, None) 292 292 if title is None: 293 293 return default_title 294 294 295 295 charset = self._charset() 296 296 if not isinstance(title, unicode): 297 297 title = title.decode(charset) 298 298 299 299 return _(title) 300 300 301 301 def hasActions(self, category="portal_tabs"): 302 302 """See interface""" 303 303 tool = getToolByName(self.context, "portal_actions") 304 304 return len(tool.listActions(categories=[category,])) > 0 305 305 306 306 def getPortalActions(self, category="portal_tabs"): 307 307 """See interface""" 308 308 portal_actions = getToolByName(self.context, "portal_actions") 309 309 310 310 if category not in portal_actions.objectIds(): 311 311 return [] 312 312 313 313 actions = [] 314 314 for item in portal_actions[category].objectValues(): 315 315 if IAction.providedBy(item): 316 316 actions.append(item) 317 317 318 318 return actions 319 319 320 320 def isGeneratedTabs(self): 321 321 """See interface""" … … 323 323 "portal_properties").site_properties 324 324 return not site_properties.getProperty("disable_folder_sections", False) 325 325 326 326 def isNotFoldersGenerated(self): 327 327 """See interface""" … … 331 331 False) 332 332 return not prop 333 333 334 334 def getActionsList(self, category="portal_tabs", errors={}, tabs=[]): 335 335 """See interface""" … … 338 338 kw['tabs'] = tabs 339 339 return self.actionslist_template(**kw) 340 340 341 341 def getAutoGenereatedSection(self, cat_name, errors={}): 342 342 """See interface""" 343 343 return self.autogenerated_template(category=cat_name, errors=errors) 344 344 345 345 def getGeneratedTabs(self): 346 346 """See interface""" 347 347 return self.autogenerated_list() 348 348 349 349 def getRootTabs(self): 350 350 """See interface""" 351 351 context = aq_inner(self.context) 352 352 353 353 portal_catalog = getToolByName(context, 'portal_catalog') 354 354 portal_properties = getToolByName(context, 'portal_properties') 355 355 navtree_properties = getattr(portal_properties, 'navtree_properties') 356 356 357 357 # Build result dict 358 358 result = [] 359 359 360 360 # check whether tabs autogeneration is turned on 361 361 if not self.isGeneratedTabs(): 362 362 return result 363 363 364 364 query = {} 365 365 rootPath = getNavigationRoot(context) 366 366 query['path'] = {'query' : rootPath, 'depth' : 1} 367 367 query['portal_type'] = utils.typesToList(context) 368 368 369 369 sortAttribute = navtree_properties.getProperty('sortAttribute', None) 370 370 if sortAttribute is not None: 371 371 query['sort_on'] = sortAttribute 372 372 373 373 sortOrder = navtree_properties.getProperty('sortOrder', None) 374 374 if sortOrder is not None: 375 375 query['sort_order'] = sortOrder 376 376 377 377 if navtree_properties.getProperty('enable_wf_state_filtering', False): 378 378 query['review_state'] = navtree_properties.getProperty( 379 379 'wf_states_to_show', []) 380 380 381 381 query['is_default_page'] = False 382 382 … … 402 402 'exclude_from_nav' : item.exclude_from_nav} 403 403 result.append(data) 404 404 405 405 return result 406 406 407 407 def getCategories(self): 408 408 """See interface""" 409 409 portal_actions = getToolByName(self.context, "portal_actions") 410 410 return portal_actions.objectIds() 411 411 412 412 # 413 413 # Methods to make this class looks like global sections viewlet 414 414 # 415 415 416 416 def test(self, condition, ifTrue, ifFalse): 417 417 """See interface""" … … 420 420 else: 421 421 return ifFalse 422 422 423 423 # methods for rendering global-sections viewlet via kss, 424 424 # due to bug in macroContent when global-section list is empty, … … 430 430 portal_tabs_view = getMultiAdapter((self.context, self.request), 431 431 name="portal_tabs_view") 432 433 return portal_tabs_view.topLevelTabs(actions=actions) 434 432 return portal_tabs_view.topLevelTabs(actions=actions['portal_tabs']) 433 435 434 def selected_portal_tab(self): 436 435 """See global-sections viewlet""" … … 438 437 selected_tabs = selectedTabs('index_html', self.context, 439 438 self.portal_tabs()) 440 439 441 440 return selected_tabs['portal'] 442 441 443 442 ########################## 444 443 # … … 446 445 # 447 446 ########################## 448 447 449 448 @kssaction 450 449 def kss_insertModeLink(self): 451 450 """Insert link which allows change categories between plain and rich""" 452 451 ksscore = self.getCommandSet('core') 453 452 454 453 html = self.link_template() 455 454 target = ksscore.getCssSelector('.link-parent') 456 455 ksscore.insertHTMLAfter(target, html, withKssSetup='False') 457 456 458 457 @kssaction 459 458 def kss_changeCategory(self, cat_name): 460 459 """Change action category to manage""" 461 460 ksscore = self.getCommandSet('core') 462 461 463 462 # update actions list 464 463 actionslist = self.getActionsList(category=cat_name) 465 464 ksscore.replaceInnerHTML(ksscore.getHtmlIdSelector('tabslist'), 466 465 actionslist) 467 466 468 467 # update autogenerated sections 469 468 section = self.getAutoGenereatedSection(cat_name) … … 475 474 ksscore.replaceInnerHTML( 476 475 ksscore.getHtmlIdSelector('plonetabs-form-title'), title) 477 476 478 477 # update category hidden field on adding form 479 478 ksscore.setAttribute(ksscore.getCssSelector( … … 481 480 'value', 482 481 cat_name) 483 482 484 483 # update state variable 'plonetabs-category' on client 485 484 ksscore.setStateVar('plonetabs-category', cat_name) 486 485 487 486 # hide adding form 488 487 self.kss_hideAddForm() 489 488 490 489 # issue portal status message 491 490 self.kss_issueMessage(_(u"Category changed successfully.")) 492 491 493 492 @kssaction 494 493 def kss_toggleGeneratedTabs(self, field, checked='0'): … … 506 505 else: 507 506 message = _(u"Generated tabs switched off.") 508 507 509 508 # update client 510 509 ksscore = self.getCommandSet("core") 511 510 content = self.getGeneratedTabs() 512 511 ksscore.replaceInnerHTML(ksscore.getHtmlIdSelector('roottabs'), content) 513 512 514 513 # update global-sections viewlet 515 514 self.updatePortalTabsPageSection() 516 515 517 516 # issue portal status message 518 517 self.kss_issueMessage(message) 519 518 520 519 @kssaction 521 520 def kss_toggleRootsVisibility(self, id, checked='0'): … … 523 522 portal = getMultiAdapter((aq_inner(self.context), self.request), 524 523 name='plone_portal_state').portal() 525 524 526 525 # remove prefix, added for making ids on configlet unique ("roottabs_") 527 526 obj_id = id[len("roottabs_"):] 528 527 529 528 if obj_id not in portal.objectIds(): 530 529 raise KSSExplicitError, \ 531 530 _(u"Object with '${id}' id doesn't exist in portal root.", 532 531 mapping={'id': obj_id}) 533 532 534 533 if checked == '1': 535 534 checked = True 536 535 else: 537 536 checked = False 538 537 539 538 portal[obj_id].update(excludeFromNav=not checked) 540 539 541 540 # update client 542 541 ksscore = self.getCommandSet("core") … … 550 549 message = _(u"'${id}' object was excluded from navigation.", 551 550 mapping={'id':obj_id}) 552 551 553 552 # update global-sections viewlet 554 553 self.updatePortalTabsPageSection() 555 554 556 555 # issue portal status message 557 556 self.kss_issueMessage(message) 558 557 559 558 @kssaction 560 559 def kss_toggleActionsVisibility(self, id, checked='0', cat_name=None): … … 564 563 self.updateAction(act_id, cat_name, 565 564 {'id': act_id, 'visible': (checked == '1') or False}) 566 565 567 566 # update client 568 567 ksscore = self.getCommandSet("core") … … 577 576 mapping={'id':act_id}) 578 577 self.updatePage(cat_name) 579 578 580 579 # issue portal status message 581 580 self.kss_issueMessage(message) 582 581 583 582 @kssaction 584 583 def kss_deleteAction(self, id, cat_name): … … 587 586 act_id, category, action = self.kss_validateAction(id, cat_name) 588 587 self.deleteAction(act_id, cat_name) 589 588 590 589 # update client 591 590 ksscore = self.getCommandSet("core") … … 593 592 # we need kukit js action/command plugin 594 593 ksscore.deleteNode(ksscore.getHtmlIdSelector(id)) 595 594 596 595 # update different sections of page depending on actions category 597 596 self.updatePage(cat_name) 598 597 599 598 # issue portal status message 600 599 self.kss_issueMessage(_(u"'${id}' action successfully removed.", 601 600 mapping={'id':act_id})) 602 601 603 602 @kssaction 604 603 def kss_addAction(self, cat_name): … … 606 605 # extract posted data 607 606 id, ie7bad_category, data = self.parseAddForm(self.request.form) 608 607 609 608 # validate posted data 610 609 errors = self.validateActionFields(cat_name, data) 611 610 612 611 # if not errors find (or create) category and set action to it 613 612 ksscore = self.getCommandSet('core') … … 615 614 if not errors: 616 615 action = self.addAction(cat_name, data) 617 616 618 617 # update client 619 618 # add one more action to actions list … … 621 620 ksscore.insertHTMLAsLastChild(ksscore.getHtmlIdSelector('tabslist'), 622 621 content) 623 622 624 623 # update reorder controls 625 624 #self.kss_checkReorderControls(cat_name) 626 625 627 626 # hide adding form 628 627 ksscore.removeClass(ksscore.getHtmlIdSelector('addaction'), … … 631 630 ksscore.getCssSelector('form[name=addaction_form] ' 632 631 '.headerAdvanced'), collapse='true') 633 632 634 633 # set client state var 'plonetabs-addingTitle' to empty 635 634 # string for correct id autogeneration functionality 636 635 ksscore.setStateVar('plonetabs-addingTitle', '') 637 636 638 637 # reset adding form 639 638 self.kss_resetForm(ksscore.getHtmlIdSelector('addaction')) 640 639 641 640 # remove focus from name input 642 641 self.kss_blur(ksscore.getHtmlIdSelector('actname')) 643 642 644 643 message = _(u"'${id}' action successfully added.", 645 644 mapping={'id':action.id}) 646 645 msgtype = "info" 647 646 648 647 # update page 649 648 self.updatePage(cat_name) … … 654 653 ksscore.getCssSelector('form[name=addaction_form] ' 655 654 '.headerAdvanced'), collapse='false') 656 655 657 656 message = _(u"Please correct the indicated errors.") 658 657 msgtype = "error" 659 658 660 659 # update errors on client form 661 660 self.kss_issueErrors(errors) 662 661 663 662 # issue portal status message 664 663 self.kss_issueMessage(message, msgtype) 665 664 666 665 @kssaction 667 666 def kss_hideAddForm(self): … … 669 668 # no server changes, only update client 670 669 ksscore = self.getCommandSet("core") 671 670 672 671 # hide form itself 673 672 ksscore.removeClass(ksscore.getHtmlIdSelector('addaction'), 'adding') 674 673 675 674 # collapse advanced section 676 675 self.kss_toggleCollapsible( 677 676 ksscore.getCssSelector('form[name=addaction_form] .headerAdvanced'), 678 677 collapse='true') 679 678 680 679 # reset form inputs 681 680 self.kss_resetForm(ksscore.getHtmlIdSelector('addaction')) 682 681 683 682 # set client state var 'plonetabs-addingTitle' to empty string for 684 683 # correct id autogeneration functionality 685 684 ksscore.setStateVar('plonetabs-addingTitle', '') 686 685 687 686 # remove form errors if such exist 688 687 self.kss_issueErrors({}) 689 688 690 689 # issue portal status message 691 690 self.kss_issueMessage(_(u"Adding canceled.")) 692 691 693 692 @kssaction 694 693 def kss_showEditForm(self, id, cat_name): 695 694 """Show edit form for given action""" 696 695 act_id, category, action = self.kss_validateAction(id, cat_name) 697 696 698 697 # fetch data 699 698 action_info = self.copyAction(action) 700 699 action_info["editing"] = True 701 700 702 701 # update client 703 702 ksscore = self.getCommandSet("core") 704 703 content = self.getActionsList(category=cat_name, tabs=[action_info,]) 705 704 ksscore.replaceHTML(ksscore.getHtmlIdSelector(id), content) 706 705 707 706 # focus name field 708 707 ksscore.focus( 709 708 ksscore.getCssSelector("#%s input[name=title_%s]" % (id, act_id))) 710 709 711 710 # issue portal status message 712 711 self.kss_issueMessage(_(u"Fill in required fields and click on Add.")) 713 712 714 713 @kssaction 715 714 def kss_hideEditForm(self, id, cat_name): 716 715 """Hide edit form for given action""" 717 716 act_id, category, action = self.kss_validateAction(id, cat_name) 718 717 719 718 # update client 720 719 ksscore = self.getCommandSet("core") 721 720 content = self.getActionsList(category=cat_name, tabs=[action,]) 722 721 ksscore.replaceHTML(ksscore.getHtmlIdSelector(id), content) 723 722 724 723 # issue portal status message 725 724 self.kss_issueMessage(_(u"Changes discarded.")) 726 725 727 726 @kssaction 728 727 def kss_editAction(self): 729 728 """Update action's properties""" 730 729 id, cat_name, data = self.parseEditForm(self.request.form) 731 730 732 731 # get category and action to edit 733 732 category = self.getActionCategory(cat_name) 734 733 action = category[id] 735 734 736 735 # validate posted data 737 736 errors = self.validateActionFields(cat_name, data, 738 737 allow_dup=(id == data['id'])) 739 738 740 739 html_id = '%s%s%s' % (self.prefix, id, self.sufix) 741 740 ksscore = self.getCommandSet('core') … … 743 742 if not errors: 744 743 action = self.updateAction(id, cat_name, data) 745 744 746 745 # update client 747 746 # replace action item with updated one 748 747 content = self.getActionsList(category=cat_name, tabs=[action,]) 749 748 ksscore.replaceHTML(ksscore.getHtmlIdSelector(html_id), content) 750 749 751 750 message = _(u"'${id}' action successfully updated.", 752 751 mapping={'id':action.id}) 753 752 msgtype = "info" 754 753 755 754 # update page 756 755 self.updatePage(cat_name) … … 758 757 # issue error messages 759 758 self.kss_issueErrors(errors, editform=id) 760 759 761 760 # expand advanced section if there are errors in id, 762 761 # action url or condition … … 766 765 ksscore.getCssSelector('#%s .headerAdvanced' % html_id), 767 766 collapse='false') 768 767 769 768 message = _(u"Please correct the indicated errors.") 770 769 msgtype = "error" 771 770 772 771 # issue portal status message 773 772 self.kss_issueMessage(message, msgtype) 774 773 775 774 @kssaction 776 775 def kss_orderActions(self): … … 779 778 cat_name = form['cat_name'] 780 779 category = self.getActionCategory(cat_name) 781 780 782 781 # decode URI components and collect ids from request 783 782 components = urllib.unquote(form['actions']).split('&') … … 787 786 ids = [component[len(self.prefix):-len(self.sufix)] 788 787 for component in components] 789 788 790 789 # do actual sorting 791 790 category.moveObjectsByDelta(ids, -len(category.objectIds())) 792 791 793 792 # update client 794 793 self.updatePage(cat_name) 795 794 796 795 # issue portal status message 797 796 self.kss_issueMessage(_(u"Actions successfully sorted.")) 798 797 799 798 # 800 799 # Utility Methods 801 800 # 802 801 803 802 def fixExpression(self, expr): 804 803 """Fix expression appropriately for tal format""" … … 814 813 else: 815 814 return 'string:${object_url}/%s' % expr 816 815 817 816 def copyAction(self, action): 818 817 """Copy action to dictionary""" … … 821 820 action_info[attr] = getattr(action, attr) 822 821 return action_info 823 822 824 823 def validateActionFields(self, cat_name, data, allow_dup=False): 825 824 """Check action fields on validity""" 826 825 errors = {} 827 826 828 827 if allow_dup: 829 828 # create dummy category to avoid id … … 833 832 # get or create (if necessary) actions category 834 833 category = self.getOrCreateCategory(cat_name) 835 834 836 835 # validate action id 837 836 chooser = INameChooser(category) … … 840 839 except Exception, e: 841 840 errors['id'] = self._formatError(e, **{'id':data['id']}) 842 841 843 842 # validate action name 844 843 if not data['title'].strip(): 845 844 errors['title'] = _(u"Empty or invalid title specified") 846 845 847 846 # validate condition expression 848 847 if data['available_expr']: … … 855 854 mapping['expr_type'] = data['available_expr'][:idx] 856 855 errors["available_expr"] = self._formatError(e, **mapping) 857 856 858 857 # validate action expression 859 858 if data['url_expr']: … … 866 865 mapping['expr_type'] = data['url_expr'][:idx] 867 866 errors["url_expr"] = self._formatError(e, **mapping) 868 867 869 868 return errors 870 869 871 870 def _formatError(self, message, **kw): 872 871 """Make error message a little bit prettier to ease translation""" … … 881 880 message = message.strip() 882 881 return _(unicode(message, charset), mapping=mapping) 883 882 884 883 def processErrors(self, errors, prefix='', sufix=''): 885 """Add prefixes, sufixes to error ids 884 """Add prefixes, sufixes to error ids 886 885 This is necessary during edit form validation, 887 886 because every edit form on the page has it's own sufix (id) … … 889 888 if not (prefix or sufix): 890 889 return errors 891 890 892 891 result = {} 893 892 for key, value in errors.items(): 894 893 result['%s%s%s' % (prefix, key, sufix)] = value 895 894 896 895 return result 897 896 898 897 def parseEditForm(self, form): 899 898 """Extract all needed fields from edit form""" … … 902 901 id = form['orig_id'] 903 902 category = form['category'] 904 903 905 904 # preprocess 'visible' field (checkbox needs special checking) 906 905 if form.has_key('visible_%s' % id): … … 908 907 else: 909 908 form['visible_%s' % id] = False 910 909 911 910 # collect all action fields 912 911 for attr in ACTION_ATTRS: 913 912 info[attr] = form['%s_%s' % (attr, id)] 914 913 915 914 return (id, category, info) 916 915 917 916 def parseAddForm(self, form): 918 917 """Extract all needed fields from add form""" … … 920 919 id = form['id'] 921 920 category = form['category'] 922 921 923 922 # preprocess 'visible' field (checkbox needs special checking) 924 923 if form.has_key('visible') and form['visible']: … … 926 925 else: 927 926 form['visible'] = False 928 927 929 928 # fix expression fields 930 929 form['url_expr'] = self.fixExpression(form['url_expr']) 931 930 932 931 # collect all action fields 933 932 for attr in ACTION_ATTRS: 934 933 info[attr] = form[attr] 935 934 936 935 return (id, category, info) 937 936 938 937 def getActionCategory(self, name): 939 938 portal_actions = getToolByName(self.context, 'portal_actions') 940 939 return portal_actions[name] 941 940 942 941 def getOrCreateCategory(self, name): 943 942 """Get or create (if necessary) category""" … … 948 947 portal_actions._setObject(name, ActionCategory(name)) 949 948 return self.getActionCategory(name) 950 949 951 950 def setSiteProperties(self, **kw): 952 951 """Change site_properties""" … … 955 954 site_properties.manage_changeProperties(**kw) 956 955 return True 957 956 958 957 # 959 958 # Utility methods for the kss actions management 960 959 # 961 960 962 961 def kss_validateAction(self, id, cat_name): 963 962 """Check whether action with given id exists in cat_name category""" … … 968 967 _(u"'${cat_name}' action category does not exist.", 969 968 mapping={'cat_name': cat_name}) 970 969 971 970 # extract action id from given list item id on client 972 971 action_id = self.sufix and id[len(self.prefix):-len(self.sufix)] or \ … … 978 977 _(u"No '${id}' action in '${cat_name}' category.", 979 978 mapping={'id': action_id, 'cat_name': cat_name}) 980 979 981 980 return (action_id, category, action) 982 981 983 982 def kss_issueErrors(self, errors, editform=False, fields=ACTION_ATTRS): 984 983 """Display error messages on the client""" … … 988 987 self.kss_issueFieldError(ksscore, field, 989 988 errors.get(field, False), editform, ts) 990 989 991 990 def kss_issueFieldError(self, ksscore, name, error, editform, ts): 992 991 """Issue this error message for the field""" … … 1011 1010 ksscore.clearChildNodes(field_error_selector) 1012 1011 ksscore.removeClass(field_selector, 'error') 1013 1012 1014 1013 def kss_toggleCollapsible(self, selector, collapsed=None, 1015 1014 expanded=None, collapse=None): … … 1025 1024 if collapse is not None: 1026 1025 data = command.addParam('collapse', collapse) 1027 1026 1028 1027 def kss_resetForm(self, selector): 1029 1028 """KSS Server command to reset form on client""" 1030 1029 command = self.commands.addCommand('plonetabs-resetForm', selector) 1031 1030 1032 1031 def kss_blur(self, selector): 1033 1032 """KSS Server command to remove focus from input""" 1034 1033 command = self.commands.addCommand('plonetabs-blur', selector) 1035 1034 1036 1035 def kss_replaceOrInsert(self, selector, parentSelector, html, 1037 1036 withKssSetup='True', alternativeHTML='', … … 1055 1054 data = command.addParam('positionSelectorType', 1056 1055 positionSelectorType) 1057 1056 1058 1057 def kss_issueMessage(self, message, msgtype="info"): 1059 1058 """"Issues portal status message and removes it afte 10 seconds""" … … 1065 1064 cmd_name='setStyle', name='display', value='none' 1066 1065 ) 1067 1066 1068 1067 def kss_timeout(self, selector, **kw): 1069 1068 """KSS Server command to execute plonetabs-timeout client action""" 1070 1069 command = self.commands.addCommand('plonetabs-timeout', selector, **kw) 1071 1070 1072 1071 def renderViewlet(self, manager, name): 1073 1072 if isinstance(manager, basestring): … … 1079 1078 renderer.update() 1080 1079 return renderer.render() 1081 1080 1082 1081 # 1083 1082 # Basic API to work with portal actions tool in a more pleasent way 1084 1083 # 1085 1084 1086 1085 def addAction(self, cat_name, data): 1087 1086 """Create and add new action to category with given name""" … … 1091 1090 category._setObject(id, action) 1092 1091 return action 1093 1092 1094 1093 def updateAction(self, id, cat_name, data): 1095 1094 """Update action with given id and category""" 1096 1095 new_id = data.pop('id') 1097 1096 category = self.getActionCategory(cat_name) 1098 1097 1099 1098 # rename action if necessary 1100 1099 if id != new_id: 1101 1100 category.manage_renameObject(id, new_id) 1102 1101 1103 1102 # get action 1104 1103 action = category[new_id] 1105 1104 1106 1105 # update action properties 1107 1106 for attr in data.keys(): 1108 1107 if data.has_key(attr): 1109 1108 action._setPropValue(attr, data[attr]) 1110 1109 1111 1110 return action 1112 1111 1113 1112 def deleteAction(self, id, cat_name): 1114 1113 """Delete action with given id from given category""" … … 1116 1115 category.manage_delObjects(ids=[id,]) 1117 1116 return True 1118 1117 1119 1118 def moveAction(self, id, cat_name, steps=0): 1120 1119 """Move action by a given steps""" … … 1127 1126 return True 1128 1127 return False 1129 1128 1130 1129 # 1131 1130 # KSS Methods that are used to update different parts of the page 1132 1131 # accordingly to category 1133 1132 # 1134 1133 1135 1134 def updatePage(self, category): 1136 1135 """Seek for according method in class and calls it if found … … 1142 1141 if hasattr(self, method_name): 1143 1142 getattr(self, method_name)() 1144 1143 1145 1144 def updatePortalTabsPageSection(self): 1146 1145 """Method for updating global-sections on client""" … … 1151 1150 withKssSetup='False', 1152 1151 selectorType='htmlid') 1153 1152 1154 1153 def updateSiteActionsPageSection(self): 1155 1154 """Method for updating site action on client""" … … 1164 1163 positionSelector="portal-searchbox", 1165 1164 positionSelectorType="htmlid") 1166 1165 1167 1166 #ksszope = self.getCommandSet("zope") 1168 1167 #ksszope.refreshViewlet( … … 1170 1169 #"plone.portalheader", 1171 1170 #"plone.site_actions") 1172 1171 1173 1172 def updateUserPageSection(self): 1174 1173 """Method for updating site action on client""" … … 1181 1180 1182 1181 class PloneTabsMode(BrowserView): 1183 1182 1184 1183 def __call__(self): 1185 1184 mode = self.request.get(cookie_name, False)
Note: See TracChangeset
for help on using the changeset viewer.