includes/clientside/static/ajax.js
changeset 696 bd5069e1f19a
parent 672 08a7875258b4
child 699 c7d737202d59
equal deleted inserted replaced
695:6bd7215c718b 696:bd5069e1f19a
   220 {
   220 {
   221   // IE <6 pseudo-compatibility
   221   // IE <6 pseudo-compatibility
   222   if ( KILL_SWITCH )
   222   if ( KILL_SWITCH )
   223     return true;
   223     return true;
   224   load_component('l10n');
   224   load_component('l10n');
   225   var reason = prompt($lang.get('ajax_delete_prompt_reason'));
   225   load_component('messagebox');
   226   if ( !reason || reason == '' )
   226   load_component('SpryEffects');
   227   {
   227   
   228     return false;
   228   // stage 1: prompt for reason and confirmation
   229   }
   229   miniPrompt(function(parent)
   230   c = confirm($lang.get('ajax_delete_confirm'));
   230     {
   231   if(!c)
   231       // heading/title
   232   {
   232       var h3 = document.createElement('h3');
   233     return;
   233       h3.appendChild(document.createTextNode($lang.get('ajax_delete_header')));
   234   }
   234       parent.appendChild(h3);
       
   235       
       
   236       // "please enter your reason"
       
   237       var p1 = document.createElement('p');
       
   238       p1.appendChild(document.createTextNode($lang.get('ajax_delete_prompt_reason')));
       
   239       parent.appendChild(p1);
       
   240       
       
   241       // textbox + label thereof
       
   242       var p2 = document.createElement('p');
       
   243       var tb = document.createElement('input');
       
   244       var dl = document.createElement('label');
       
   245       
       
   246       tb.type = 'text';
       
   247       tb.size = '30';
       
   248       tb.onkeyup = function(e)
       
   249       {
       
   250         if ( e )
       
   251         if ( e.keyCode )
       
   252         if ( e.keyCode == 13 )
       
   253         {
       
   254           if ( ajaxDeletePageSubmit(this) )
       
   255           {
       
   256             miniPromptDestroy(this);
       
   257           }
       
   258         }
       
   259         else if ( e.keyCode == 27 )
       
   260         {
       
   261           miniPromptDestroy(this);
       
   262         }
       
   263       }
       
   264       
       
   265       dl.appendChild(document.createTextNode($lang.get('ajax_delete_lbl_reason') + ' '));
       
   266       dl.appendChild(tb);
       
   267       p2.appendChild(dl);
       
   268       parent.appendChild(p2);
       
   269       
       
   270       // notice underneath
       
   271       var p3 = document.createElement('p');
       
   272       p3.style.fontSize = 'smaller';
       
   273       p3.appendChild(document.createTextNode($lang.get('ajax_delete_msg_confirm')));
       
   274       parent.appendChild(p3);
       
   275       
       
   276       // confirmation + submit/cancel (structure)
       
   277       var divleft  = document.createElement('div');
       
   278       var divright = document.createElement('div');
       
   279       var divclear = document.createElement('div');
       
   280       
       
   281       divleft.style.cssFloat = 'left';
       
   282       divleft.style.styleFloat = 'left';
       
   283       
       
   284       divright.style.cssFloat = 'right';
       
   285       divright.style.styleFloat = 'right';
       
   286       
       
   287       divclear.style.clear = 'both';
       
   288       
       
   289       parent.appendChild(divleft);
       
   290       parent.appendChild(divright);
       
   291       parent.appendChild(divclear);
       
   292       
       
   293       // confirmation + submit/cancel (controls)
       
   294       var cb = document.createElement('input');
       
   295       var cl = document.createElement('label');
       
   296       
       
   297       cb.type = 'checkbox';
       
   298       cb.checked = false;
       
   299       
       
   300       // a bit of a hack here, doesn't seem to work in fx3
       
   301       cb.onblur = function(e)
       
   302       {
       
   303         var parent = this.parentNode.parentNode.parentNode;
       
   304         var submitter = parent.getElementsByTagName('a')[0];
       
   305         if ( submitter )
       
   306           submitter.focus();
       
   307       }
       
   308       
       
   309       cl.appendChild(cb);
       
   310       cl.appendChild(document.createTextNode(' ' + $lang.get('ajax_delete_lbl_confirm')));
       
   311       divleft.appendChild(cl);
       
   312       
       
   313       var btn_submit = document.createElement('a');
       
   314       btn_submit.className = 'abutton abutton_red';
       
   315       btn_submit.href = '#';
       
   316       btn_submit.appendChild(document.createTextNode($lang.get('ajax_delete_btn_delete')));
       
   317       btn_submit.onclick = function()
       
   318       {
       
   319         if ( ajaxDeletePageSubmit(this) )
       
   320         {
       
   321           miniPromptDestroy(this);
       
   322         }
       
   323         return false;
       
   324       }
       
   325       
       
   326       var btn_cancel = document.createElement('a');
       
   327       btn_cancel.className = 'abutton';
       
   328       btn_cancel.href = '#';
       
   329       btn_cancel.appendChild(document.createTextNode($lang.get('etc_cancel')));
       
   330       btn_cancel.onclick = function()
       
   331       {
       
   332         miniPromptDestroy(this);
       
   333         return false;
       
   334       }
       
   335       
       
   336       divright.appendChild(btn_submit);
       
   337       divright.appendChild(document.createTextNode(' '));
       
   338       divright.appendChild(btn_cancel);
       
   339       
       
   340       var timeout = ( aclDisableTransitionFX ) ? 10 : 1000;
       
   341       setTimeout(function()
       
   342         {
       
   343           tb.focus();
       
   344         }, timeout);
       
   345     });
       
   346 }
       
   347 
       
   348 window.ajaxDeletePageSubmit = function(prompt_obj)
       
   349 {
       
   350   prompt_obj = miniPromptGetParent(prompt_obj).childNodes[1];
       
   351   var inputs = prompt_obj.getElementsByTagName('input');
       
   352   var reason = inputs[0];
       
   353   var confirm = inputs[1];
       
   354   
       
   355   if ( trim(reason.value) == '' )
       
   356   {
       
   357     // flash the background of the reason entry
       
   358     if ( !reason.sfx )
       
   359       reason.sfx = new Spry.Effect.Highlight(reason.parentNode);
       
   360     
       
   361     reason.sfx.start();
       
   362     return false;
       
   363   }
       
   364   
       
   365   if ( !confirm.checked )
       
   366   {
       
   367     // flash the background of the confirm checkbox
       
   368     if ( !confirm.sfx )
       
   369       confirm.sfx = new Spry.Effect.Highlight(confirm.parentNode);
       
   370     
       
   371     confirm.sfx.start();
       
   372     return false;
       
   373   }
       
   374   
       
   375   prompt_obj.innerHTML = '<img alt="loading" style="display: block; margin: 0 auto;" src="' + cdnPath + '/images/loading-big.gif" />';
       
   376   
       
   377   // tenemos la confirmación y la razón - borre la página.
   235   setAjaxLoading();
   378   setAjaxLoading();
   236   ajaxPost(stdAjaxPrefix+'&_mode=deletepage', 'reason=' + ajaxEscape(reason), function() {
   379   ajaxPost(stdAjaxPrefix + '&_mode=deletepage', 'reason=' + ajaxEscape(trim(reason.value)), function()
   237     if ( ajax.readyState == 4 && ajax.status == 200 ) {
   380     {
   238       unsetAjaxLoading();
   381       if ( ajax.readyState == 4 && ajax.status == 200 )
   239       alert(ajax.responseText);
   382       {
   240       window.location.reload();                                                                           
   383         unsetAjaxLoading();
   241     }
   384         
   242   });
   385         // show the response in the same prompt window
       
   386         prompt_obj.style.textAlign = 'center';
       
   387         prompt_obj.innerHTML = '';
       
   388         
       
   389         var p1 = document.createElement('div');
       
   390         p1.style.marginBottom = '15px';
       
   391         p1.appendChild(document.createTextNode(ajax.responseText));
       
   392         prompt_obj.appendChild(p1);
       
   393         
       
   394         var p2 = document.createElement('p');
       
   395         var a = document.createElement('a');
       
   396         a.className = 'abutton';
       
   397         a.href = '#';
       
   398         a.appendChild(document.createTextNode($lang.get('etc_close')));
       
   399         a.onclick = function()
       
   400         {
       
   401           miniPromptDestroy(this);
       
   402           window.location.reload();
       
   403           return false;
       
   404         }
       
   405         p2.appendChild(a);
       
   406         prompt_obj.appendChild(a);
       
   407         
       
   408         a.focus();
       
   409       }
       
   410     });
       
   411   
       
   412   return true;
   243 }
   413 }
   244 
   414 
   245 window.ajaxDelVote = function()
   415 window.ajaxDelVote = function()
   246 {
   416 {
   247   load_component('l10n');
   417   load_component('l10n');