includes/clientside/static/ajax.js
changeset 526 b2fb50d572c7
parent 522 fd46b1bf708e
child 527 21e11f564463
equal deleted inserted replaced
525:3f2dfdb99be4 526:b2fb50d572c7
  1515         }
  1515         }
  1516       }
  1516       }
  1517     });
  1517     });
  1518 }
  1518 }
  1519 
  1519 
       
  1520 function ajaxPluginAction(action, plugin_filename, btnobj)
       
  1521 {
       
  1522   // if installing or uninstalling, confirm
       
  1523   if ( action == 'install' || action == 'uninstall' )
       
  1524   {
       
  1525     var prompt = miniPrompt(function(div)
       
  1526       {
       
  1527         var txtholder = document.createElement('div');
       
  1528         txtholder.style.textAlign = 'center';
       
  1529         txtholder.appendChild(document.createTextNode($lang.get('acppl_msg_confirm_' + action)));
       
  1530         txtholder.appendChild(document.createElement('br'));
       
  1531         txtholder.appendChild(document.createElement('br'));
       
  1532         
       
  1533         // create buttons
       
  1534         var btn_go = document.createElement('a');
       
  1535         btn_go.className = 'abutton abutton_red';
       
  1536         btn_go.href = '#';
       
  1537         btn_go._action = action;
       
  1538         btn_go._filename = plugin_filename;
       
  1539         btn_go._button = btnobj;
       
  1540         btn_go.appendChild(document.createTextNode($lang.get('acppl_btn_' + action)));
       
  1541         btn_go.style.fontWeight = 'bold';
       
  1542         txtholder.appendChild(btn_go);
       
  1543         
       
  1544         // space
       
  1545         txtholder.appendChild(document.createTextNode(' '));
       
  1546         
       
  1547         // cancel
       
  1548         var btn_cancel = document.createElement('a');
       
  1549         btn_cancel.className = 'abutton abutton_blue';
       
  1550         btn_cancel.href = '#';
       
  1551         btn_cancel.appendChild(document.createTextNode($lang.get('etc_cancel')));
       
  1552         
       
  1553         txtholder.appendChild(btn_cancel);
       
  1554         div.appendChild(txtholder);
       
  1555         
       
  1556         btn_go.onclick = function()
       
  1557         {
       
  1558           ajaxPluginAction(this._action + '_confirm', this._filename, this._button);
       
  1559           miniPromptDestroy(this);
       
  1560           return false;
       
  1561         }
       
  1562         btn_cancel.onclick = function()
       
  1563         {
       
  1564           miniPromptDestroy(this);
       
  1565           return false;
       
  1566         }
       
  1567       });
       
  1568     return true;
       
  1569   }
       
  1570   action = action.replace(/_confirm$/, '');
       
  1571   var request = toJSONString({
       
  1572       mode: action,
       
  1573       plugin: plugin_filename
       
  1574     });
       
  1575   ajaxPost(makeUrlNS('Admin', 'PluginManager/action.json'), 'r=' + ajaxEscape(request), function()
       
  1576     {
       
  1577       if ( ajax.readyState == 4 && ajax.status == 200 )
       
  1578       {
       
  1579         if ( ajax.responseText == 'good' )
       
  1580         {
       
  1581           ajaxPage( namespace_list['Admin'] + 'PluginManager' );
       
  1582         }
       
  1583         else
       
  1584         {
       
  1585           var response = String(ajax.responseText + '');
       
  1586           if ( response.substr(0, 1) != '{' )
       
  1587           {
       
  1588             handle_invalid_json(response);
       
  1589             return false;
       
  1590           }
       
  1591           response = parseJSON(response);
       
  1592           if ( response.mode != 'error' )
       
  1593           {
       
  1594             console.debug(response);
       
  1595             return false;
       
  1596           }
       
  1597           // wait for fade effect to finish its run
       
  1598           setTimeout(function()
       
  1599             {
       
  1600               miniPrompt(function(div)
       
  1601                 {
       
  1602                   var txtholder = document.createElement('div');
       
  1603                   txtholder.style.textAlign = 'center';
       
  1604                   txtholder.appendChild(document.createTextNode(response.error));
       
  1605                   txtholder.appendChild(document.createElement('br'));
       
  1606                   txtholder.appendChild(document.createElement('br'));
       
  1607                   
       
  1608                   // close button
       
  1609                   var btn_cancel = document.createElement('a');
       
  1610                   btn_cancel.className = 'abutton abutton_red';
       
  1611                   btn_cancel.href = '#';
       
  1612                   btn_cancel.appendChild(document.createTextNode($lang.get('etc_ok')));
       
  1613                   
       
  1614                   txtholder.appendChild(btn_cancel);
       
  1615                   div.appendChild(txtholder);
       
  1616                   
       
  1617                   btn_cancel.onclick = function()
       
  1618                   {
       
  1619                     miniPromptDestroy(this);
       
  1620                     return false;
       
  1621                   }
       
  1622                 });
       
  1623             }, 750);
       
  1624         }
       
  1625       }
       
  1626     });
       
  1627 }