includes/clientside/static/theme-manager.js
changeset 465 fe8b8c9b54e8
parent 435 a434d60e525d
child 651 ce9d78d7251d
equal deleted inserted replaced
464:8063eace5b67 465:fe8b8c9b54e8
    38     return false;
    38     return false;
    39   thediv.removeChild(thediv.getElementsByTagName('a')[0]);
    39   thediv.removeChild(thediv.getElementsByTagName('a')[0]);
    40   var status = document.createElement('div');
    40   var status = document.createElement('div');
    41   status.className = 'status';
    41   status.className = 'status';
    42   thediv.appendChild(status);
    42   thediv.appendChild(status);
    43   setTimeout(function()
    43   
    44     {
    44   var req = toJSONString({
    45       var theme_list = document.getElementById('theme_list_edit');
    45       mode: 'install',
    46       
    46       theme_id: theme_id
    47       var btn = document.createElement('div');
    47     });
    48       btn.className = 'themebutton';
    48   // we've finished nukeing the existing interface, request editor data
    49       btn.style.backgroundImage = thediv.style.backgroundImage;
    49   ajaxPost(makeUrlNS('Admin', 'ThemeManager/action.json'), 'r=' + ajaxEscape(req), function()
    50       btn.id = 'themebtn_edit_' + theme_id;
    50     {
    51       
    51       if ( ajax.readyState == 4 && ajax.status == 200 )
    52       var a = document.createElement('a');
       
    53       a.className = 'tb-inner';
       
    54       a.appendChild(document.createTextNode($lang.get('acptm_btn_theme_edit')));
       
    55       a.appendChild(document.createTextNode("\n"));
       
    56       a.theme_id = theme_id;
       
    57       a.onclick = function()
       
    58       {
    52       {
    59         ajaxEditTheme(this.theme_id);
    53         var response = String(ajax.responseText + '');
    60         return false;
    54         if ( response.substr(0, 1) == '{' )
       
    55         {
       
    56           response = parseJSON(response);
       
    57           if ( response.mode == 'error' )
       
    58           {
       
    59             alert(response.error);
       
    60             return false;
       
    61           }
       
    62         }
       
    63         
       
    64         var theme_list = document.getElementById('theme_list_edit');
       
    65   
       
    66         var btn = document.createElement('div');
       
    67         btn.className = 'themebutton';
       
    68         btn.style.backgroundImage = thediv.style.backgroundImage;
       
    69         btn.id = 'themebtn_edit_' + theme_id;
       
    70         
       
    71         var a = document.createElement('a');
       
    72         a.className = 'tb-inner';
       
    73         a.appendChild(document.createTextNode($lang.get('acptm_btn_theme_edit')));
       
    74         a.appendChild(document.createTextNode("\n"));
       
    75         a.theme_id = theme_id;
       
    76         a.onclick = function()
       
    77         {
       
    78           ajaxEditTheme(this.theme_id);
       
    79           return false;
       
    80         }
       
    81         a.href = '#';
       
    82         var span = document.createElement('span');
       
    83         span.className = 'themename';
       
    84         span.appendChild(document.createTextNode(thediv.getAttribute('enano:themename')));
       
    85         a.appendChild(span);
       
    86         btn.appendChild(a);
       
    87         btn.setAttribute('enano:themename', thediv.getAttribute('enano:themename'));
       
    88         theme_list.appendChild(btn);
       
    89         
       
    90         thediv.parentNode.removeChild(thediv);
    61       }
    91       }
    62       a.href = '#';
    92     });
    63       var span = document.createElement('span');
       
    64       span.className = 'themename';
       
    65       span.appendChild(document.createTextNode(thediv.getAttribute('enano:themename')));
       
    66       a.appendChild(span);
       
    67       btn.appendChild(a);
       
    68       btn.setAttribute('enano:themename', thediv.getAttribute('enano:themename'));
       
    69       theme_list.appendChild(btn);
       
    70       
       
    71       thediv.parentNode.removeChild(thediv);
       
    72     }, 3000);
       
    73 }
    93 }
    74 
    94 
    75 function ajaxEditTheme(theme_id)
    95 function ajaxEditTheme(theme_id)
    76 {
    96 {
    77   // Fade out and subsequently destroy the entire list, then make an
    97   // Fade out and subsequently destroy the entire list, then make an
    78   // ajax request to the theme manager for the theme info via JSON
    98   // ajax request to the theme manager for the theme info via JSON
    79   var theme_list = document.getElementById('theme_list_edit').parentNode;
    99   var theme_list = document.getElementById('theme_list_edit').parentNode;
    80   var backgroundImage = document.getElementById('themebtn_edit_' + theme_id).style.backgroundImage;
   100   var backgroundImage = document.getElementById('themebtn_edit_' + theme_id).style.backgroundImage;
       
   101   /*
    81   for ( var i = 0; i < theme_list.childNodes.length; i++ )
   102   for ( var i = 0; i < theme_list.childNodes.length; i++ )
    82   {
   103   {
    83     var el = theme_list.childNodes[i];
   104     var el = theme_list.childNodes[i];
    84     if ( el.tagName )
   105     if ( el.tagName )
    85       domOpacity(el, 100, 0, 1000);
   106       domOpacity(el, 100, 0, 1000);
    86   }
   107   }
       
   108   */
       
   109   var thediv = document.getElementById('themebtn_edit_' + theme_id);
       
   110   if ( !thediv )
       
   111     return false;
       
   112   thediv.removeChild(thediv.getElementsByTagName('a')[0]);
       
   113   var status = document.createElement('div');
       
   114   status.className = 'status';
       
   115   thediv.appendChild(status);
       
   116   
    87   setTimeout(function()
   117   setTimeout(function()
    88     {
   118     {
    89       theme_list.innerHTML = '';
       
    90       var req = toJSONString({
   119       var req = toJSONString({
    91           mode: 'fetch_theme',
   120           mode: 'fetch_theme',
    92           theme_id: theme_id
   121           theme_id: theme_id
    93         });
   122         });
    94       // we've finished nukeing the existing interface, request editor data
   123       // we've finished nukeing the existing interface, request editor data
    95       ajaxPost(makeUrlNS('Admin', 'ThemeManager/action.json'), 'r=' + ajaxEscape(req), function()
   124       ajaxPost(makeUrlNS('Admin', 'ThemeManager/action.json'), 'r=' + ajaxEscape(req), function()
    96         {
   125         {
    97           if ( ajax.readyState == 4 && ajax.status == 200 )
   126           if ( ajax.readyState == 4 && ajax.status == 200 )
    98           {
   127           {
       
   128             theme_list.innerHTML = '';
    99             var response = String(ajax.responseText + '');
   129             var response = String(ajax.responseText + '');
   100             if ( response.substr(0, 1) != '{' )
   130             if ( response.substr(0, 1) != '{' )
   101             {
   131             {
   102               alert(response);
   132               alert(response);
   103               return false;
   133               return false;
   110             }
   140             }
   111             response.background_image = backgroundImage;
   141             response.background_image = backgroundImage;
   112             ajaxBuildThemeEditor(response, theme_list);
   142             ajaxBuildThemeEditor(response, theme_list);
   113           }
   143           }
   114         });
   144         });
   115     }, 1050);
   145     }, 200);
   116 }
   146 }
   117 
   147 
   118 function ajaxBuildThemeEditor(data, target)
   148 function ajaxBuildThemeEditor(data, target)
   119 {
   149 {
   120   // Build the theme editor interface
   150   // Build the theme editor interface
   150   f_name.size = '40';
   180   f_name.size = '40';
   151   l_name.appendChild(f_name);
   181   l_name.appendChild(f_name);
   152   target.appendChild(l_name);
   182   target.appendChild(l_name);
   153   
   183   
   154   target.appendChild(document.createElement('br'));
   184   target.appendChild(document.createElement('br'));
       
   185   target.appendChild(document.createElement('br'));
   155   
   186   
   156   // Field: default style
   187   // Field: default style
   157   var l_style = document.createElement('label');
   188   var l_style = document.createElement('label');
   158   l_style.appendChild(document.createTextNode($lang.get('acptm_field_default_style') + ' '));
   189   l_style.appendChild(document.createTextNode($lang.get('acptm_field_default_style') + ' '));
   159   var f_style = document.createElement('select');
   190   var f_style = document.createElement('select');
   175   }
   206   }
   176   l_style.appendChild(f_style);
   207   l_style.appendChild(f_style);
   177   target.appendChild(l_style);
   208   target.appendChild(l_style);
   178   
   209   
   179   target.appendChild(document.createElement('br'));
   210   target.appendChild(document.createElement('br'));
       
   211   target.appendChild(document.createElement('br'));
   180   
   212   
   181   // Default theme
   213   // Default theme
   182   target.appendChild(document.createTextNode($lang.get('acptm_field_default_theme') + ' '));
   214   target.appendChild(document.createTextNode($lang.get('acptm_field_default_theme') + ' '));
   183   if ( data.is_default )
   215   if ( data.is_default )
   184   {
   216   {
   194     l_default.appendChild(f_default);
   226     l_default.appendChild(f_default);
   195     l_default.appendChild(document.createTextNode($lang.get('acptm_field_default_btn_make_default')));
   227     l_default.appendChild(document.createTextNode($lang.get('acptm_field_default_btn_make_default')));
   196   }
   228   }
   197   target.appendChild(l_default);
   229   target.appendChild(l_default);
   198   
   230   
       
   231   target.appendChild(document.createElement('br'));
       
   232   target.appendChild(document.createElement('br'));
       
   233   
       
   234   // Disable theme
       
   235   var disable_span = document.createElement('span');
       
   236   disable_span.appendChild(document.createTextNode($lang.get('acptm_field_disable_title') + ' '));
       
   237   target.appendChild(disable_span);
       
   238   var l_disable = document.createElement('label');
       
   239   var f_disable = document.createElement('input');
       
   240   f_disable.type = 'checkbox';
       
   241   f_disable.id = 'themeed_field_disable';
       
   242   if ( !data.enabled )
       
   243     f_disable.setAttribute('checked', 'checked');
       
   244   l_disable.style.fontWeight = 'bold';
       
   245   l_disable.appendChild(f_disable);
       
   246   l_disable.appendChild(document.createTextNode($lang.get('acptm_field_disable')));
       
   247   target.appendChild(l_disable);
       
   248   
   199   // Availability policy
   249   // Availability policy
   200   var h3 = document.createElement('h3');
   250   var h3 = document.createElement('h3');
   201   h3.appendChild(document.createTextNode($lang.get('acptm_heading_theme_groups')));
   251   h3.appendChild(document.createTextNode($lang.get('acptm_heading_theme_groups')));
   202   target.appendChild(h3);
   252   target.appendChild(h3);
   203   
   253   
       
   254   // Label for the whole field
       
   255   var p_d_policy = document.createElement('p');
       
   256   p_d_policy.style.fontWeight = 'bold';
       
   257   p_d_policy.appendChild(document.createTextNode($lang.get('acptm_field_policy')));
       
   258   target.appendChild(p_d_policy);
       
   259   
       
   260   // Wrapper for options
       
   261   var p_f_policy = document.createElement('p');
       
   262   
       
   263   // Option: allow all
       
   264   var l_policy_allow_all = document.createElement('label');
       
   265   var f_policy_allow_all = document.createElement('input');
       
   266   f_policy_allow_all.type = 'radio';
       
   267   f_policy_allow_all.id = 'themeed_field_policy_allow_all';
       
   268   f_policy_allow_all.name = 'themeed_field_policy';
       
   269   f_policy_allow_all.value = 'allow_all';
       
   270   l_policy_allow_all.appendChild(f_policy_allow_all);
       
   271   l_policy_allow_all.appendChild(document.createTextNode(' ' + $lang.get('acptm_field_policy_allow_all')));
       
   272   if ( data.group_policy == 'allow_all' )
       
   273   {
       
   274     f_policy_allow_all.setAttribute('checked', 'checked');
       
   275   }
       
   276   
       
   277   // Option: whitelist
       
   278   var l_policy_whitelist = document.createElement('label');
       
   279   var f_policy_whitelist = document.createElement('input');
       
   280   f_policy_whitelist.type = 'radio';
       
   281   f_policy_whitelist.id = 'themeed_field_policy_whitelist';
       
   282   f_policy_whitelist.name = 'themeed_field_policy';
       
   283   f_policy_whitelist.value = 'whitelist';
       
   284   l_policy_whitelist.appendChild(f_policy_whitelist);
       
   285   l_policy_whitelist.appendChild(document.createTextNode(' ' + $lang.get('acptm_field_policy_whitelist')));
       
   286   if ( data.group_policy == 'whitelist' )
       
   287   {
       
   288     f_policy_whitelist.setAttribute('checked', 'checked');
       
   289   }
       
   290   
       
   291   // Option: blacklist
       
   292   var l_policy_blacklist = document.createElement('label');
       
   293   var f_policy_blacklist = document.createElement('input');
       
   294   f_policy_blacklist.type = 'radio';
       
   295   f_policy_blacklist.id = 'themeed_field_policy_blacklist';
       
   296   f_policy_blacklist.name = 'themeed_field_policy';
       
   297   f_policy_blacklist.value = 'blacklist';
       
   298   l_policy_blacklist.appendChild(f_policy_blacklist);
       
   299   l_policy_blacklist.appendChild(document.createTextNode(' ' + $lang.get('acptm_field_policy_blacklist')));
       
   300   if ( data.group_policy == 'blacklist' )
       
   301   {
       
   302     f_policy_blacklist.setAttribute('checked', 'checked');
       
   303   }
       
   304   f_policy_allow_all.onclick = ajaxThemeManagerHandlePolicyClick;
       
   305   f_policy_whitelist.onclick = ajaxThemeManagerHandlePolicyClick;
       
   306   f_policy_blacklist.onclick = ajaxThemeManagerHandlePolicyClick;
       
   307   
       
   308   p_f_policy.appendChild(l_policy_allow_all);
       
   309   p_f_policy.appendChild(document.createElement('br'));
       
   310   p_f_policy.appendChild(l_policy_whitelist);
       
   311   p_f_policy.appendChild(document.createElement('br'));
       
   312   p_f_policy.appendChild(l_policy_blacklist);
       
   313   
       
   314   target.appendChild(p_d_policy);
       
   315   target.appendChild(p_f_policy);
       
   316   
       
   317   var div_acl = document.createElement('div');
       
   318   div_acl.id = 'themeed_acl_box';
       
   319   div_acl.style.margin = '0 0 10px 30px';
       
   320   
       
   321   var h3_g = document.createElement('h3');
       
   322   h3_g.appendChild(document.createTextNode($lang.get('acptm_field_acl_heading_groups')));
       
   323   div_acl.appendChild(h3_g);
       
   324   
       
   325   var div_groups = document.createElement('div');
       
   326   div_groups.style.border = '1px solid #E8E8E8';
       
   327   div_groups.id = 'themeed_group_list';
       
   328   
       
   329   // Group list
       
   330   for ( var i in data.group_names )
       
   331   {
       
   332     var g_name = data.group_names[i];
       
   333     var check = document.createElement('input');
       
   334     check.type = 'checkbox';
       
   335     if ( in_array("g:" + i, data.group_list) )
       
   336     {
       
   337       check.setAttribute('checked', 'checked');
       
   338     }
       
   339     check.group_id = parseInt(i);
       
   340     var lbl_g_acl = document.createElement('label');
       
   341     lbl_g_acl.appendChild(check);
       
   342     // FIXME: l10n on group name
       
   343     lbl_g_acl.appendChild(document.createTextNode(g_name));
       
   344     div_groups.appendChild(lbl_g_acl);
       
   345     div_groups.appendChild(document.createElement('br'));
       
   346   }
       
   347   div_acl.appendChild(div_groups);
       
   348   
       
   349   var h3_u = document.createElement('h3');
       
   350   h3_u.appendChild(document.createTextNode($lang.get('acptm_field_acl_heading_users')));
       
   351   div_acl.appendChild(h3_u);
       
   352   
       
   353   // User addition field
       
   354   var frm = document.createElement('form');
       
   355   frm.action = 'javascript:ajaxThemeManagerHandleUserAdd();';
       
   356   frm.appendChild(document.createTextNode($lang.get('acptm_field_acl_add_user')));
       
   357   var f_useradd = document.createElement('input');
       
   358   f_useradd.type = 'text';
       
   359   f_useradd.id = 'themeed_field_adduser';
       
   360   f_useradd.onkeyup = function(e)
       
   361   {
       
   362     new AutofillUsername(this, e, false);
       
   363   }
       
   364   
       
   365   frm.appendChild(f_useradd);
       
   366   div_acl.appendChild(frm);
       
   367   
       
   368   div_acl.appendChild(document.createElement('br'));
       
   369   
       
   370   // User list
       
   371   var div_users = document.createElement('div');
       
   372   div_users.style.border = '1px solid #E8E8E8';
       
   373   div_users.style.padding = '4px';
       
   374   div_users.id = 'themeed_user_list';
   204   for ( var i = 0; i < data.group_list.length; i++ )
   375   for ( var i = 0; i < data.group_list.length; i++ )
   205   {
   376   {
       
   377     var id = data.group_list[i];
       
   378     if ( id.substr(0, 2) != 'u:' )
       
   379       continue;
       
   380     var uid = id.substr(2);
       
   381     var username = data.usernames[uid];
   206     
   382     
   207   }
   383     var useritem = document.createElement('span');
       
   384     useritem.appendChild(document.createTextNode(username + ' '));
       
   385     useritem.userid = parseInt(uid);
       
   386     var deleter = document.createElement('a');
       
   387     deleter.href = '#';
       
   388     deleter.onclick = function()
       
   389     {
       
   390       ajaxThemeManagerHandleUserRemoval(this);
       
   391       return false;
       
   392     }
       
   393     deleter.appendChild(document.createTextNode('[X]'));
       
   394     useritem.appendChild(deleter);
       
   395     div_users.appendChild(useritem);
       
   396     div_users.appendChild(document.createElement('br'));
       
   397   }
       
   398   div_acl.appendChild(div_users);
       
   399   
       
   400   target.appendChild(div_acl);
       
   401   
       
   402   ajaxThemeManagerHandlePolicyClick();
   208   
   403   
   209   var clearer = document.createElement('span');
   404   var clearer = document.createElement('span');
   210   clearer.className = 'menuclear';
   405   clearer.className = 'menuclear';
   211   target.appendChild(clearer);
   406   target.appendChild(clearer);
   212   
   407   
       
   408   // Theme ID
       
   409   var tid = document.createElement('input');
       
   410   tid.type = 'hidden';
       
   411   tid.id = 'themeed_theme_id';
       
   412   tid.value = data.theme_id;
       
   413   target.appendChild(tid);
       
   414   
       
   415   // Save button
       
   416   var raquo = unescape('%BB');
       
   417   var savebtn = document.createElement('input');
       
   418   savebtn.type = 'button';
       
   419   savebtn.style.fontWeight = 'bold';
       
   420   savebtn.value = $lang.get('etc_save_changes') + ' ' + raquo;
       
   421   savebtn.onclick = function()
       
   422   {
       
   423     ajaxThemeManagerHandleSaveRequest();
       
   424   }
       
   425   target.appendChild(savebtn);
       
   426   
       
   427   target.appendChild(document.createTextNode(' '));
       
   428   
       
   429   // Cancel button
       
   430   var savebtn = document.createElement('input');
       
   431   savebtn.type = 'button';
       
   432   savebtn.value = $lang.get('etc_cancel');
       
   433   savebtn.onclick = function()
       
   434   {
       
   435     ajaxPage(namespace_list['Admin'] + 'ThemeManager');
       
   436   }
       
   437   target.appendChild(savebtn);
       
   438   
       
   439   target.appendChild(document.createTextNode(' '));
       
   440   
       
   441   // Uninstall button
       
   442   var savebtn = document.createElement('input');
       
   443   savebtn.type = 'button';
       
   444   savebtn.value = $lang.get('acptm_btn_uninstall_theme');
       
   445   savebtn.style.color = '#D84308';
       
   446   savebtn.onclick = function()
       
   447   {
       
   448     if ( !confirm($lang.get('acptm_msg_uninstall_confirm')) )
       
   449       return false;
       
   450     ajaxThemeManagerHandleUninstallClick();
       
   451   }
       
   452   target.appendChild(savebtn);
       
   453   
   213   // Fade it all in
   454   // Fade it all in
   214   domOpacity(target, 0, 100, 500);
   455   domOpacity(target, 0, 100, 500);
   215   f_name.focus();
   456   f_name.focus();
   216 }
   457 }
       
   458 
       
   459 function ajaxThemeManagerHandlePolicyClick()
       
   460 {
       
   461   if ( document.getElementById('themeed_field_policy_allow_all').checked )
       
   462   {
       
   463     document.getElementById('themeed_acl_box').style.display = 'none';
       
   464   }
       
   465   else if ( document.getElementById('themeed_field_policy_whitelist').checked || document.getElementById('themeed_field_policy_blacklist').checked )
       
   466   {
       
   467     document.getElementById('themeed_acl_box').style.display = 'block';
       
   468   }
       
   469 }
       
   470 
       
   471 function ajaxThemeManagerHandleUserAdd()
       
   472 {
       
   473   var f_useradd = document.getElementById('themeed_field_adduser');
       
   474   f_useradd.setAttribute('disabled', 'disabled');
       
   475   var parent = f_useradd.parentNode;
       
   476   var img = document.createElement('img');
       
   477   img.src = ajax_load_icon;
       
   478   img.id = 'themeed_useradd_status';
       
   479   img.style.marginLeft = '10px';
       
   480   insertAfter(parent, img, f_useradd);
       
   481   
       
   482   var req = toJSONString({
       
   483       mode: 'uid_lookup',
       
   484       username: f_useradd.value
       
   485     });
       
   486   ajaxPost(makeUrlNS('Admin', 'ThemeManager/action.json'), 'r=' + ajaxEscape(req), function()
       
   487     {
       
   488       if ( ajax.readyState == 4 && ajax.status == 200 )
       
   489       {
       
   490         var img = document.getElementById('themeed_useradd_status');
       
   491         var f_useradd = document.getElementById('themeed_field_adduser');
       
   492         
       
   493         f_useradd.disabled = null;
       
   494         img.parentNode.removeChild(img);
       
   495         
       
   496         // process response
       
   497         var response = String(ajax.responseText + '');
       
   498         if ( response.substr(0, 1) != '{' )
       
   499         {
       
   500           alert(response);
       
   501           return false;
       
   502         }
       
   503         response = parseJSON(response);
       
   504         if ( response.mode == 'error' )
       
   505         {
       
   506           alert(response.error);
       
   507           return false;
       
   508         }
       
   509             
       
   510         var uid = parseInt(response.uid);
       
   511         var username = response.username;
       
   512         
       
   513         // Loop through the list of users and remove any existing ones with the same uid
       
   514         var div_users = document.getElementById('themeed_user_list');
       
   515         var children = div_users.getElementsByTagName('span');
       
   516         for ( var i = 0; i < children.length; i++ )
       
   517         {
       
   518           var child = children[i];
       
   519           if ( child.userid == uid )
       
   520           {
       
   521             // the sister is the br element next to the span with the checkbox/text
       
   522             var sister = child.nextSibling;
       
   523             div_users.removeChild(child);
       
   524             div_users.removeChild(sister);
       
   525             break;
       
   526           }
       
   527         }
       
   528         
       
   529         var useritem = document.createElement('span');
       
   530         useritem.appendChild(document.createTextNode(username + ' '));
       
   531         useritem.userid = parseInt(uid);
       
   532         var deleter = document.createElement('a');
       
   533         deleter.href = '#';
       
   534         deleter.onclick = function()
       
   535         {
       
   536           ajaxThemeManagerHandleUserRemoval(this);
       
   537           return false;
       
   538         }
       
   539         deleter.appendChild(document.createTextNode('[X]'));
       
   540         useritem.appendChild(deleter);
       
   541         div_users.appendChild(useritem);
       
   542         div_users.appendChild(document.createElement('br'));
       
   543       }
       
   544     });
       
   545 }
       
   546 
       
   547 function ajaxThemeManagerHandleUserRemoval(el)
       
   548 {
       
   549   var parent = el.parentNode;
       
   550   var uid = parent.userid;
       
   551   
       
   552   var grandparent = parent.parentNode;
       
   553   var sister = parent.nextSibling;
       
   554   grandparent.removeChild(parent);
       
   555   grandparent.removeChild(sister);
       
   556 }
       
   557 
       
   558 function ajaxThemeManagerHandleSaveRequest()
       
   559 {
       
   560   // Build a JSON condensed request
       
   561   var md = false;
       
   562   if ( document.getElementById('themeed_field_default') )
       
   563   {
       
   564     if ( document.getElementById('themeed_field_default').checked )
       
   565     {
       
   566       md = true;
       
   567     }
       
   568   }
       
   569   var policy = 'allow_all';
       
   570   if ( document.getElementById('themeed_field_policy_whitelist').checked )
       
   571     policy = 'whitelist';
       
   572   else if ( document.getElementById('themeed_field_policy_blacklist').checked )
       
   573     policy = 'blacklist';
       
   574   var json_packet = {
       
   575     theme_id: document.getElementById('themeed_theme_id').value,
       
   576     theme_name: document.getElementById('themeed_field_name').value,
       
   577     default_style: document.getElementById('themeed_field_style').value,
       
   578     make_default: md,
       
   579     group_policy: policy,
       
   580     enabled: ( document.getElementById('themeed_field_disable').checked ? false : true )
       
   581   };
       
   582   var acl_list = [];
       
   583   var checks = document.getElementById('themeed_group_list').getElementsByTagName('input');
       
   584   for ( var i = 0; i < checks.length; i++ )
       
   585   {
       
   586     if ( checks[i].checked )
       
   587       acl_list.push('g:' + checks[i].group_id);
       
   588   }
       
   589   var spans = document.getElementById('themeed_user_list').getElementsByTagName('span');
       
   590   for ( var i = 0; i < spans.length; i++ )
       
   591   {
       
   592     if ( spans[i].userid )
       
   593       acl_list.push('u:' + spans[i].userid);
       
   594   }
       
   595   json_packet.group_list = acl_list;
       
   596   
       
   597   var json_send = {
       
   598     mode: 'save_theme',
       
   599     theme_data: json_packet
       
   600   };
       
   601   
       
   602   json_send = ajaxEscape(toJSONString(json_send));
       
   603   
       
   604   // Request the save
       
   605   var parent = document.getElementById('ajaxPageContainer');
       
   606   ajaxPost(makeUrlNS('Admin', 'ThemeManager/action.json'), 'r=' + json_send, function()
       
   607     {
       
   608       if ( ajax.readyState == 4 && ajax.status == 200 )
       
   609       {
       
   610         // process response
       
   611         var response = String(ajax.responseText + '');
       
   612         if ( response.substr(0, 1) != '{' )
       
   613         {
       
   614           // For this we actually *expect* an HTML response.
       
   615           parent.innerHTML = response;
       
   616           return false;
       
   617         }
       
   618         response = parseJSON(response);
       
   619         if ( response.mode == 'error' )
       
   620         {
       
   621           alert(response.error);
       
   622           return false;
       
   623         }
       
   624       }
       
   625     });
       
   626 }
       
   627 
       
   628 function ajaxThemeManagerHandleUninstallClick()
       
   629 {
       
   630   var theme_id = document.getElementById('themeed_theme_id').value;
       
   631   var json_send = {
       
   632     mode: 'uninstall',
       
   633     theme_id: theme_id
       
   634   };
       
   635   
       
   636   json_send = ajaxEscape(toJSONString(json_send));
       
   637   
       
   638   // Request the action
       
   639   var parent = document.getElementById('ajaxPageContainer');
       
   640   ajaxPost(makeUrlNS('Admin', 'ThemeManager/action.json'), 'r=' + json_send, function()
       
   641     {
       
   642       if ( ajax.readyState == 4 && ajax.status == 200 )
       
   643       {
       
   644         // process response
       
   645         var response = String(ajax.responseText + '');
       
   646         if ( response.substr(0, 1) != '{' )
       
   647         {
       
   648           // For this we actually *expect* an HTML response.
       
   649           parent.innerHTML = response;
       
   650           return false;
       
   651         }
       
   652         response = parseJSON(response);
       
   653         if ( response.mode == 'error' )
       
   654         {
       
   655           alert(response.error);
       
   656           return false;
       
   657         }
       
   658       }
       
   659     });
       
   660 }