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 from __pyjamas__ import JS 16 from pyjamas import Factory, DOM 17 import pyjd 18 if pyjd.is_desktop: 19 from __pyjamas__ import get_main_frame 20 21 from pyjamas.ui.SimplePanel import SimplePanel 22 from pyjamas.ui import Event 23 from pyjamas.ui.EventObject import EventObject 24 35 42 43 FormPanel_formId = 0 4446 ENCODING_MULTIPART = "multipart/form-data" 47 ENCODING_URLENCODED = "application/x-www-form-urlencoded" 48 METHOD_GET = "get" 49 METHOD_POST = "post" 50207 208 Factory.registerClass('pyjamas.ui.FormPanel', 'FormPanel', FormPanel) 20952 global FormPanel_formId 53 54 if hasattr(target, "getName"): 55 target = target.getName() 56 57 if kwargs.has_key('Element'): 58 element = kwargs.pop('Element') 59 else: 60 element = DOM.createForm() 61 62 self.formHandlers = [] 63 self.iframe = None 64 self.__formAction = None 65 66 FormPanel_formId += 1 67 formName = "FormPanel_" + str(FormPanel_formId) 68 DOM.setAttribute(element, "target", formName) 69 DOM.setInnerHTML(element, """<iframe name='%s' src="javascript:''">"""\ 70 % formName) 71 self.iframe = DOM.getFirstChild(element) 72 73 DOM.setIntStyleAttribute(self.iframe, "width", 0) 74 DOM.setIntStyleAttribute(self.iframe, "height", 0) 75 DOM.setIntStyleAttribute(self.iframe, "border", 0) 76 77 if target is not None: 78 kwargs['Target'] = target 79 80 SimplePanel.__init__(self, element, **kwargs) 81 82 try: 83 self.sinkEvents(Event.ONLOAD) 84 except: 85 # MSHTML doesn't have form.onload, 86 # it has onreadystatechange. 87 pass8890 self.formHandlers.append(handler)91 94 95 # FormPanelImpl.getEncoding97 elem = self.getElement() 98 if hasattr(elem, 'enctype'): 99 return elem.enctype 100 return elem.encoding101 104 107 108 # FormPanelImpl.getTextContents110 try: 111 if not iframe.contentDocument: 112 return None 113 return DOM.getInnerHTML(iframe.contentDocument.body) 114 except: 115 return None116118 print form, event, something 119 if not self.__formAction: 120 return 121 self._listener.onFrameLoad()122124 print form, event, something 125 try: 126 event = get_main_frame().gobject_wrap(event) # webkit HACK! 127 form = get_main_frame().gobject_wrap(form) # webkit HACK! 128 except: 129 pass 130 131 if self.iframe is not None: 132 self.__formAction = form.action 133 return self._listener.onFormSubmit()134 135 # FormPanelImpl.hookEvents137 # TODO: might have to fix this, use DOM.set_listener() 138 self._listener = listener 139 if iframe is not None: 140 wf = mf = get_main_frame() 141 self._onload_listener = mf.addEventListener(iframe, "load", 142 self._onload) 143 144 self._onsubmit_listener = mf.addEventListener(form, "onsubmit", 145 self._onsubmit)146148 event = FormSubmitEvent(self) 149 for handler in self.formHandlers: 150 handler.onSubmit(event) 151 152 return not event.isCancelled()153155 event = FormSubmitCompleteEvent(self, self.getTextContents(self.iframe)) 156 for handler in self.formHandlers: 157 handler.onSubmitComplete(event)158160 self.formHandlers.remove(handler)161 164 165 # FormPanelImpl.setEncoding167 form = self.getElement() 168 if hasattr(form, 'enctype'): 169 form.enctype = encodingType 170 form.encoding = encodingType171 174176 event = FormSubmitEvent(self) 177 for handler in self.formHandlers: 178 handler.onSubmit(event) 179 180 if event.isCancelled(): 181 return 182 183 self.submitImpl(self.getElement(), self.iframe)184 185 # FormPanelImpl.submit 190 194 198 201 202 # FormPanelImpl.unhookEvents
Home | Trees | Indices | Help |
|
---|
http://epydoc.sourceforge.net |