2 var iconDropdown_wrapper;
4 var currentSelectedValue_;
6 var changesMade_ =
false;
7 var saveClicked_ =
false;
10 megaLibrary_ =
new Array();
11 makeServerRequest(
"");
14 function finishInit(){
16 iconTable_wrapper = document.getElementById(
"iconTable");
17 iconDropdown_wrapper = document.getElementById(
"iconDropdown");
18 save_wrapper = document.getElementById(
"save");
19 currentSelectedValue_ =
"";
24 function chooseIcon(){
25 iconDropdown_wrapper.innerHTML =
"";
26 var icon_list = document.createElement(
"select");
27 iconDropdown_wrapper.appendChild(icon_list);
32 var iconOption = document.createElement(
"option");
33 icon_list.appendChild(iconOption);
34 iconOption.value=
"select";
35 iconOption.innerHTML=
"Select";
37 iconOption = document.createElement(
"option");
38 icon_list.appendChild(iconOption);
39 iconOption.value=
"new";
40 iconOption.innerHTML=
"Create New Icon";
41 icon_list.setAttribute(
"onchange",
"iconSelected(this.value)");
43 for(a = 0; a < megaLibrary_.length; a++)
45 iconOption = document.createElement(
"option");
46 icon_list.appendChild(iconOption);
48 iconOption.innerHTML = megaLibrary_[a][0];
54 function checkForChanges(){
56 save_wrapper.innerHTML =
"";
57 var submitButton = document.createElement(
"button");
58 submitButton.setAttribute(
"onClick",
"submitChangesToServer()");
59 submitButton.innerHTML =
"Submit Changes to Server";
62 submitButton.disabled =
"true";
65 save_wrapper.appendChild(submitButton);
69 function iconSelected(selectedValue){
77 if (selectedValue==
"select"){
78 var icon_list_options = document.getElementById(
"iconDropdown").childNodes[0].childNodes;
79 for (var opt = 0; opt < icon_list_options.length; opt++){
80 if (icon_list_options[opt].value == currentSelectedValue_){
81 icon_list_options[opt].selected =
true;
88 if (selectedValue == currentSelectedValue_){
95 iconTable_wrapper.innerHTML =
"";
98 console.log(
"selectedIcon " + selectedValue);
100 var altLabel = document.createElement(
"td");
101 var titleLabel = document.createElement(
"td");
102 var uniqueLabel = document.createElement(
"td");
103 var permissionNeededLabel = document.createElement(
"td");
104 var imageLabel = document.createElement(
"td");
105 var linkLabel = document.createElement(
"td");
107 altLabel.innerHTML =
"Title";
108 titleLabel.innerHTML =
"Alt";
109 uniqueLabel.innerHTML =
"Unique";
110 permissionNeededLabel.innerHTML =
"Permission Needed";
111 imageLabel.innerHTML =
"Image";
112 linkLabel.innerHTML =
"Link";
114 var alt = document.createElement(
"td");
115 var title = document.createElement(
"td");
116 var unique = document.createElement(
"td");
117 var permissionNeeded = document.createElement(
"td");
118 var image = document.createElement(
"td");
119 var link = document.createElement(
"td");
122 var alt_tr = document.createElement(
"tr");
123 var title_tr = document.createElement(
"tr");
124 var unique_tr = document.createElement(
"tr");
125 var permissionNeeded_tr = document.createElement(
"tr");
126 var image_tr = document.createElement(
"tr");
127 var link_tr = document.createElement(
"tr");
130 var altField = document.createElement(
"input");
131 var titleField = document.createElement(
"input");
132 var uniqueField = document.createElement(
"input");
133 var permissionNeededField = document.createElement(
"input");
134 var imageField = document.createElement(
"input");
135 var linkField = document.createElement(
"input");
137 if(selectedValue !=
"new")
140 altField.value = megaLibrary_[selectedValue][0];
141 titleField.value = megaLibrary_[selectedValue][1];
142 uniqueField.value = megaLibrary_[selectedValue][2];
143 permissionNeededField.value = megaLibrary_[selectedValue][3];
144 imageField.value = megaLibrary_[selectedValue][4];
145 linkField.value = megaLibrary_[selectedValue][5];
150 altField.setAttribute(
"oninput",
"activateSave()");
151 titleField.setAttribute(
"oninput",
"activateSave()");
152 uniqueField.setAttribute(
"oninput",
"activateSave()");
153 permissionNeededField.setAttribute(
"oninput",
"activateSave()");
154 imageField.setAttribute(
"oninput",
"activateSave()");
155 linkField.setAttribute(
"oninput",
"activateSave()");
157 alt.appendChild(altField);
158 title.appendChild(titleField);
159 unique.appendChild(uniqueField);
160 permissionNeeded.appendChild(permissionNeededField);
161 image.appendChild(imageField);
162 link.appendChild(linkField);
164 alt_tr.appendChild(altLabel);
165 title_tr.appendChild(titleLabel);
166 unique_tr.appendChild(uniqueLabel);
167 permissionNeeded_tr.appendChild(permissionNeededLabel);
168 image_tr.appendChild(imageLabel);
169 link_tr.appendChild(linkLabel);
171 alt_tr.appendChild(alt);
172 title_tr.appendChild(title);
173 unique_tr.appendChild(unique);
174 permissionNeeded_tr.appendChild(permissionNeeded);
175 image_tr.appendChild(image);
176 link_tr.appendChild(link);
178 iconTable.appendChild(alt_tr);
179 iconTable.appendChild(title_tr);
180 iconTable.appendChild(unique_tr);
181 iconTable.appendChild(permissionNeeded_tr);
182 iconTable.appendChild(image_tr);
183 iconTable.appendChild(link_tr);
203 var deleteButton = document.createElement(
"button");
204 deleteButton.setAttribute(
"onClick",
"deleteIcon(" + selectedValue +
")");
205 deleteButton.innerHTML =
"Delete";
206 var submitRow = document.createElement(
"tr");
208 var button_td = document.createElement(
"td");
209 button_td.appendChild(deleteButton);
211 if(selectedValue ==
"new"){
212 var addButton = document.createElement(
"button");
213 addButton.setAttribute(
"onClick",
"addIcon()");
214 addButton.innerHTML =
"Add";
215 addButton.setAttribute(
"id",
"save");
216 button_td.appendChild(addButton);
218 var saveButton = document.createElement(
"button");
219 saveButton.setAttribute(
"onClick",
"saveIcon()");
220 saveButton.innerHTML =
"Save";
221 button_td.appendChild(saveButton);
225 submitRow.appendChild(document.createElement(
"td"));
226 submitRow.appendChild(button_td);
229 iconTable.appendChild(submitRow);
230 currentSelectedValue_ = selectedValue;
234 function deleteIcon(index){
239 console.log(megaLibrary_);
241 megaLibrary_.splice(index, 1);
242 console.log(megaLibrary_);
243 currentSelectedValue_ =
"";
246 iconTable_wrapper.innerHTML =
"";
256 var currentIcon =[document.getElementsByTagName(
"input")[0].value,
257 document.getElementsByTagName(
"input")[1].value,
258 document.getElementsByTagName(
"input")[2].value,
259 document.getElementsByTagName(
"input")[3].value,
260 document.getElementsByTagName(
"input")[4].value,
261 document.getElementsByTagName(
"input")[5].value];
263 megaLibrary_.push(currentIcon);
270 iconSelected(megaLibrary_.length-1);
281 alert(
"No changes have been made!");
288 var currentIcon =[document.getElementsByTagName(
"input")[0].value,
289 document.getElementsByTagName(
"input")[1].value,
290 document.getElementsByTagName(
"input")[2].value,
291 document.getElementsByTagName(
"input")[3].value,
292 document.getElementsByTagName(
"input")[4].value,
293 document.getElementsByTagName(
"input")[5].value];
295 var icon_list_options = document.getElementById(
"iconDropdown").childNodes[0].childNodes;
296 for (var opt = 0; opt < icon_list_options.length; opt++){
297 if (icon_list_options[opt].value == currentSelectedValue_){
298 icon_list_options[opt].selected =
true;
303 megaLibrary_[opt-2] = currentIcon;
308 function submitChangesToServer(){
311 var iconList =
"iconList=";
316 for(var icon = 0; icon < (megaLibrary_.length); icon++)
318 for(var details=0; details < (megaLibrary_[icon].length); details++)
321 iconList += (megaLibrary_[icon][details] +
",");
326 iconList = iconList.substring(0, iconList.length - 1);
328 console.log(iconList);
329 makeServerRequest(iconList);
332 function activateSave(){
341 function makeServerRequest(data){
343 DesktopContent.XMLHttpRequest(
"iconEditor", data, iconEditorHandler, undefined, undefined);
346 var iconEditorHandler =
function(req){
348 var iconArray = req.responseText.split(
",");
349 console.log(iconArray);
350 var numberOfIconFields = 6;
351 megaLibrary_.length = 0;
353 for(var i=0;i<(iconArray.length-1);i+=numberOfIconFields)
354 megaLibrary_.push([iconArray[i], iconArray[i+1], iconArray[i+2], iconArray[i+3], iconArray[i+4], iconArray[i+5]]);
355 console.log(megaLibrary_);