Changeset 182 for Dev/trunk/js/sequencerScripts.js
- Timestamp:
- 12/12/11 10:49:25 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/trunk/js/sequencerScripts.js
r181 r182 16 16 }, 17 17 state: { // Operating state of the sequencer 18 editing: false, // Whether or not one of the contained child objects is currently being edited or in edit mode. Which one can be determined from the selectedStep property. 18 19 numSteps: 0, // Number of steps currently drawn in the editor (not necessarily same as number of steps in pipeline!) (INTEGER) 19 20 loaded: false, // Whether or not the sequencer content has been updated for the first time (BOOL) … … 25 26 settings: { // Various settings to determine the workings of the sequencer 26 27 content: { // Properties related to the content view of the sequencer 28 contentType: "session", // Type of the loaded parent object 27 29 width: null, // Width of the viewing area (INTEGER) 28 30 height: null, // Height of the viewing area (INTEGER) … … 167 169 sequencer.session.pipeline.upToDate.length[i] = true; 168 170 } 171 if (content.childNodes[0].nodeType == 3) content.removeChild(content.childNodes[0]); 169 172 }, true); 170 173 } … … 173 176 debugger; 174 177 var needsUpdating = new Array(); 175 176 // DIT IS FOUT. 177 // BASIC IDEE, IK LOOP NU DOOR DE CHILNODES HEEN, EN NIET DOOR DE PIPELINE ARRAY. HIERDOOR KAN JE NOOIT EEN NIEUWE OBJECT DRAWEN, WANT DAAR IS IN DE SEQUENCER NOG GEEN DIV VOOR. 178 // OPLOSSING: 179 // LOOP DOOR SEQUENCER EN HAAL ALLES WEG DAT ER NIET HOORT (CROSSCHECK DISPLAYSTEP UID MET ARRAY) 180 // LOOP DAARNA DOOR DE PIPELINE EDITOR, CHECK OF ER ELEMENTS VOOR ZIJN. ZO NIET, VOEG TOE AAN DE EDITOR! 181 178 // Add steps that need updating to the needsUpdating array (index, uid, type). 182 179 for (var i = 0; i < sequencer.session.pipeline.uids.length; i++) { 183 184 } 185 186 for (var i = 0; i < content.childNodes.length; i++) { 187 // If this childNode is not a displayStep, continue to the next childNode 188 if (!hasClass(content.childNodes[i], "displayStep")) continue; 189 // If this step is up to date, continue 190 // pseudo: the upToDate entry on the index where childNodes[i].id is stored in uids 191 if (sequencer.session.pipeline.upToDate[sequencer.session.pipeline.uids.indexOf(content.childNodes[i].id)] == true) continue; 192 193 // So now we know that we are looking at a displayStep and it needs to be refreshed. 194 // We store the current childNodes index, the uid of the proper displayStep and the type of the proper displayStep in needsUpdating array. 180 if (sequencer.session.pipeline.upToDate[i] == true) continue; 195 181 needsUpdating.push(new Array(i, sequencer.session.pipeline.uids[i], sequencer.session.pipeline.types[i])); 196 182 } 197 198 183 // Now that we have an array of the steps that need to be refreshed, we compose a requestString. 199 requestString = "uids=";184 var requestString = "uids="; 200 185 for (var i = 0; i < needsUpdating.length; i++) { 201 requestString += needsUpdating[i][1]+","; // comma separated, of course202 } 203 requestString = requestString.slice(0, requestString.length - 1); // remove trailing commas186 requestString += needsUpdating[i][1]+","; 187 } 188 if (requestString.slice(-1) == ",") requestString = requestString.slice(0, requestString.length - 1); // remove trailing commas 204 189 requestString += "&types="; 205 for (var i = 0; i< needsUpdating.length; i++) { 206 requestString += needsUpdating[i][2]+","; 207 } 208 requestString = requestString.slice(0, requestString.length - 1); // remove trailing commas 209 210 // Now it is time to send this string to returnStep.php (Soon to be returnStepDisplay.php!). 211 212 alert(requestString); 190 for (var i = 0; i < needsUpdating.length; i++) { 191 requestString += needsUpdating[i][2]; 192 } 193 if (requestString.slice(-1) == ",") requestString = requestString.slice(0, requestString.length - 1); // remove trailing commas 194 195 // perform the AJAX request 213 196 newAjaxRequest(requestString, "returnStep.php", function(result) { 214 //alert(result.responseText); 215 insertNewSteps(responseText); 197 insertNewSteps(result.responseText, needsUpdating); 216 198 }, true); 217 199 } … … 263 245 } 264 246 265 function insertNewSteps(responseText ) {247 function insertNewSteps(responseText, needsUpdating) { 266 248 debugger; 267 249 var content = document.getElementById("seqContentWrapper"); … … 271 253 // tempDiv will serve to 272 254 var tempDiv; 255 if (holderDiv.firstChild.nodeType == "3") holderDiv.removeChild(holderDiv.firstChild); 273 256 // Loop through 274 for (var i = 0; i < content.childNodes.length; i++) { 275 // Once again, skip if not a displayStep or the given displayStep is already up to date. 276 if (!hasClass(content.childNodes[i], "displayStep")) continue; 277 if (sequencer.session.pipeline.upToDate[sequencer.session.pipeline.uids.indexOf(content.childNodes[i].id)] == true) continue; 257 for (var i = 0; i < needsUpdating.length; i++) { 278 258 tempDiv = holderDiv.firstChild; 279 259 holderDiv.removeChild(holderDiv.firstChild); 280 content.replaceChild(tempDiv, content.childNodes[i]); 281 // Exit the loop if there is no more responsetext 282 if (!holderDiv.firstChild) break; 260 if (needsUpdating[i][0] > sequencer.state.numSteps-1) { 261 // this step comes at the end of the pipeline 262 content.appendChild(tempDiv); 263 sequencer.state.numSteps++; 264 } 265 else { 266 content.replaceChild(tempDiv, content.childNodes[needsUpdating[i][0]*2]); 267 } 268 // The element is now updated, therefore set this flag in the global var 269 sequencer.session.pipeline.upToDate[needsUpdating[i][0]] = true; 270 } 271 272 // Then add or adjust dividers as needed! 273 updateDividers(); 274 } 275 276 function insertNewQuestion(responseText, needsUpdating) { 277 /* 278 * This is a test function displaying how to handle the visual object representation in solely javascript. 279 * Communication of relevant variables between PHP and JS happens in JSON format. 280 * PHP returns a JSON array of objects to be created by JS 281 * JS then loops through this array and creates DIVS to be inserted into the sequencer. 282 * These are inserted at the position needsUpdating gives us. 283 */ 284 285 var content = document.getElementById("seqContent"); 286 var response = eval(responseText); 287 288 for (var i = 0; i < response.length; i++) { 289 var tempDiv = document.createElement("div"); 290 tempDiv.id = response.id; 291 tempDiv.className = "displayStep"; 292 var divImage = document.createElement("img"); 293 divImage.src = "./images/displayStep.png"; 294 divImage.addEventListener("Click", function(e){ 295 selectStep(this.id); 296 }, false); 297 tempDiv.appendChild(divImage); 298 var divLabel = document.createElement("p"); 299 divLabel.innerHTML = response.title; 300 tempDiv.appendChild(divLabel); 301 302 // This for needs to loop backwards so that the steps at the end of the pipeline are added or changed first. This keeps the childNodes index for all further steps intact. 303 for (var j = needsUpdating.length; j >= 0; j--) { 304 if (needsUpdating[j][1] != response.id) continue; 305 if (needsUpdating[j][0] > sequencer.state.numSteps-1) { 306 content.appendChild(tempDiv); 307 } 308 else { 309 content.replaceChild(tempDiv, content.childNodes[j][0]*2); 310 } 311 } 283 312 } 284 313 } … … 315 344 316 345 function savePipeline (confirmSave) { 317 if (confirmSave==true) { 318 var answer = confirm("Save changes to pipeline?"); 346 var answer; 347 if (confirmSave == true) { 348 answer = confirm("Save changes to pipeline?"); 319 349 } 320 350 else { 321 var answer = true; 322 } 323 324 325 if (answer) { 326 var pipeline = document.getElementById("pipelineStringField").value; 327 pipeline = pipeline.slice(0, pipeline.length - 1); 328 var types = document.getElementById("pipelineTypeField").value; 329 types = types.slice(0, types.length - 1); 330 var session = document.getElementById("sessionField").value; 331 var requestString = "uids="+pipeline+"&types="+types+"&sessionUid="+session; 332 console.log(requestString); 333 334 335 var success; 336 newAjaxRequest(requestString, "savesession.php", function(result){ 337 success = result.responseText; 338 }, true); 339 console.log(success); 340 } 351 answer = true; 352 } 353 if (answer == false) return; 354 355 var requestString = "uids="; 356 requestString += arrayToString(sequencer.session.pipeline.uids, ","); 357 requestString += "&types="; 358 requestString += arrayToString(sequencer.session.pipeline.types, ","); 359 requestString += "&sessionUid="; 360 requestString += sequencer.session.uid; 361 newAjaxRequest(requestString, "savePipeline.php", function(result){ 362 console.log(result.responseText); 363 }, true); 341 364 } 342 365
Note: See TracChangeset
for help on using the changeset viewer.