Changeset 3244 in products
- Timestamp:
- Jun 21, 2011 9:00:59 AM (14 years ago)
- Location:
- quintagroup.plonetabs/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.plonetabs/trunk
- Property svn:mergeinfo set to /quintagroup.plonetabs/branches/plone4:3076-3243
-
quintagroup.plonetabs/trunk/quintagroup/plonetabs/browser/plonetabs.py
r874 r3244 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 if 'portal_tabs' in actions: 433 actions_tabs = actions['portal_tabs'] 434 else: 435 actions_tabs = [] 436 return portal_tabs_view.topLevelTabs(actions=actions_tabs) 437 435 438 def selected_portal_tab(self): 436 439 """See global-sections viewlet""" … … 438 441 selected_tabs = selectedTabs('index_html', self.context, 439 442 self.portal_tabs()) 440 443 441 444 return selected_tabs['portal'] 442 445 443 446 ########################## 444 447 # … … 446 449 # 447 450 ########################## 448 451 449 452 @kssaction 450 453 def kss_insertModeLink(self): 451 454 """Insert link which allows change categories between plain and rich""" 452 455 ksscore = self.getCommandSet('core') 453 456 454 457 html = self.link_template() 455 458 target = ksscore.getCssSelector('.link-parent') 456 459 ksscore.insertHTMLAfter(target, html, withKssSetup='False') 457 460 458 461 @kssaction 459 462 def kss_changeCategory(self, cat_name): 460 463 """Change action category to manage""" 461 464 ksscore = self.getCommandSet('core') 462 465 463 466 # update actions list 464 467 actionslist = self.getActionsList(category=cat_name) 465 468 ksscore.replaceInnerHTML(ksscore.getHtmlIdSelector('tabslist'), 466 469 actionslist) 467 470 468 471 # update autogenerated sections 469 472 section = self.getAutoGenereatedSection(cat_name) … … 475 478 ksscore.replaceInnerHTML( 476 479 ksscore.getHtmlIdSelector('plonetabs-form-title'), title) 477 480 478 481 # update category hidden field on adding form 479 482 ksscore.setAttribute(ksscore.getCssSelector( … … 481 484 'value', 482 485 cat_name) 483 486 484 487 # update state variable 'plonetabs-category' on client 485 488 ksscore.setStateVar('plonetabs-category', cat_name) 486 489 487 490 # hide adding form 488 491 self.kss_hideAddForm() 489 492 490 493 # issue portal status message 491 494 self.kss_issueMessage(_(u"Category changed successfully.")) 492 495 493 496 @kssaction 494 497 def kss_toggleGeneratedTabs(self, field, checked='0'): … … 506 509 else: 507 510 message = _(u"Generated tabs switched off.") 508 511 509 512 # update client 510 513 ksscore = self.getCommandSet("core") 511 514 content = self.getGeneratedTabs() 512 515 ksscore.replaceInnerHTML(ksscore.getHtmlIdSelector('roottabs'), content) 513 516 514 517 # update global-sections viewlet 515 518 self.updatePortalTabsPageSection() 516 519 517 520 # issue portal status message 518 521 self.kss_issueMessage(message) 519 522 520 523 @kssaction 521 524 def kss_toggleRootsVisibility(self, id, checked='0'): … … 523 526 portal = getMultiAdapter((aq_inner(self.context), self.request), 524 527 name='plone_portal_state').portal() 525 528 526 529 # remove prefix, added for making ids on configlet unique ("roottabs_") 527 530 obj_id = id[len("roottabs_"):] 528 531 529 532 if obj_id not in portal.objectIds(): 530 533 raise KSSExplicitError, \ 531 534 _(u"Object with '${id}' id doesn't exist in portal root.", 532 535 mapping={'id': obj_id}) 533 536 534 537 if checked == '1': 535 538 checked = True 536 539 else: 537 540 checked = False 538 541 539 542 portal[obj_id].update(excludeFromNav=not checked) 540 543 541 544 # update client 542 545 ksscore = self.getCommandSet("core") … … 550 553 message = _(u"'${id}' object was excluded from navigation.", 551 554 mapping={'id':obj_id}) 552 555 553 556 # update global-sections viewlet 554 557 self.updatePortalTabsPageSection() 555 558 556 559 # issue portal status message 557 560 self.kss_issueMessage(message) 558 561 559 562 @kssaction 560 563 def kss_toggleActionsVisibility(self, id, checked='0', cat_name=None): … … 564 567 self.updateAction(act_id, cat_name, 565 568 {'id': act_id, 'visible': (checked == '1') or False}) 566 569 567 570 # update client 568 571 ksscore = self.getCommandSet("core") … … 577 580 mapping={'id':act_id}) 578 581 self.updatePage(cat_name) 579 582 580 583 # issue portal status message 581 584 self.kss_issueMessage(message) 582 585 583 586 @kssaction 584 587 def kss_deleteAction(self, id, cat_name): … … 587 590 act_id, category, action = self.kss_validateAction(id, cat_name) 588 591 self.deleteAction(act_id, cat_name) 589 592 590 593 # update client 591 594 ksscore = self.getCommandSet("core") … … 593 596 # we need kukit js action/command plugin 594 597 ksscore.deleteNode(ksscore.getHtmlIdSelector(id)) 595 598 596 599 # update different sections of page depending on actions category 597 600 self.updatePage(cat_name) 598 601 599 602 # issue portal status message 600 603 self.kss_issueMessage(_(u"'${id}' action successfully removed.", 601 604 mapping={'id':act_id})) 602 605 603 606 @kssaction 604 607 def kss_addAction(self, cat_name): … … 606 609 # extract posted data 607 610 id, ie7bad_category, data = self.parseAddForm(self.request.form) 608 611 609 612 # validate posted data 610 613 errors = self.validateActionFields(cat_name, data) 611 614 612 615 # if not errors find (or create) category and set action to it 613 616 ksscore = self.getCommandSet('core') … … 615 618 if not errors: 616 619 action = self.addAction(cat_name, data) 617 620 618 621 # update client 619 622 # add one more action to actions list … … 621 624 ksscore.insertHTMLAsLastChild(ksscore.getHtmlIdSelector('tabslist'), 622 625 content) 623 626 624 627 # update reorder controls 625 628 #self.kss_checkReorderControls(cat_name) 626 629 627 630 # hide adding form 628 631 ksscore.removeClass(ksscore.getHtmlIdSelector('addaction'), … … 631 634 ksscore.getCssSelector('form[name=addaction_form] ' 632 635 '.headerAdvanced'), collapse='true') 633 636 634 637 # set client state var 'plonetabs-addingTitle' to empty 635 638 # string for correct id autogeneration functionality 636 639 ksscore.setStateVar('plonetabs-addingTitle', '') 637 640 638 641 # reset adding form 639 642 self.kss_resetForm(ksscore.getHtmlIdSelector('addaction')) 640 643 641 644 # remove focus from name input 642 645 self.kss_blur(ksscore.getHtmlIdSelector('actname')) 643 646 644 647 message = _(u"'${id}' action successfully added.", 645 648 mapping={'id':action.id}) 646 649 msgtype = "info" 647 650 648 651 # update page 649 652 self.updatePage(cat_name) … … 654 657 ksscore.getCssSelector('form[name=addaction_form] ' 655 658 '.headerAdvanced'), collapse='false') 656 659 657 660 message = _(u"Please correct the indicated errors.") 658 661 msgtype = "error" 659 662 660 663 # update errors on client form 661 664 self.kss_issueErrors(errors) 662 665 663 666 # issue portal status message 664 667 self.kss_issueMessage(message, msgtype) 665 668 666 669 @kssaction 667 670 def kss_hideAddForm(self): … … 669 672 # no server changes, only update client 670 673 ksscore = self.getCommandSet("core") 671 674 672 675 # hide form itself 673 676 ksscore.removeClass(ksscore.getHtmlIdSelector('addaction'), 'adding') 674 677 675 678 # collapse advanced section 676 679 self.kss_toggleCollapsible( 677 680 ksscore.getCssSelector('form[name=addaction_form] .headerAdvanced'), 678 681 collapse='true') 679 682 680 683 # reset form inputs 681 684 self.kss_resetForm(ksscore.getHtmlIdSelector('addaction')) 682 685 683 686 # set client state var 'plonetabs-addingTitle' to empty string for 684 687 # correct id autogeneration functionality 685 688 ksscore.setStateVar('plonetabs-addingTitle', '') 686 689 687 690 # remove form errors if such exist 688 691 self.kss_issueErrors({}) 689 692 690 693 # issue portal status message 691 694 self.kss_issueMessage(_(u"Adding canceled.")) 692 695 693 696 @kssaction 694 697 def kss_showEditForm(self, id, cat_name): 695 698 """Show edit form for given action""" 696 699 act_id, category, action = self.kss_validateAction(id, cat_name) 697 700 698 701 # fetch data 699 702 action_info = self.copyAction(action) 700 703 action_info["editing"] = True 701 704 702 705 # update client 703 706 ksscore = self.getCommandSet("core") 704 707 content = self.getActionsList(category=cat_name, tabs=[action_info,]) 705 708 ksscore.replaceHTML(ksscore.getHtmlIdSelector(id), content) 706 709 707 710 # focus name field 708 711 ksscore.focus( 709 712 ksscore.getCssSelector("#%s input[name=title_%s]" % (id, act_id))) 710 713 711 714 # issue portal status message 712 715 self.kss_issueMessage(_(u"Fill in required fields and click on Add.")) 713 716 714 717 @kssaction 715 718 def kss_hideEditForm(self, id, cat_name): 716 719 """Hide edit form for given action""" 717 720 act_id, category, action = self.kss_validateAction(id, cat_name) 718 721 719 722 # update client 720 723 ksscore = self.getCommandSet("core") 721 724 content = self.getActionsList(category=cat_name, tabs=[action,]) 722 725 ksscore.replaceHTML(ksscore.getHtmlIdSelector(id), content) 723 726 724 727 # issue portal status message 725 728 self.kss_issueMessage(_(u"Changes discarded.")) 726 729 727 730 @kssaction 728 731 def kss_editAction(self): 729 732 """Update action's properties""" 730 733 id, cat_name, data = self.parseEditForm(self.request.form) 731 734 732 735 # get category and action to edit 733 736 category = self.getActionCategory(cat_name) 734 737 action = category[id] 735 738 736 739 # validate posted data 737 740 errors = self.validateActionFields(cat_name, data, 738 741 allow_dup=(id == data['id'])) 739 742 740 743 html_id = '%s%s%s' % (self.prefix, id, self.sufix) 741 744 ksscore = self.getCommandSet('core') … … 743 746 if not errors: 744 747 action = self.updateAction(id, cat_name, data) 745 748 746 749 # update client 747 750 # replace action item with updated one 748 751 content = self.getActionsList(category=cat_name, tabs=[action,]) 749 752 ksscore.replaceHTML(ksscore.getHtmlIdSelector(html_id), content) 750 753 751 754 message = _(u"'${id}' action successfully updated.", 752 755 mapping={'id':action.id}) 753 756 msgtype = "info" 754 757 755 758 # update page 756 759 self.updatePage(cat_name) … … 758 761 # issue error messages 759 762 self.kss_issueErrors(errors, editform=id) 760 763 761 764 # expand advanced section if there are errors in id, 762 765 # action url or condition … … 766 769 ksscore.getCssSelector('#%s .headerAdvanced' % html_id), 767 770 collapse='false') 768 771 769 772 message = _(u"Please correct the indicated errors.") 770 773 msgtype = "error" 771 774 772 775 # issue portal status message 773 776 self.kss_issueMessage(message, msgtype) 774 777 775 778 @kssaction 776 779 def kss_orderActions(self): … … 779 782 cat_name = form['cat_name'] 780 783 category = self.getActionCategory(cat_name) 781 784 782 785 # decode URI components and collect ids from request 783 786 components = urllib.unquote(form['actions']).split('&') … … 787 790 ids = [component[len(self.prefix):-len(self.sufix)] 788 791 for component in components] 789 792 790 793 # do actual sorting 791 794 category.moveObjectsByDelta(ids, -len(category.objectIds())) 792 795 793 796 # update client 794 797 self.updatePage(cat_name) 795 798 796 799 # issue portal status message 797 800 self.kss_issueMessage(_(u"Actions successfully sorted.")) 798 801 799 802 # 800 803 # Utility Methods 801 804 # 802 805 803 806 def fixExpression(self, expr): 804 807 """Fix expression appropriately for tal format""" … … 814 817 else: 815 818 return 'string:${object_url}/%s' % expr 816 819 817 820 def copyAction(self, action): 818 821 """Copy action to dictionary""" … … 821 824 action_info[attr] = getattr(action, attr) 822 825 return action_info 823 826 824 827 def validateActionFields(self, cat_name, data, allow_dup=False): 825 828 """Check action fields on validity""" 826 829 errors = {} 827 830 828 831 if allow_dup: 829 832 # create dummy category to avoid id … … 833 836 # get or create (if necessary) actions category 834 837 category = self.getOrCreateCategory(cat_name) 835 838 836 839 # validate action id 837 840 chooser = INameChooser(category) … … 840 843 except Exception, e: 841 844 errors['id'] = self._formatError(e, **{'id':data['id']}) 842 845 843 846 # validate action name 844 847 if not data['title'].strip(): 845 848 errors['title'] = _(u"Empty or invalid title specified") 846 849 847 850 # validate condition expression 848 851 if data['available_expr']: … … 855 858 mapping['expr_type'] = data['available_expr'][:idx] 856 859 errors["available_expr"] = self._formatError(e, **mapping) 857 860 858 861 # validate action expression 859 862 if data['url_expr']: … … 866 869 mapping['expr_type'] = data['url_expr'][:idx] 867 870 errors["url_expr"] = self._formatError(e, **mapping) 868 871 869 872 return errors 870 873 871 874 def _formatError(self, message, **kw): 872 875 """Make error message a little bit prettier to ease translation""" … … 881 884 message = message.strip() 882 885 return _(unicode(message, charset), mapping=mapping) 883 886 884 887 def processErrors(self, errors, prefix='', sufix=''): 885 """Add prefixes, sufixes to error ids 888 """Add prefixes, sufixes to error ids 886 889 This is necessary during edit form validation, 887 890 because every edit form on the page has it's own sufix (id) … … 889 892 if not (prefix or sufix): 890 893 return errors 891 894 892 895 result = {} 893 896 for key, value in errors.items(): 894 897 result['%s%s%s' % (prefix, key, sufix)] = value 895 898 896 899 return result 897 900 898 901 def parseEditForm(self, form): 899 902 """Extract all needed fields from edit form""" … … 902 905 id = form['orig_id'] 903 906 category = form['category'] 904 907 905 908 # preprocess 'visible' field (checkbox needs special checking) 906 909 if form.has_key('visible_%s' % id): … … 908 911 else: 909 912 form['visible_%s' % id] = False 910 913 911 914 # collect all action fields 912 915 for attr in ACTION_ATTRS: 913 916 info[attr] = form['%s_%s' % (attr, id)] 914 917 915 918 return (id, category, info) 916 919 917 920 def parseAddForm(self, form): 918 921 """Extract all needed fields from add form""" … … 920 923 id = form['id'] 921 924 category = form['category'] 922 925 923 926 # preprocess 'visible' field (checkbox needs special checking) 924 927 if form.has_key('visible') and form['visible']: … … 926 929 else: 927 930 form['visible'] = False 928 931 929 932 # fix expression fields 930 933 form['url_expr'] = self.fixExpression(form['url_expr']) 931 934 932 935 # collect all action fields 933 936 for attr in ACTION_ATTRS: 934 937 info[attr] = form[attr] 935 938 936 939 return (id, category, info) 937 940 938 941 def getActionCategory(self, name): 939 942 portal_actions = getToolByName(self.context, 'portal_actions') 940 943 return portal_actions[name] 941 944 942 945 def getOrCreateCategory(self, name): 943 946 """Get or create (if necessary) category""" … … 948 951 portal_actions._setObject(name, ActionCategory(name)) 949 952 return self.getActionCategory(name) 950 953 951 954 def setSiteProperties(self, **kw): 952 955 """Change site_properties""" … … 955 958 site_properties.manage_changeProperties(**kw) 956 959 return True 957 960 958 961 # 959 962 # Utility methods for the kss actions management 960 963 # 961 964 962 965 def kss_validateAction(self, id, cat_name): 963 966 """Check whether action with given id exists in cat_name category""" … … 968 971 _(u"'${cat_name}' action category does not exist.", 969 972 mapping={'cat_name': cat_name}) 970 973 971 974 # extract action id from given list item id on client 972 975 action_id = self.sufix and id[len(self.prefix):-len(self.sufix)] or \ … … 978 981 _(u"No '${id}' action in '${cat_name}' category.", 979 982 mapping={'id': action_id, 'cat_name': cat_name}) 980 983 981 984 return (action_id, category, action) 982 985 983 986 def kss_issueErrors(self, errors, editform=False, fields=ACTION_ATTRS): 984 987 """Display error messages on the client""" … … 988 991 self.kss_issueFieldError(ksscore, field, 989 992 errors.get(field, False), editform, ts) 990 993 991 994 def kss_issueFieldError(self, ksscore, name, error, editform, ts): 992 995 """Issue this error message for the field""" … … 1011 1014 ksscore.clearChildNodes(field_error_selector) 1012 1015 ksscore.removeClass(field_selector, 'error') 1013 1016 1014 1017 def kss_toggleCollapsible(self, selector, collapsed=None, 1015 1018 expanded=None, collapse=None): … … 1025 1028 if collapse is not None: 1026 1029 data = command.addParam('collapse', collapse) 1027 1030 1028 1031 def kss_resetForm(self, selector): 1029 1032 """KSS Server command to reset form on client""" 1030 1033 command = self.commands.addCommand('plonetabs-resetForm', selector) 1031 1034 1032 1035 def kss_blur(self, selector): 1033 1036 """KSS Server command to remove focus from input""" 1034 1037 command = self.commands.addCommand('plonetabs-blur', selector) 1035 1038 1036 1039 def kss_replaceOrInsert(self, selector, parentSelector, html, 1037 1040 withKssSetup='True', alternativeHTML='', … … 1055 1058 data = command.addParam('positionSelectorType', 1056 1059 positionSelectorType) 1057 1060 1058 1061 def kss_issueMessage(self, message, msgtype="info"): 1059 1062 """"Issues portal status message and removes it afte 10 seconds""" … … 1065 1068 cmd_name='setStyle', name='display', value='none' 1066 1069 ) 1067 1070 1068 1071 def kss_timeout(self, selector, **kw): 1069 1072 """KSS Server command to execute plonetabs-timeout client action""" 1070 1073 command = self.commands.addCommand('plonetabs-timeout', selector, **kw) 1071 1074 1072 1075 def renderViewlet(self, manager, name): 1073 1076 if isinstance(manager, basestring): … … 1079 1082 renderer.update() 1080 1083 return renderer.render() 1081 1084 1082 1085 # 1083 1086 # Basic API to work with portal actions tool in a more pleasent way 1084 1087 # 1085 1088 1086 1089 def addAction(self, cat_name, data): 1087 1090 """Create and add new action to category with given name""" … … 1091 1094 category._setObject(id, action) 1092 1095 return action 1093 1096 1094 1097 def updateAction(self, id, cat_name, data): 1095 1098 """Update action with given id and category""" 1096 1099 new_id = data.pop('id') 1097 1100 category = self.getActionCategory(cat_name) 1098 1101 1099 1102 # rename action if necessary 1100 1103 if id != new_id: 1101 1104 category.manage_renameObject(id, new_id) 1102 1105 1103 1106 # get action 1104 1107 action = category[new_id] 1105 1108 1106 1109 # update action properties 1107 1110 for attr in data.keys(): 1108 1111 if data.has_key(attr): 1109 1112 action._setPropValue(attr, data[attr]) 1110 1113 1111 1114 return action 1112 1115 1113 1116 def deleteAction(self, id, cat_name): 1114 1117 """Delete action with given id from given category""" … … 1116 1119 category.manage_delObjects(ids=[id,]) 1117 1120 return True 1118 1121 1119 1122 def moveAction(self, id, cat_name, steps=0): 1120 1123 """Move action by a given steps""" … … 1127 1130 return True 1128 1131 return False 1129 1132 1130 1133 # 1131 1134 # KSS Methods that are used to update different parts of the page 1132 1135 # accordingly to category 1133 1136 # 1134 1137 1135 1138 def updatePage(self, category): 1136 1139 """Seek for according method in class and calls it if found … … 1142 1145 if hasattr(self, method_name): 1143 1146 getattr(self, method_name)() 1144 1147 1145 1148 def updatePortalTabsPageSection(self): 1146 1149 """Method for updating global-sections on client""" … … 1151 1154 withKssSetup='False', 1152 1155 selectorType='htmlid') 1153 1156 1154 1157 def updateSiteActionsPageSection(self): 1155 1158 """Method for updating site action on client""" … … 1164 1167 positionSelector="portal-searchbox", 1165 1168 positionSelectorType="htmlid") 1166 1169 1167 1170 #ksszope = self.getCommandSet("zope") 1168 1171 #ksszope.refreshViewlet( … … 1170 1173 #"plone.portalheader", 1171 1174 #"plone.site_actions") 1172 1175 1173 1176 def updateUserPageSection(self): 1174 1177 """Method for updating site action on client""" … … 1181 1184 1182 1185 class PloneTabsMode(BrowserView): 1183 1186 1184 1187 def __call__(self): 1185 1188 mode = self.request.get(cookie_name, False)
Note: See TracChangeset
for help on using the changeset viewer.