| | @@ -174,10 +174,16 @@ |
| 174 | 174 | TheApp.jqe.taResponse.val( val ); |
| 175 | 175 | }; |
| 176 | 176 | opt.onError = function(req,opt) { |
| 177 | 177 | TheApp.jqe.taResponse.val( "ERROR SENDING REQUEST:\n"+WhAjaj.stringify(opt) ); |
| 178 | 178 | }; |
| 179 | + |
| 180 | + TheApp.jqe.taPageContent.blur(function(){ |
| 181 | + var p = TheApp.currentPage; |
| 182 | + if(! p ) return; |
| 183 | + p.content = TheApp.jqe.taPageContent.val(); |
| 184 | + }); |
| 179 | 185 | |
| 180 | 186 | TheApp.cgi.onLogin = function(){ |
| 181 | 187 | TheApp.jqe.taResponse.val( "Logged in. Auth token =\n"+this.authToken ); |
| 182 | 188 | TheApp.jqe.currentAuthToken.text("Auth token: "+(this.authToken || "not logged in")); |
| 183 | 189 | }; |
| | @@ -191,11 +197,11 @@ |
| 191 | 197 | TheApp.currentPage = page; |
| 192 | 198 | TheApp.jqe.spanPageName.text('('+page.name+')'); |
| 193 | 199 | TheApp.jqe.taPageContent.val(page.content); |
| 194 | 200 | } |
| 195 | 201 | var p = ('object' === typeof name) ? name : TheApp.pages[name]; |
| 196 | | - if('object' === typeof p) { |
| 202 | + if(('object' === typeof p) && p.content) { |
| 197 | 203 | doShow(p); |
| 198 | 204 | return; |
| 199 | 205 | } |
| 200 | 206 | TheApp.cgi.sendCommand('/json/wiki/get',{ |
| 201 | 207 | page:name |
| | @@ -206,42 +212,58 @@ |
| 206 | 212 | var p = resp.payload; |
| 207 | 213 | doShow( TheApp.pages[p.name] = p ); |
| 208 | 214 | } |
| 209 | 215 | }); |
| 210 | 216 | }; |
| 211 | | - TheApp.updatePageList = function(list){ |
| 212 | | - var tgt = TheApp.jqe.pageListArea; |
| 213 | | - tgt.empty(); |
| 214 | | - var i, p, a; |
| 217 | + TheApp.refreshPageListView = function(){ |
| 218 | + var list = (function(){ |
| 219 | + var k, v, li = []; |
| 220 | + for( k in TheApp.pages ){ |
| 221 | + if(!TheApp.pages.hasOwnProperty(k)) continue; |
| 222 | + li.push(k); |
| 223 | + } |
| 224 | + return li; |
| 225 | + })(); |
| 226 | + var i, p, a, tgt = TheApp.jqe.pageListArea; |
| 227 | + tgt.text(''); |
| 215 | 228 | function makeLink(name){ |
| 216 | | - var a = jQuery('<span class="wikiPageLink"></span>'); |
| 217 | | - a.text(name). |
| 218 | | - click(function(e){ |
| 229 | + var link = jQuery('<span></span>'); |
| 230 | + link.text(name); |
| 231 | + link.addClass('wikiPageLink'); |
| 232 | + link.click(function(e){ |
| 219 | 233 | TheApp.showPage(name); |
| 220 | 234 | e.preventDefault(); |
| 221 | 235 | return false; |
| 222 | 236 | }); |
| 223 | | - return a; |
| 237 | + return link; |
| 224 | 238 | } |
| 239 | + list.sort(); |
| 225 | 240 | for( i = 0; i < list.length; ++i ){ |
| 226 | | - tgt.append(makeLink(list[i])).append('<br/>'); |
| 241 | + tgt.append(makeLink(list[i])); |
| 242 | + tgt.append('<br/>'); |
| 227 | 243 | } |
| 228 | 244 | }; |
| 229 | 245 | |
| 230 | 246 | TheApp.loadPageList = function(){ |
| 231 | 247 | TheApp.cgi.sendCommand('/json/wiki/list',null,{ |
| 232 | 248 | onResponse:function(resp,req){ |
| 233 | 249 | TheApp.onResponse(resp,req); |
| 234 | 250 | if(resp.resultCode) return; |
| 235 | | - else TheApp.updatePageList(resp.payload); |
| 251 | + var i, v, p, ar = resp.payload; |
| 252 | + for( i = 0; i < ar.length; ++i ){ |
| 253 | + v = ar[i]; |
| 254 | + p = TheApp.pages[v]; |
| 255 | + if( !p ) TheApp.pages[v] = {name:v}; |
| 256 | + } |
| 257 | + TheApp.refreshPageListView(); |
| 236 | 258 | } |
| 237 | 259 | }); |
| 238 | 260 | return false /*for click handlers*/; |
| 239 | 261 | } |
| 240 | 262 | |
| 241 | 263 | TheApp.savePage = function(p){ |
| 242 | | - p = p || TheApp.currentPage || TheApp.pages[TheApp.currentPage]; |
| 264 | + p = p || TheApp.currentPage; |
| 243 | 265 | if( 'object' !== typeof p ){ |
| 244 | 266 | p = TheApp.pages[p]; |
| 245 | 267 | } |
| 246 | 268 | if('object' !== typeof p){ |
| 247 | 269 | alert("savePage() argument is not a page object or known page name."); |
| | @@ -251,11 +273,43 @@ |
| 251 | 273 | var req = { |
| 252 | 274 | name:p.name, |
| 253 | 275 | content:p.content |
| 254 | 276 | }; |
| 255 | 277 | if(! confirm("Really save wiki page ["+p.name+"]?") ) return; |
| 256 | | - TheApp.cgi.sendCommand('/json/wiki/save',req); |
| 278 | + TheApp.cgi.sendCommand('/json/wiki/'+(p.isNew?'create':'save'),req,{ |
| 279 | + onResponse:function(resp,req){ |
| 280 | + TheApp.onResponse(resp,req); |
| 281 | + if(resp.resultCode) return; |
| 282 | + delete p.isNew; |
| 283 | + p.timestamp = resp.payload.timestamp; |
| 284 | + } |
| 285 | + }); |
| 286 | + |
| 287 | + }; |
| 288 | + |
| 289 | + TheApp.createNewPage = function(){ |
| 290 | + var name = prompt("New page name?"); |
| 291 | + if(!name) return; |
| 292 | + var p = { |
| 293 | + name:name, |
| 294 | + content:"New, empty page.", |
| 295 | + isNew:true |
| 296 | + }; |
| 297 | + TheApp.pages[name] = p; |
| 298 | + TheApp.refreshPageListView(); |
| 299 | + TheApp.showPage(p); |
| 300 | +/* |
| 301 | + if(! confirm("Really create new wiki page ["+name+"]?") ) return; |
| 302 | + TheApp.cgi.sendCommand('/json/wiki/create',req,{ |
| 303 | + onResponse:function(resp,req){ |
| 304 | + TheApp.onResponse(resp,req); |
| 305 | + if(resp.resultCode) return; |
| 306 | + TheApp.pages[p.name] = p; |
| 307 | + TheApp.refreshPageListView(); |
| 308 | + } |
| 309 | + }); |
| 310 | +*/ |
| 257 | 311 | }; |
| 258 | 312 | |
| 259 | 313 | }); |
| 260 | 314 | |
| 261 | 315 | </script> |
| | @@ -303,10 +357,11 @@ |
| 303 | 357 | <th>Page List</th> |
| 304 | 358 | <th>Content <span id='spanPageName'></span></th> |
| 305 | 359 | </tr> |
| 306 | 360 | <tr> |
| 307 | 361 | <td width='25%' valign='top'> |
| 362 | + <input type='button' value='Create new...' onclick='TheApp.createNewPage()' /><br/> |
| 308 | 363 | <div id='pageListArea'></div> |
| 309 | 364 | </td> |
| 310 | 365 | <td width='75%' valign='top'> |
| 311 | 366 | <input type='button' value='Save' onclick='TheApp.savePage()' /><br/> |
| 312 | 367 | <textarea id='taPageContent' rows='20' cols='60'></textarea> |
| 313 | 368 | |