| 1 | ################################################################################
|
|---|
| 2 | # zmslinkcontainer.py
|
|---|
| 3 | #
|
|---|
| 4 | # This program is free software; you can redistribute it and/or
|
|---|
| 5 | # modify it under the terms of the GNU General Public License
|
|---|
| 6 | # as published by the Free Software Foundation; either version 2
|
|---|
| 7 | # of the License, or (at your option) any later version.
|
|---|
| 8 | #
|
|---|
| 9 | # This program is distributed in the hope that it will be useful,
|
|---|
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 12 | # GNU General Public License for more details.
|
|---|
| 13 | #
|
|---|
| 14 | # You should have received a copy of the GNU General Public License
|
|---|
| 15 | # along with this program; if not, write to the Free Software
|
|---|
| 16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|---|
| 17 | ################################################################################
|
|---|
| 18 |
|
|---|
| 19 | # Imports.
|
|---|
| 20 | from AccessControl import ClassSecurityInfo
|
|---|
| 21 | from App.special_dtml import HTMLFile
|
|---|
| 22 | import Globals
|
|---|
| 23 | import time
|
|---|
| 24 | import urllib
|
|---|
| 25 | # Product Imports.
|
|---|
| 26 | from zmscontainerobject import ZMSContainerObject
|
|---|
| 27 | import zmslinkelement
|
|---|
| 28 | import _globals
|
|---|
| 29 | import _zreferableitem
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 | ################################################################################
|
|---|
| 33 | ################################################################################
|
|---|
| 34 | ###
|
|---|
| 35 | ### Constructor
|
|---|
| 36 | ###
|
|---|
| 37 | ################################################################################
|
|---|
| 38 | ################################################################################
|
|---|
| 39 | def manage_addZMSLinkContainer(self, lang, _sort_id, REQUEST, RESPONSE):
|
|---|
| 40 | """ manage_addZMSLinkContainer """
|
|---|
| 41 |
|
|---|
| 42 | ##### Create ####
|
|---|
| 43 | id_prefix = _globals.id_prefix(REQUEST.get('id_prefix','e'))
|
|---|
| 44 | new_id = self.getNewId(id_prefix)
|
|---|
| 45 | obj = ZMSLinkContainer(new_id,_sort_id+1)
|
|---|
| 46 | self._setObject(obj.id, obj)
|
|---|
| 47 |
|
|---|
| 48 | obj = getattr(self,obj.id)
|
|---|
| 49 | ##### Object State ####
|
|---|
| 50 | obj.setObjStateNew(REQUEST)
|
|---|
| 51 | ##### Init Coverage ####
|
|---|
| 52 | coverage = self.getDCCoverage(REQUEST)
|
|---|
| 53 | if coverage.find('local.')==0:
|
|---|
| 54 | obj.setObjProperty('attr_dc_coverage',coverage)
|
|---|
| 55 | else:
|
|---|
| 56 | obj.setObjProperty('attr_dc_coverage','global.'+lang)
|
|---|
| 57 | ##### Init Properties ####
|
|---|
| 58 | obj.setObjProperty('active',1,lang)
|
|---|
| 59 | ##### VersionManager ####
|
|---|
| 60 | obj.onChangeObj(REQUEST)
|
|---|
| 61 |
|
|---|
| 62 | ##### Normalize Sort-IDs ####
|
|---|
| 63 | self.normalizeSortIds(id_prefix)
|
|---|
| 64 |
|
|---|
| 65 | # Return with message.
|
|---|
| 66 | message = self.getZMILangStr('MSG_INSERTED')%obj.display_type(REQUEST)
|
|---|
| 67 | RESPONSE.redirect('%s/%s/manage_main?lang=%s&manage_tabs_message=%s'%(self.absolute_url(),obj.id,lang,urllib.quote(message)))
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 | ################################################################################
|
|---|
| 71 | ################################################################################
|
|---|
| 72 | ###
|
|---|
| 73 | ### Class
|
|---|
| 74 | ###
|
|---|
| 75 | ################################################################################
|
|---|
| 76 | ################################################################################
|
|---|
| 77 | class ZMSLinkContainer(ZMSContainerObject):
|
|---|
| 78 |
|
|---|
| 79 | # Create a SecurityInfo for this class. We will use this
|
|---|
| 80 | # in the rest of our class definition to make security
|
|---|
| 81 | # assertions.
|
|---|
| 82 | security = ClassSecurityInfo()
|
|---|
| 83 |
|
|---|
| 84 | # Properties.
|
|---|
| 85 | # -----------
|
|---|
| 86 | meta_type = meta_id = "ZMSLinkContainer"
|
|---|
| 87 |
|
|---|
| 88 | # Management Options.
|
|---|
| 89 | # -------------------
|
|---|
| 90 | manage_options = (
|
|---|
| 91 | {'label': 'TAB_EDIT', 'action': 'manage_main'},
|
|---|
| 92 | {'label': 'TAB_HISTORY', 'action': 'manage_UndoVersionForm'},
|
|---|
| 93 | {'label': 'TAB_PREVIEW', 'action': 'preview_html'}, # empty string defaults to index_html
|
|---|
| 94 | )
|
|---|
| 95 |
|
|---|
| 96 | # Management Permissions.
|
|---|
| 97 | # -----------------------
|
|---|
| 98 | __authorPermissions__ = (
|
|---|
| 99 | 'manage','manage_main','manage_main_iframe','manage_workspace',
|
|---|
| 100 | 'manage_deleteObjs','manage_undoObjs',
|
|---|
| 101 | 'manage_properties','manage_changeProperties','manage_changeTempBlobjProperty',
|
|---|
| 102 | 'manage_moveObjUp','manage_moveObjDown','manage_moveObjToPos',
|
|---|
| 103 | 'manage_wfTransition', 'manage_wfTransitionFinalize',
|
|---|
| 104 | 'manage_ajaxZMIActions',
|
|---|
| 105 | 'manage_userForm','manage_user',
|
|---|
| 106 | )
|
|---|
| 107 | __ac_permissions__=(
|
|---|
| 108 | ('ZMS Author', __authorPermissions__),
|
|---|
| 109 | )
|
|---|
| 110 |
|
|---|
| 111 | # Management Interface.
|
|---|
| 112 | # ---------------------
|
|---|
| 113 | manage_main = HTMLFile('dtml/ZMSObject/manage_main', globals())
|
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 | ############################################################################
|
|---|
| 117 | ###
|
|---|
| 118 | ### Properties
|
|---|
| 119 | ###
|
|---|
| 120 | ############################################################################
|
|---|
| 121 |
|
|---|
| 122 | ############################################################################
|
|---|
| 123 | # ZMSLinkContainer.manage_changeProperties:
|
|---|
| 124 | #
|
|---|
| 125 | # Change LinkContainer properties.
|
|---|
| 126 | ############################################################################
|
|---|
| 127 | def manage_changeProperties(self, lang, REQUEST, RESPONSE):
|
|---|
| 128 | """ ZMSLinkContainer.manage_changeProperties """
|
|---|
| 129 |
|
|---|
| 130 | message = ''
|
|---|
| 131 |
|
|---|
| 132 | # Change.
|
|---|
| 133 | # -------
|
|---|
| 134 | if REQUEST.get('btn','') not in [ self.getZMILangStr('BTN_CANCEL'), self.getZMILangStr('BTN_BACK')]:
|
|---|
| 135 |
|
|---|
| 136 | ##### Object State #####
|
|---|
| 137 | self.setObjStateModified(REQUEST)
|
|---|
| 138 |
|
|---|
| 139 | ##### Properties ####
|
|---|
| 140 | # Attributes.
|
|---|
| 141 | self.setReqProperty('active',REQUEST)
|
|---|
| 142 | self.setReqProperty('attr_active_start',REQUEST)
|
|---|
| 143 | self.setReqProperty('attr_active_end',REQUEST)
|
|---|
| 144 | self.setReqProperty('align',REQUEST)
|
|---|
| 145 |
|
|---|
| 146 | ##### Change #####
|
|---|
| 147 | if REQUEST['btn'] == self.getZMILangStr('BTN_SAVE'):
|
|---|
| 148 | for ob in self.getChildNodes(REQUEST,['ZMSLinkElement']):
|
|---|
| 149 | id = ob.id
|
|---|
| 150 | url = REQUEST['url%s'%id]
|
|---|
| 151 | title = REQUEST['title%s'%id]
|
|---|
| 152 | description = REQUEST['description%s'%id]
|
|---|
| 153 | zmslinkelement.setZMSLinkElement(ob,title,url,description,REQUEST)
|
|---|
| 154 |
|
|---|
| 155 | ##### Add #####
|
|---|
| 156 | elif REQUEST['btn'] == self.getZMILangStr('BTN_INSERT'):
|
|---|
| 157 | title = REQUEST['_title']
|
|---|
| 158 | url = REQUEST['_url']
|
|---|
| 159 | description = REQUEST['_description']
|
|---|
| 160 | zmslinkelement.addZMSLinkElement(self,title,url,description,REQUEST)
|
|---|
| 161 |
|
|---|
| 162 | ##### VersionManager ####
|
|---|
| 163 | self.onChangeObj(REQUEST)
|
|---|
| 164 |
|
|---|
| 165 | # Return with message.
|
|---|
| 166 | message = self.getZMILangStr('MSG_CHANGED')
|
|---|
| 167 | return RESPONSE.redirect('manage_main?lang=%s&manage_tabs_message=%s'%(lang,urllib.quote(message)))
|
|---|
| 168 |
|
|---|
| 169 | else:
|
|---|
| 170 | # Return to parent.
|
|---|
| 171 | return RESPONSE.redirect('%s/manage_main?lang=%s#_%s'%(self.getParentNode().absolute_url(),lang,self.id))
|
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 | # --------------------------------------------------------------------------
|
|---|
| 175 | # ZMSLinkContainer.isPageElement
|
|---|
| 176 | # --------------------------------------------------------------------------
|
|---|
| 177 | def isPageElement( self):
|
|---|
| 178 | return self.getObjProperty('align',self.REQUEST) != 'NONE'
|
|---|
| 179 |
|
|---|
| 180 |
|
|---|
| 181 | ############################################################################
|
|---|
| 182 | ###
|
|---|
| 183 | ### HTML-Presentation
|
|---|
| 184 | ###
|
|---|
| 185 | ############################################################################
|
|---|
| 186 |
|
|---|
| 187 | # --------------------------------------------------------------------------
|
|---|
| 188 | # ZMSLinkContainer._getBodyContent:
|
|---|
| 189 | # --------------------------------------------------------------------------
|
|---|
| 190 | def _getBodyContent(self, REQUEST):
|
|---|
| 191 | # @see ZMSObject.getBodyContent
|
|---|
| 192 | v = self.metaobj_manager.renderTemplate( self)
|
|---|
| 193 | if v:
|
|---|
| 194 | return v
|
|---|
| 195 | # @deprecated after ZMS2 2.13.4.1569
|
|---|
| 196 | align = self.getObjProperty('align',REQUEST)
|
|---|
| 197 | css = []
|
|---|
| 198 | if align in [ 'LEFT', 'RIGHT']:
|
|---|
| 199 | css.append(align.lower())
|
|---|
| 200 | elif align in [ 'LEFT_FLOAT']:
|
|---|
| 201 | css.append('floatleft')
|
|---|
| 202 | elif align in [ 'RIGHT_FLOAT']:
|
|---|
| 203 | css.append('floatright')
|
|---|
| 204 | if css:
|
|---|
| 205 | bodyContent = self.renderShort(REQUEST)
|
|---|
| 206 | return '<div class="%s" id="%s">%s</div>'%(' '.join(css), self.id, bodyContent)
|
|---|
| 207 | return ''
|
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 | # --------------------------------------------------------------------------
|
|---|
| 211 | # ZMSLinkContainer.renderShort:
|
|---|
| 212 | # --------------------------------------------------------------------------
|
|---|
| 213 | security.declareProtected('View', 'renderShort')
|
|---|
| 214 | def renderShort(self, REQUEST):
|
|---|
| 215 | """
|
|---|
| 216 | Renders short presentation of link-container.
|
|---|
| 217 | """
|
|---|
| 218 | html = ''
|
|---|
| 219 | try:
|
|---|
| 220 | html = ''.join(
|
|---|
| 221 | map(lambda x: x.renderShort(REQUEST),
|
|---|
| 222 | filter(lambda x: x.isCommitted(REQUEST),
|
|---|
| 223 | self.getChildNodes(REQUEST,['ZMSLinkElement']))))
|
|---|
| 224 | html = '<div class="contentEditable" id="contentEditable_%s_%s">%s</div>'%(self.id,REQUEST['lang'],html)
|
|---|
| 225 | html = '<div class="zmiRenderShort">%s</div><!-- .zmiRenderShort -->'%html
|
|---|
| 226 | # Process html <form>-tags.
|
|---|
| 227 | html = _globals.form_quote(html,REQUEST)
|
|---|
| 228 | except:
|
|---|
| 229 | html = _globals.writeError(self,"[renderShort]")
|
|---|
| 230 | html = '<br/>'.join(html.split('\n'))
|
|---|
| 231 | # Return <html>.
|
|---|
| 232 | return html
|
|---|
| 233 |
|
|---|
| 234 |
|
|---|
| 235 | ############################################################################
|
|---|
| 236 | ###
|
|---|
| 237 | ### DOM-Methods
|
|---|
| 238 | ###
|
|---|
| 239 | ############################################################################
|
|---|
| 240 |
|
|---|
| 241 | # --------------------------------------------------------------------------
|
|---|
| 242 | # ZMSLinkContainer.getChildNodes:
|
|---|
| 243 | #
|
|---|
| 244 | # Returns a NodeList that contains all children of this node in correct
|
|---|
| 245 | # sort-order. If none, this is a empty NodeList.
|
|---|
| 246 | # --------------------------------------------------------------------------
|
|---|
| 247 | def getChildNodes(self, REQUEST={}, meta_types=None, reid=None):
|
|---|
| 248 | lang = REQUEST.get('lang',None)
|
|---|
| 249 | nodelist = ZMSContainerObject.getChildNodes(self,REQUEST,meta_types,reid)
|
|---|
| 250 | if lang is None:
|
|---|
| 251 | return nodelist
|
|---|
| 252 | else:
|
|---|
| 253 | return filter(lambda ob: ob.getDCCoverage(REQUEST).find("."+lang)>0,nodelist)
|
|---|
| 254 |
|
|---|
| 255 |
|
|---|
| 256 | # call this to initialize framework classes, which
|
|---|
| 257 | # does the right thing with the security assertions.
|
|---|
| 258 | Globals.InitializeClass(ZMSLinkContainer)
|
|---|
| 259 |
|
|---|
| 260 | ################################################################################
|
|---|