!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 *
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * The Original Code is Mozilla Communicator client code, released
17 * March 31, 1998.
18 *
19 * The Initial Developer of the Original Code is
20 * Netscape Communications Corporation.
21 * Portions created by the Initial Developer are Copyright (C) 1998
22 * the Initial Developer. All Rights Reserved.
23 *
24 * Contributor(s):
25 * Jason Kersey (kerz@netscape.com)
26 *
27 * Alternatively, the contents of this file may be used under the terms of
28 * either the GNU General Public License Version 2 or later (the "GPL"), or
29 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
38 *
39 * ***** END LICENSE BLOCK ***** */
40
41 /* for xpconnect */
42 var walletpreview =
43 Components.classes
44 ["@mozilla.org/walletpreview/walletpreview-world;1"].createInstance();
45 walletpreview = walletpreview.QueryInterface(Components.interfaces.nsIWalletPreview);
46
47 var prefillList = [];
48 var fieldCount = 0;
49
50 function Startup() {
Startup
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
51
52 /* fetch the input */
53
54 var list = walletpreview.GetPrefillValue();
55 var BREAK = list[0];
56 prefillList = list.split(BREAK);
57
58 var menuPopup;
59 var count;
60
61 /* create the fill-in entries */
62
63 for (var i=1; i<prefillList.length-1; i+=3) {
64
65 if(prefillList[i] != 0) {
66 count = prefillList[i];
67 menuPopup = document.createElement("menupopup");
68 }
69 count--;
70 var menuItem = document.createElement("menuitem");
71 if (count == (prefillList[i]-1)) {
72 menuItem.setAttribute("selected", "true");
73 }
74 menuItem.setAttribute("label", prefillList[i+2]);
75
76 // Avoid making duplicate entries in the same menulist
77 var child = menuPopup.firstChild;
78 var alreadyThere = false;
79 while (child) {
80 if (child.getAttribute("label") == prefillList[i+2]) {
81 alreadyThere = true;
82 break;
83 }
84 child = child.nextSibling;
85 }
86 if (!alreadyThere) {
87 menuPopup.appendChild(menuItem);
88 }
89
90 if(count == 0) {
91 //create the menulist of form data options.
92 var menuList = document.createElement("menulist");
93 menuList.setAttribute("data", prefillList[i+1]);
94 menuList.setAttribute("id", "xx"+(++fieldCount));
95 menuList.setAttribute("allowevents", "true");
96 menuList.appendChild(menuPopup);
97
98 //create the checkbox for the menulist.
99 var localCheckBox = document.createElement("checkbox");
100 localCheckBox.setAttribute("id", "x"+fieldCount);
101 // Note: menulist name is deliberately chosen to be x + checkbox name in
102 // order to make it easy to get to menulist from associated checkbox
103 localCheckBox.setAttribute("oncommand", "UpdateMenuListEnable(this)");
104 localCheckBox.setAttribute("checked", "true");
105 localCheckBox.setAttribute("crop", "right");
106
107 //fix label so it only shows title of field, not any of the url.
108 var colonPos = prefillList[i+1].indexOf(':');
109 var checkBoxLabel;
110 if (colonPos != -1)
111 checkBoxLabel = prefillList[i+1].slice(colonPos + 1)
112 else
113 checkBoxLabel = prefillList[i+1];
114 localCheckBox.setAttribute("label", checkBoxLabel );
115
116 //append all the items into the row.
117 var row = document.createElement("row");
118 row.appendChild(localCheckBox);
119 row.appendChild(menuList);
120
121 var rows = document.getElementById("rows");
122 rows.appendChild(row);
123
124 // xul bug: if this is done earlier, it will result in a crash (???)
125 menuList.setAttribute("editable", "true");
126
127 }
128 }
129 }
130
131 function UpdateMenuListEnable(checkBox) {
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
132 var id = checkBox.getAttribute("id");
133 var menuList = document.getElementById("x" + id);
134 var menuItem = menuList.selectedItem;
135 if (checkBox.checked) {
136 menuList.removeAttribute("disabled");
137 menuList.setAttribute("editable", "true");
138 } else {
139 menuList.setAttribute("disabled", "true");
140 menuList.removeAttribute("editable");
141 }
142 menuList.selectedItem = menuItem;
143 }
144
145 function EncodeVerticalBars(s) {
EncodeVerticalBars
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
146 s = s.replace(/\^/g, "^1");
147 s = s.replace(/\|/g, "^2");
148 return s;
149 }
150
151 function Save() {
Save
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
152 var url = prefillList[prefillList.length-1];
153 var fillins = "";
154
155 for (var i=1; i<=fieldCount; i++) {
156 var menuList = document.getElementById("xx" + i);
157 if (menuList)
158 {
159 fillins += menuList.getAttribute("data") + "#*%$";
160 var localCheckBox = document.getElementById("x" + i);
161 if (localCheckBox.checked) {
162 fillins += menuList.value;
163 }
164 fillins += "#*%$";
165 }
166 }
167
168 var checkBox = document.getElementById("checkbox");
169 var checked = checkBox.checked;
170
171 var result = "|fillins|"+EncodeVerticalBars(fillins)+
172 "|url|"+EncodeVerticalBars(url)+"|skip|"+checked+"|";
173 walletpreview.SetValue(result, window);
174 return true;
175 }
176
177 function Cancel() {
Cancel
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
178 var list = prefillList[prefillList.length-2];
179 var result = "|list|"+list+"|fillins||url||skip|false|";
180 walletpreview.SetValue(result, window);
181 return true;
182 }
183
184 function doHelpButton() {
doHelpButton
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
185 openHelp("forms_prefill");
186 return true;
187 }