includes/clientside/static/ajax.js
changeset 522 fd46b1bf708e
parent 481 07bf15b066bc
child 526 b2fb50d572c7
equal deleted inserted replaced
519:94214ec0871c 522:fd46b1bf708e
   237 function ajaxRename()
   237 function ajaxRename()
   238 {
   238 {
   239   // IE <6 pseudo-compatibility
   239   // IE <6 pseudo-compatibility
   240   if ( KILL_SWITCH )
   240   if ( KILL_SWITCH )
   241     return true;
   241     return true;
   242   r = prompt($lang.get('ajax_rename_prompt'));
   242   
   243   if(!r || r=='') return;
   243   // updated - 1.1.4 to use miniPrompt
   244   setAjaxLoading();
   244   miniPrompt(ajaxRenameConstructDialog);
   245   ajaxPost(stdAjaxPrefix+'&_mode=rename', 'newtitle='+ajaxEscape(r), function() {
   245 }
   246     if ( ajax.readyState == 4 && ajax.status == 200 ) {
   246 
   247       unsetAjaxLoading();
   247 var ajaxRenameConstructDialog = function(div)
   248       alert(ajax.responseText);
   248 {
   249     }
   249   // title
   250   }, true);
   250   var heading = document.createElement('h3');
       
   251   heading.appendChild(document.createTextNode($lang.get('ajax_rename_prompt_short')));
       
   252   div.appendChild(heading);
       
   253   
       
   254   // form
       
   255   var form = document.createElement('form');
       
   256   form.action = 'javascript:void(0);';
       
   257   
       
   258   // box
       
   259   var box = document.createElement('input');
       
   260   box.size = '43';
       
   261   box.style.width = '100%';
       
   262   form.appendChild(box);
       
   263   div.appendChild(form);
       
   264   
       
   265   // notice
       
   266   var notice = document.createElement('small');
       
   267   notice.appendChild(document.createTextNode($lang.get('ajax_rename_notice')));
       
   268   div.appendChild(notice);
       
   269   
       
   270   // button area
       
   271   var btndiv = document.createElement('div');
       
   272   btndiv.className = 'mp-buttons';
       
   273   
       
   274   // buttons
       
   275   var btn_submit = document.createElement('a');
       
   276   btn_submit.href = '#';
       
   277   btn_submit.appendChild(document.createTextNode($lang.get('etc_go')));
       
   278   btn_submit.className = 'fakebutton fakebutton-submit';
       
   279   
       
   280   var btn_cancel = document.createElement('a');
       
   281   btn_cancel.href = '#';
       
   282   btn_cancel.appendChild(document.createTextNode($lang.get('etc_cancel')));
       
   283   btn_cancel.className = 'fakebutton';
       
   284   
       
   285   btndiv.appendChild(btn_submit);
       
   286   btndiv.appendChild(document.createTextNode(' | '));
       
   287   btndiv.appendChild(btn_cancel);
       
   288   div.appendChild(btndiv);
       
   289   
       
   290   // events
       
   291   btn_submit.onclick = function()
       
   292   {
       
   293     ajaxRenameSubmit(this);
       
   294     return false;
       
   295   }
       
   296   btn_cancel.onclick = function()
       
   297   {
       
   298     miniPromptDestroy(this);
       
   299     return false;
       
   300   }
       
   301   form.onsubmit = function()
       
   302   {
       
   303     ajaxRenameSubmit(this);
       
   304     return false;
       
   305   }
       
   306   
       
   307   setTimeout(function()
       
   308     {
       
   309       box.focus();
       
   310     }, 200);
       
   311 }
       
   312 
       
   313 function ajaxRenameSubmit(obj)
       
   314 {
       
   315   var box = miniPromptGetParent(obj);
       
   316   if ( !box )
       
   317     return false;
       
   318   
       
   319   var newname = ( obj.getElementsByTagName('input')[0] ).value;
       
   320   newname = trim(newname);
       
   321   
       
   322   if ( newname.length < 1 )
       
   323   {
       
   324     alert($lang.get('ajax_rename_too_short'));
       
   325     return false;
       
   326   }
       
   327   
       
   328   if ( !newname )
       
   329   {
       
   330     return false;
       
   331   }
       
   332   
       
   333   var innerBox = getElementsByClassName(box, 'div', 'mp-body')[0];
       
   334   var whiteout = whiteOutElement(innerBox);
       
   335   whiteout.style.width = ( $(whiteout).Width() - 78 ) + 'px';
       
   336   whiteout.style.left = ( $(whiteout).Left() + 44 ) + 'px';
       
   337   
       
   338   ajaxPost(stdAjaxPrefix + '&_mode=rename', 'newtitle=' + ajaxEscape(newname), function()
       
   339     {
       
   340       if ( ajax.readyState == 4 && ajax.status == 200 )
       
   341       {
       
   342         whiteout.parentNode.removeChild(whiteout);
       
   343         var response = String(ajax.responseText);
       
   344         if ( response.substr(0, 1) != '{' )
       
   345         {
       
   346           handle_invalid_json(response);
       
   347           return false;
       
   348         }
       
   349         response = parseJSON(response);
       
   350         if ( response.success )
       
   351         {
       
   352           miniPromptDestroy(box, true);
       
   353           ajaxRenameDoClientTransform(newname);
       
   354           new messagebox( MB_OK|MB_ICONINFORMATION, $lang.get('ajax_rename_success_title'), $lang.get('ajax_rename_success_body', { page_name_new: newname }) );
       
   355           mb_previously_had_darkener = false;
       
   356         }
       
   357         else
       
   358         {
       
   359           var errmsg = $lang.get('page_err_' + response.error);
       
   360           alert(errmsg);
       
   361         }
       
   362       }
       
   363     }, true);
       
   364 }
       
   365 
       
   366 function ajaxRenameDoClientTransform(newname)
       
   367 {
       
   368   var obj = document.getElementById('h2PageName');
       
   369   if ( obj )
       
   370   {
       
   371     obj.firstChild.nodeValue = newname;
       
   372   }
       
   373   document.title = newname;
   251 }
   374 }
   252 
   375 
   253 function ajaxMakePage()
   376 function ajaxMakePage()
   254 {
   377 {
   255   // IE <6 pseudo-compatibility
   378   // IE <6 pseudo-compatibility