diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/exe/ajax.php | 38 | ||||
-rw-r--r-- | lib/exe/js.php | 4 | ||||
-rw-r--r-- | lib/scripts/edit.js | 41 | ||||
-rw-r--r-- | lib/scripts/script.js | 10 | ||||
-rw-r--r-- | lib/tpl/default/design.css | 14 |
5 files changed, 98 insertions, 9 deletions
diff --git a/lib/exe/ajax.php b/lib/exe/ajax.php index e52d5d378..886e9829d 100644 --- a/lib/exe/ajax.php +++ b/lib/exe/ajax.php @@ -61,18 +61,52 @@ function ajax_qsearch(){ } /** - * Refresh a page lock + * Refresh a page lock and save draft * * Andreas Gohr <andi@splitbrain.org> */ function ajax_lock(){ + global $conf; + global $lang; $id = cleanID($_POST['id']); if(empty($id)) return; if(!checklock($id)){ lock($id); - print 1; + echo 1; } + + if($conf['usedraft'] && $_POST['wikitext']){ + $client = $_SERVER['REMOTE_USER']; + if(!$client) $client = clientIP(true); + + $draft = array('id' => $ID, + 'prefix' => $_POST['prefix'], + 'text' => $_POST['wikitext'], + 'suffix' => $_POST['suffix'], + 'date' => $_POST['date'], + 'client' => $client, + ); + $cname = getCacheName($draft['client'].$id,'.draft'); + if(io_saveFile($cname,serialize($draft))){ + echo $lang['draftdate'].' '.date($conf['dformat']); + } + } + +} + +/** + * Delete a draft + */ +function ajax_draftdel(){ + $id = cleanID($_POST['id']); + if(empty($id)) return; + + $client = $_SERVER['REMOTE_USER']; + if(!$client) $client = clientIP(true); + + $cname = getCacheName($client.$id,'.draft'); + @unlink($cname); } //Setup VIM: ex: et ts=2 enc=utf-8 : diff --git a/lib/exe/js.php b/lib/exe/js.php index 5147f1be3..9cc4a863c 100644 --- a/lib/exe/js.php +++ b/lib/exe/js.php @@ -93,7 +93,7 @@ function js_out(){ js_runonstart("initChangeCheck('".js_escape($lang['notsavedyet'])."')"); // add lock timer - js_runonstart("locktimer.init(".($conf['locktime'] - 60).",'".js_escape($lang['willexpire'])."')"); + js_runonstart("locktimer.init(".($conf['locktime'] - 60).",'".js_escape($lang['willexpire'])."',".$conf['usedraft'].")"); // load spell checker if($conf['spellchecker']){ @@ -195,7 +195,7 @@ function js_escape($string){ * @author Andreas Gohr <andi@splitbrain.org> */ function js_runonstart($func){ - echo "addInitEvent(function(){ $func; });"; + echo "addInitEvent(function(){ $func; });\n"; } /** diff --git a/lib/scripts/edit.js b/lib/scripts/edit.js index d39835526..48acc542a 100644 --- a/lib/scripts/edit.js +++ b/lib/scripts/edit.js @@ -328,7 +328,24 @@ var textChanged = false; */ function changeCheck(msg){ if(textChanged){ - return confirm(msg); + var ok = confirm(msg); + if(ok){ + // remove a possibly saved draft using ajax + var dwform = $('dw__editform'); + if(dwform){ + var params = 'call=draftdel'; + params += '&id='+dwform.elements.id.value; + params += '&user='+encodeURI(USERNAME); + + var sackobj = new sack(DOKU_BASE + 'lib/exe/ajax.php'); + sackobj.AjaxFailedAlert = ''; + sackobj.encodeURIString = false; + sackobj.runAJAX(params); + // we send this request blind without waiting for + // and handling the returned data + } + } + return ok; }else{ return true; } @@ -408,10 +425,11 @@ function locktimer_class(){ this.pageid = ''; }; var locktimer = new locktimer_class(); - locktimer.init = function(timeout,msg){ + locktimer.init = function(timeout,msg,draft){ // init values locktimer.timeout = timeout*1000; locktimer.msg = msg; + locktimer.draft = draft; locktimer.lasttime = new Date(); if(!$('dw__editform')) return; @@ -465,8 +483,16 @@ var locktimer = new locktimer_class(); locktimer.refresh = function(){ var now = new Date(); // refresh every minute only - if(now.getTime() - locktimer.lasttime.getTime() > 60*1000){ - locktimer.sack.runAJAX('call=lock&id='+encodeURI(locktimer.pageid)); + if(now.getTime() - locktimer.lasttime.getTime() > 30*1000){ //FIXME decide on time + var params = 'call=lock&id='+encodeURI(locktimer.pageid); + if(locktimer.draft){ + var dwform = $('dw__editform'); + params += '&prefix='+encodeURI(dwform.elements.prefix.value); + params += '&wikitext='+encodeURI(dwform.elements.wikitext.value); + params += '&suffix='+encodeURI(dwform.elements.suffix.value); + params += '&date='+encodeURI(dwform.elements.date.value); + } + locktimer.sack.runAJAX(params); locktimer.lasttime = now; } }; @@ -476,7 +502,12 @@ var locktimer = new locktimer_class(); * Callback. Resets the warning timer */ locktimer.refreshed = function(){ - if(this.response != '1') return; // locking failed + var data = this.response; + var error = data.charAt(0); + data = data.substring(1); + + $('draft__status').innerHTML=data; + if(error != '1') return; // locking failed locktimer.reset(); }; // end of locktimer class functions diff --git a/lib/scripts/script.js b/lib/scripts/script.js index e05aeb0fe..87fd8e503 100644 --- a/lib/scripts/script.js +++ b/lib/scripts/script.js @@ -41,6 +41,16 @@ function $() { } /** + * Simple function to check if a global var is defined + * + * @author Kae Verens + * @link http://verens.com/archives/2005/07/25/isset-for-javascript/#comment-2835 + */ +function isset(varname){ + return(typeof(window[varname])!='undefined'); +} + +/** * Get the X offset of the top left corner of the given object * * @link http://www.quirksmode.org/index.html?/js/findpos.html diff --git a/lib/tpl/default/design.css b/lib/tpl/default/design.css index 0f3502c98..70b429bc3 100644 --- a/lib/tpl/default/design.css +++ b/lib/tpl/default/design.css @@ -115,6 +115,16 @@ div.dokuwiki input.missing { display: inline; } +/* disabled style - not understood by IE */ +div.dokuwiki textarea.edit[disabled], +div.dokuwiki textarea.edit[readonly], +div.dokuwiki input.edit[disabled], +div.dokuwiki input.edit[readonly], +div.dokuwiki select.edit[disabled] { + background-color: #f5f5f5!important; + color: #666!important; +} + /* edit form */ div.dokuwiki div.toolbar, div.dokuwiki div#wiki__editbar { margin:2px 0; @@ -138,6 +148,10 @@ div.dokuwiki div#wiki__editbar div.summary { div.dokuwiki .nowrap { white-space:nowrap; } +div.dokuwiki div#draft__status { + float: right; + color: __dark__; +} /* --------- buttons ------------------- */ |