!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 *
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
8 *
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
13 *
14 * The Original Code is Form Properties Dialog.
15 *
16 * The Initial Developer of the Original Code is
17 * Neil Rashbrook.
18 * Portions created by the Initial Developer are Copyright (C) 2001
19 * the Initial Developer. All Rights Reserved.
20 *
21 * Contributor(s): Neil Rashbrook <neil@parkwaycc.co.uk>
22 *
23 * Alternatively, the contents of this file may be used under the terms of
24 * either the GNU General Public License Version 2 or later (the "GPL"), or
25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 * in which case the provisions of the GPL or the LGPL are applicable instead
27 * of those above. If you wish to allow use of your version of this file only
28 * under the terms of either the GPL or the LGPL, and not to allow others to
29 * use your version of this file under the terms of the MPL, indicate your
30 * decision by deleting the provisions above and replace them with the notice
31 * and other provisions required by the GPL or the LGPL. If you do not delete
32 * the provisions above, a recipient may use your version of this file under
33 * the terms of any one of the MPL, the GPL or the LGPL.
34 *
35 * ***** END LICENSE BLOCK ***** */
36
37 var gForm;
38 var insertNew;
39 var formElement;
40 var formActionWarning;
41
Startup
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
42 function Startup()
43 {
44 var editor = GetCurrentEditor();
45 if (!editor)
46 {
47 dump("Failed to get active editor!\n");
48 window.close();
49 return;
50 }
51
52 gForm = {
53 Name: document.getElementById("FormName"),
54 Action: document.getElementById("FormAction"),
55 Method: document.getElementById("FormMethod"),
56 EncType: document.getElementById("FormEncType"),
57 Target: document.getElementById("FormTarget")
58 }
59 gDialog.MoreSection = document.getElementById("MoreSection");
60 gDialog.MoreFewerButton = document.getElementById("MoreFewerButton");
61 gDialog.RemoveForm = document.getElementById("RemoveForm")
62
63 // Get a single selected form element
64 const kTagName = "form";
65 try {
66 formElement = editor.getSelectedElement(kTagName);
67 if (!formElement)
68 formElement = editor.getElementOrParentByTagName(kTagName, editor.selection.anchorNode);
69 if (!formElement)
70 formElement = editor.getElementOrParentByTagName(kTagName, editor.selection.focusNode);
71 } catch (e) {}
72
73 if (formElement)
74 {
75 // We found an element and don't need to insert one
76 insertNew = false;
77 formActionWarning = formElement.hasAttribute("action");
78 }
79 else
80 {
81 insertNew = true;
82 formActionWarning = true;
83
84 // We don't have an element selected,
85 // so create one with default attributes
86 try {
87 formElement = editor.createElementWithDefaults(kTagName);
88 } catch (e) {}
89
90 if (!formElement)
91 {
92 dump("Failed to get selected element or create a new one!\n");
93 window.close();
94 return;
95 }
96 // Hide button removing existing form
97 gDialog.RemoveForm.hidden = true;
98 }
99
100 // Make a copy to use for AdvancedEdit
101 globalElement = formElement.cloneNode(false);
102
103 InitDialog();
104
105 InitMoreFewer();
106
107 SetTextboxFocus(gForm.Name);
108
109 SetWindowLocation();
110 }
111
InitDialog
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
112 function InitDialog()
113 {
114 for (var attribute in gForm)
115 gForm[attribute].value = globalElement.getAttribute(attribute);
116 }
117
RemoveForm
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
118 function RemoveForm()
119 {
120 RemoveBlockContainer(formElement);
121 SaveWindowLocation();
122 window.close();
123 }
124
ValidateData
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
125 function ValidateData()
126 {
127 for (var attribute in gForm)
128 {
129 if (gForm[attribute].value)
130 globalElement.setAttribute(attribute, gForm[attribute].value);
131 else
132 globalElement.removeAttribute(attribute);
133 }
134 return true;
135 }
136
onAccept
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
137 function onAccept()
138 {
139 if (formActionWarning && !gForm.Action.value)
140 {
141 AlertWithTitle(GetString("Alert"), GetString("NoFormAction"));
142 gForm.Action.focus();
143 formActionWarning = false;
144 return false;
145 }
146 // All values are valid - copy to actual element in doc or
147 // element created to insert
148 ValidateData();
149
150 var editor = GetCurrentEditor();
151
152 editor.cloneAttributes(formElement, globalElement);
153
154 if (insertNew)
155 InsertElementAroundSelection(formElement);
156
157 SaveWindowLocation();
158
159 return true;
160 }