- Timestamp:
- 2013-06-27T16:52:08+12:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/web/interfaces/default/js/javascript-global-functions.js
r26431 r27713 1 var SUCCESS = 1; 2 var ACCEPTED = 2; 3 var ERROR = 3; 4 var CONTINUING = 10; 5 var COMPLETED = 11; 6 var HALTED = 12; 7 1 8 gs.functions = new Array(); 2 9 … … 93 100 } 94 101 102 gs.functions.checkForErrors = function(xml) 103 { 104 var errorElems = xml.getElementsByTagName("error"); 105 106 if(errorElems && errorElems.length > 0) 107 { 108 var errorString = gs.text.dse.error_saving_changes + ": "; 109 for(var i = 0; i < errorElems.length; i++) 110 { 111 errorString += " " + errorElems.item(i).firstChild.nodeValue; 112 } 113 alert(errorString); 114 return true; 115 } 116 return false; //No errors 117 } 118 119 gs.functions.validateXML = function(txt) 120 { 121 // code for IE 122 if (window.ActiveXObject) 123 { 124 var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); 125 xmlDoc.async = "false"; 126 xmlDoc.loadXML(document.all(txt).value); 127 128 if(xmlDoc.parseError.errorCode!=0) 129 { 130 txt = dse.error_code + ": " + xmlDoc.parseError.errorCode + "\n"; 131 txt = txt + dse.error_reason + ": " + xmlDoc.parseError.reason; 132 txt = txt + dse.error_line + ": " + xmlDoc.parseError.line; 133 console.log(txt); 134 return null; 135 } 136 137 return xmlDoc; 138 } 139 // code for Mozilla, Firefox, Opera, etc. 140 else if (document.implementation.createDocument) 141 { 142 var parser = new DOMParser(); 143 var xmlDoc = parser.parseFromString(txt,"text/xml"); 144 145 if (xmlDoc.getElementsByTagName("parsererror").length > 0) 146 { 147 console.log(gs.text.dse.xml_error); 148 return null; 149 } 150 151 return xmlDoc; 152 } 153 else 154 { 155 console.log(gs.text.dse.browse_cannot_validate_xml); 156 } 157 return null; 158 } 159 95 160 gs.functions.buildCollections = function(collections, finalFunction) 96 161 { … … 105 170 { 106 171 var ajax = new gs.functions.ajaxRequest(); 107 ajax.open("GET", _baseURL+ "?a=g&rt=r&ro=1&s=BuildCollection&s1.collection=" + collections[counter]);172 ajax.open("GET", gs.xsltParams.library_name + "?a=g&rt=r&ro=1&s=BuildCollection&s1.collection=" + collections[counter]); 108 173 ajax.onreadystatechange = function() 109 174 { … … 111 176 { 112 177 var text = ajax.responseText; 113 var xml = validateXML(text);114 115 if(!xml || checkForErrors(xml))178 var xml = gs.functions.validateXML(text); 179 180 if(!xml || gs.functions.checkForErrors(xml)) 116 181 { 117 182 console.log("Could not build collection -> " + collections[counter] + ", aborting"); … … 122 187 var pid = status.getAttribute("pid"); 123 188 124 startCheckLoop(pid, "BuildCollection", function()189 gs.functions.startCheckLoop(pid, "BuildCollection", function() 125 190 { 126 191 var localAjax = new gs.functions.ajaxRequest(); 127 localAjax.open("GET", _baseURL+ "?a=g&rt=r&ro=1&s=ActivateCollection&s1.collection=" + collections[counter], true);192 localAjax.open("GET", gs.xsltParams.library_name + "?a=g&rt=r&ro=1&s=ActivateCollection&s1.collection=" + collections[counter], true); 128 193 localAjax.onreadystatechange = function() 129 194 { … … 131 196 { 132 197 var localText = localAjax.responseText; 133 var localXML = validateXML(localText);198 var localXML = gs.functions.validateXML(localText); 134 199 135 if(!xml || checkForErrors(xml))200 if(!xml || gs.functions.checkForErrors(xml)) 136 201 { 137 202 console.log("Could not activate collection -> " + collections[counter] + ", aborting"); … … 143 208 { 144 209 var localPID = localStatus.getAttribute("pid"); 145 startCheckLoop(localPID, "ActivateCollection", function()210 gs.functions.startCheckLoop(localPID, "ActivateCollection", function() 146 211 { 147 if (++counter == _collections.length)212 if (++counter == collections.length) 148 213 { 149 214 //Run this function once we are done building all the collections … … 167 232 } 168 233 169 function startCheckLoop(pid, serverFunction, callbackFunction)234 gs.functions.startCheckLoop = function(pid, serverFunction, callbackFunction) 170 235 { 171 236 var ajaxFunction = function() 172 237 { 173 238 var ajax = new gs.functions.ajaxRequest(); 174 ajax.open("GET", _baseURL+ "?a=g&rt=s&ro=1&s=" + serverFunction + "&s1.pid=" + pid, true);239 ajax.open("GET", gs.xsltParams.library_name + "?a=g&rt=s&ro=1&s=" + serverFunction + "&s1.pid=" + pid, true); 175 240 ajax.onreadystatechange = function() 176 241 { … … 178 243 { 179 244 var text = ajax.responseText; 180 var xml = validateXML(text);245 var xml = gs.functions.validateXML(text); 181 246 182 if(!xml || checkForErrors(xml))247 if(!xml || gs.functions.checkForErrors(xml)) 183 248 { 184 249 console.log("Could not check status of " + serverFunction + ", there was an error in the XML, aborting");
Note:
See TracChangeset
for help on using the changeset viewer.