Home | Trees | Indices | Help |
|
---|
|
1 # Copyright 2006 James Tauber and contributors 2 # Copyright (C) 2009 Luke Kenneth Casson Leighton <lkcl@lkcl.net> 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of the License at 7 # 8 # http://www.apache.org/licenses/LICENSE-2.0 9 # 10 # Unless required by applicable law or agreed to in writing, software 11 # distributed under the License is distributed on an "AS IS" BASIS, 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 import sys 16 from __pyjamas__ import JS 17 from pyjamas import Factory 18 if sys.platform not in ['mozilla', 'ie6', 'opera', 'oldmoz', 'safari']: 19 from __pyjamas__ import get_main_frame 20 21 from pyjamas import DOM 22 from __pyjamas__ import JS 23 24 from SimplePanel import SimplePanel 25 from pyjamas.ui import Event 26 from EventObject import EventObject 27 38 45 46 FormPanel_formId = 0 4749 ENCODING_MULTIPART = "multipart/form-data" 50 ENCODING_URLENCODED = "application/x-www-form-urlencoded" 51 METHOD_GET = "get" 52 METHOD_POST = "post" 53210 211 Factory.registerClass('pyjamas.ui.FormPanel', FormPanel) 21255 global FormPanel_formId 56 57 if hasattr(target, "getName"): 58 target = target.getName() 59 60 if kwargs.has_key('Element'): 61 element = kwargs.pop('Element') 62 else: 63 element = DOM.createForm() 64 65 self.formHandlers = [] 66 self.iframe = None 67 self.__formAction = None 68 69 FormPanel_formId += 1 70 formName = "FormPanel_" + str(FormPanel_formId) 71 DOM.setAttribute(element, "target", formName) 72 DOM.setInnerHTML(element, """<iframe name='%s' src="javascript:''">"""\ 73 % formName) 74 self.iframe = DOM.getFirstChild(element) 75 76 DOM.setIntStyleAttribute(self.iframe, "width", 0) 77 DOM.setIntStyleAttribute(self.iframe, "height", 0) 78 DOM.setIntStyleAttribute(self.iframe, "border", 0) 79 80 if target is not None: 81 kwargs['Target'] = target 82 83 SimplePanel.__init__(self, element, **kwargs) 84 85 try: 86 self.sinkEvents(Event.ONLOAD) 87 except: 88 # MSHTML doesn't have form.onload, 89 # it has onreadystatechange. 90 pass9193 self.formHandlers.append(handler)94 97 98 # FormPanelImpl.getEncoding100 elem = self.getElement() 101 if hasattr(elem, 'enctype'): 102 return elem.enctype 103 return elem.encoding104 107 110 111 # FormPanelImpl.getTextContents113 try: 114 if not iframe.contentDocument: 115 return None 116 return DOM.getInnerHTML(iframe.contentDocument.body) 117 except: 118 return None119121 print form, event, something 122 if not self.__formAction: 123 return 124 self._listener.onFrameLoad()125127 print form, event, something 128 try: 129 event = get_main_frame().gobject_wrap(event) # webkit HACK! 130 form = get_main_frame().gobject_wrap(form) # webkit HACK! 131 except: 132 pass 133 134 if self.iframe: 135 self.__formAction = form.action 136 return self._listener.onFormSubmit()137 138 # FormPanelImpl.hookEvents140 # TODO: might have to fix this, use DOM.set_listener() 141 self._listener = listener 142 if iframe: 143 wf = mf = get_main_frame() 144 self._onload_listener = mf.addEventListener(iframe, "load", 145 self._onload) 146 147 self._onsubmit_listener = mf.addEventListener(form, "onsubmit", 148 self._onsubmit)149151 event = FormSubmitEvent(self) 152 for handler in self.formHandlers: 153 handler.onSubmit(event) 154 155 return not event.isCancelled()156158 event = FormSubmitCompleteEvent(self, self.getTextContents(self.iframe)) 159 for handler in self.formHandlers: 160 handler.onSubmitComplete(event)161163 self.formHandlers.remove(handler)164 167 168 # FormPanelImpl.setEncoding170 form = self.getElement() 171 if hasattr(form, 'enctype'): 172 form.enctype = encodingType 173 form.encoding = encodingType174 177179 event = FormSubmitEvent(self) 180 for handler in self.formHandlers: 181 handler.onSubmit(event) 182 183 if event.isCancelled(): 184 return 185 186 self.submitImpl(self.getElement(), self.iframe)187 188 # FormPanelImpl.submit 193 197 201 204 205 # FormPanelImpl.unhookEvents
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Wed Jun 16 12:42:36 2010 | http://epydoc.sourceforge.net |