TextEditor class appended
@@ -357,10 +357,24 @@ | ||
357 | 357 | } |
358 | 358 | ); |
359 | 359 | } |
360 | -TextEditor.prototype.showFile=function(name){ this.getFile(name, 'showFileData'); } | |
361 | 360 | |
361 | +TextEditor.prototype.showFile=function(name){ this.getFile(name, this.name+'.showFileData'); } | |
362 | +TextEditor.prototype.showFileData=function(transaction, results){ | |
363 | + var data = results.rows.item(0); | |
364 | + var filename = data['name']; | |
365 | + var filedata = data['datablob']; | |
366 | + | |
367 | + var datadiv = document.getElementById('tempdata'); | |
368 | + datadiv.setAttribute('lfdataid', parseInt(data['filedata_id'])); | |
369 | + document.title=filename; | |
370 | + | |
371 | + previewFile(filedata); | |
372 | + | |
373 | + updateShowMenu(); | |
374 | + setMode('Preview'); | |
375 | +} | |
376 | +/// ErrorHandler | |
362 | 377 | TextEditor.prototype.killTransaction=function(transaction, error){ return true; } |
363 | - | |
364 | 378 | TextEditor.prototype.errorHandler=function(transaction, error){ |
365 | 379 | alert('Oops. Error was '+error.message+' (Code '+error.code+')'); |
366 | 380 |
@@ -368,50 +382,58 @@ | ||
368 | 382 | if (this.we_think_this_error_is_fatal) return true; |
369 | 383 | return false; |
370 | 384 | } |
371 | - | |
372 | 385 | TextEditor.prototype.nullDataHandler=function(transaction, results){ } |
373 | 386 | |
374 | -TextEditor.prototype.fileSelector=function(){ | |
387 | +/// FileList | |
388 | +TextEditor.prototype.mkfileList=function(){ | |
375 | 389 | this.db.transaction( |
376 | - function (transaction) { | |
377 | - transaction.executeSql("SELECT * from files where deleted=0;", [ ], | |
378 | - function (transaction, results) { | |
379 | - var filelist = ''; | |
380 | - var menuDiv = document.getElementById('menuDiv'); | |
381 | - if(menuDiv){ | |
382 | - for(var i=0; i<results.rows.length; i++) { | |
383 | - var row = results.rows.item(i); | |
384 | - filelist = filelist + fileEntry(row); | |
385 | - } | |
386 | - if (filelist == "") { | |
387 | - filelist = "No files.<br />\n"; | |
388 | - } else { | |
389 | - filelist = "<center><table class='filetable'>"+filelist+"</table></center>"; | |
390 | - } | |
391 | - menuDiv.innerHTML="<H1 class='title'>"+MainTitle+"</H1>"+createMenuBar()+filelist; | |
392 | - } | |
393 | - }, this.errorHandler); | |
394 | - } | |
390 | + new Function("transaction", | |
391 | + "transaction.executeSql('SELECT * from files where deleted=0;',[],"+ | |
392 | + "function (transaction, results) {"+ | |
393 | + "var filelist = '';"+ | |
394 | + "var menuDiv = document.getElementById('menuDiv');"+ | |
395 | + "if(menuDiv){"+ | |
396 | + "for(var i=0;i<results.rows.length;i++){"+ | |
397 | + "var row = results.rows.item(i);"+ | |
398 | + "filelist = filelist + "+this.name+".fileEntry(row);"+ | |
399 | + "}"+ | |
400 | + "if(!filelist){"+ | |
401 | + "filelist = 'No files.<br />';"+ | |
402 | + "}else{"+ | |
403 | + "filelist = '<center><table class=\"filetable\">'+filelist+'</table></center>';"+ | |
404 | + "}"+ | |
405 | + "menuDiv.innerHTML='<H1 class=\"title\">'+MainTitle+'</H1>'+"+this.name+".createMenuBar()+filelist;"+ | |
406 | + "}"+ | |
407 | + "}, "+this.name+".errorHandler);") | |
395 | 408 | ); |
396 | 409 | } |
397 | - | |
398 | 410 | |
399 | -function showFileData(transaction, results){ | |
400 | - var data = results.rows.item(0); | |
401 | - var filename = data['name']; | |
402 | - var filedata = data['datablob']; | |
411 | +TextEditor.prototype.fileEntry=function(row){ | |
412 | + var name = row['name']; | |
413 | + var files_id = row['id']; | |
403 | 414 | |
404 | - var datadiv = document.getElementById('tempdata'); | |
405 | - datadiv.setAttribute('lfdataid', parseInt(data['filedata_id'])); | |
406 | - document.title=filename; | |
415 | + var res = "<tr class='filerow'>"; | |
416 | + res += "<td class='filenamecell' onClick=\""+this.name+".showFile('"+name+"');\">"+name+"</td>"; | |
417 | + res += "<td class='filelinkcell'>"; | |
418 | + res += "<button class='blue' onClick=\"editFile('"+name+"');\"> Edit </button> "; | |
419 | + res += "<button class='green' onClick=\"renameFile('"+name+"',"+files_id+");\"> Rename </button> "; | |
420 | + res += "<button onClick=\"uploadFile('"+name+"');\">Upload</button>"; | |
421 | + res += "<button class='red' onClick=\""+this.name+".deleteFile('"+name+"');\">Delete</button>"; | |
422 | + res += "</td></tr>\n"; | |
407 | 423 | |
408 | - previewFile(filedata); | |
424 | + return res; | |
425 | +} | |
409 | 426 | |
410 | - updateShowMenu(); | |
411 | - setMode('Preview'); | |
427 | +TextEditor.prototype.createMenuBar=function(){ | |
428 | + var menu = "<ul id='menubar'>"; | |
429 | + menu += "<li><button onClick='createNewFile()'>Create New File</button></li>"; | |
430 | +// menu += "<li><button onClick='deleteAllFile()'>Delete All</button></li>"; | |
431 | + menu += "<li><button onClick='getRemoteFileList()'>File List on a Server</button></li>"; | |
432 | + menu += "<li><button onClick='configServer()'>Server Configuration</button></li>"; | |
433 | + menu += "</ul><p class='cls'>"; | |
434 | + return menu; | |
412 | 435 | } |
413 | 436 | |
414 | - | |
415 | 437 | |
416 | 438 | ///////// |
417 | 439 | function fileSelector() { |
@@ -418,7 +440,7 @@ | ||
418 | 440 | if(!systemDB){ |
419 | 441 | getRemoteFileList(); |
420 | 442 | }else{ |
421 | - Editor.fileSelector(); | |
443 | + Editor.mkfileList(); | |
422 | 444 | } |
423 | 445 | setMode('List'); |
424 | 446 | } |
@@ -458,32 +480,7 @@ | ||
458 | 480 | return res; |
459 | 481 | } |
460 | 482 | |
461 | -function fileEntry(row){ | |
462 | - var name = row['name']; | |
463 | - var files_id = row['id']; | |
464 | 483 | |
465 | - var res = "<tr class='filerow'>"; | |
466 | - res += "<td class='filenamecell' onClick=\"Editor.showFile('"+name+"');\">"+name+"</td>"; | |
467 | - res += "<td class='filelinkcell'>"; | |
468 | - res += "<button class='blue' onClick=\"editFile('"+name+"');\"> Edit </button> "; | |
469 | - res += "<button class='green' onClick=\"renameFile('"+name+"',"+files_id+");\"> Rename </button> "; | |
470 | - res += "<button onClick=\"uploadFile('"+name+"');\">Upload</button>"; | |
471 | - res += "<button class='red' onClick=\"Editor.deleteFile('"+name+"');\">Delete</button>"; | |
472 | - res += "</td></tr>\n"; | |
473 | - | |
474 | - return res; | |
475 | -} | |
476 | - | |
477 | -function createMenuBar(){ | |
478 | - var menu = "<ul id='menubar'>"; | |
479 | - menu += "<li><button onClick='createNewFile()'>Create New File</button></li>"; | |
480 | - menu += "<li><button onClick='deleteAllFile()'>Delete All</button></li>"; | |
481 | - menu += "<li><button onClick='getRemoteFileList()'>File List on a Server</button></li>"; | |
482 | - menu += "<li><button onClick='configServer()'>Server Configuration</button></li>"; | |
483 | - menu += "</ul><p class='cls'>"; | |
484 | - return menu; | |
485 | -} | |
486 | - | |
487 | 484 | //// Config |
488 | 485 | function setConfig(){ |
489 | 486 | var ele = document.getElementById('ServerURL'); |
@@ -610,7 +607,7 @@ | ||
610 | 607 | function updateEditMenu(){ |
611 | 608 | var menuDiv = document.getElementById('menuDiv'); |
612 | 609 | menuDiv.innerHTML="<h1 class='title'>" +document.title+"</h1>\n"; |
613 | - menuDiv.innerHTML+= "<button onClick=\"saveFile();fileSelector();\"> Save </button>\n"; | |
610 | + menuDiv.innerHTML+= "<button onClick=\"Editor.saveFile();fileSelector();\"> Save </button>\n"; | |
614 | 611 | menuDiv.innerHTML+= "<button onClick=\"previewData();\"> Preview </button>\n"; |
615 | 612 | menuDiv.innerHTML+= "<button onClick=\"fileSelector();\"> File List </button>\n"; |
616 | 613 |
@@ -657,7 +654,7 @@ | ||
657 | 654 | editFile(name); |
658 | 655 | } |
659 | 656 | |
660 | - | |
657 | +////////////////////////////// | |
661 | 658 | // Show File (GUI Editor) |
662 | 659 | function updateShowMenu(){ |
663 | 660 | var menuDiv = document.getElementById('menuDiv'); |