includes/clientside/static/ajax.js
changeset 870 82bbfe3dc8a0
parent 869 58bc29c14a4d
child 881 01810d32a0d6
equal deleted inserted replaced
869:58bc29c14a4d 870:82bbfe3dc8a0
   153   var box = miniPromptGetParent(obj);
   153   var box = miniPromptGetParent(obj);
   154   if ( !box )
   154   if ( !box )
   155     return false;
   155     return false;
   156   
   156   
   157   var input = obj.getElementsByTagName('input')[0];
   157   var input = obj.getElementsByTagName('input')[0];
   158   console.debug(obj, input);
       
   159   if ( !input )
   158   if ( !input )
   160     return false;
   159     return false;
   161   var newname = input.value;
   160   var newname = input.value;
   162   newname = trim(newname);
   161   newname = trim(newname);
   163   
   162   
   736 window.ajaxChangeStyle = function()
   735 window.ajaxChangeStyle = function()
   737 {
   736 {
   738   // IE <6 pseudo-compatibility
   737   // IE <6 pseudo-compatibility
   739   if ( KILL_SWITCH )
   738   if ( KILL_SWITCH )
   740     return true;
   739     return true;
   741   load_component(['l10n', 'messagebox', 'flyin', 'fadefilter']);
   740   load_component(['l10n', 'fadefilter', 'jquery', 'jquery-ui']);
   742   
   741   
   743   var inner_html = '';
   742   // force string fetch
   744   inner_html += '<p><label>' + $lang.get('ajax_changestyle_lbl_theme') + ' ';
   743   $lang.get('etc_cancel');
   745   inner_html += '  <select id="chtheme_sel_theme" onchange="ajaxGetStyles(this.value);">';
   744   
   746   inner_html += '    <option value="_blank" selected="selected">' + $lang.get('ajax_changestyle_select') + '</option>';
   745   // preload some images
   747   inner_html +=      ENANO_THEME_LIST;
   746   var i1 = new Image();
   748   inner_html += '  </select>';
   747   i1.src = cdnPath + '/images/loading-big.gif';
   749   inner_html += '</label></p>';
   748   var i2 = new Image();
   750   var chtheme_mb = new MessageBox(MB_OKCANCEL|MB_ICONQUESTION, $lang.get('ajax_changestyle_title'), inner_html);
   749   i2.src = cdnPath + '/images/check-large.png';
   751   chtheme_mb.onbeforeclick['OK'] = ajaxChangeStyleComplete;
   750   
   752 }
   751   darken(true, 70, 'theme-selector-shade');
   753 
   752   
   754 window.ajaxGetStyles = function(id)
   753   $('body').append('<div id="theme-selector-wrapper"><div id="theme-selector-body"><div id="theme-selector-inner"><div class="theme-selector-spinner"></div></div></div></div>');
   755 {
   754   $('#theme-selector-wrapper')
   756   // IE <6 pseudo-compatibility
   755     .css('top', String(getScrollOffset()) + 'px')
   757   if ( KILL_SWITCH )
   756     .css('z-index', String( getHighestZ() + 20 ));
   758     return true;
   757   
   759   var thediv = document.getElementById('chtheme_sel_style_parent');
   758   $.get(stdAjaxPrefix + '&_mode=theme_list', {}, function(data, status)
   760   if ( thediv )
   759     {
   761   {
   760       $('#theme-selector-inner .theme-selector-spinner').fadeOut(650);
   762     thediv.parentNode.removeChild(thediv);
   761       $('#theme-selector-body').animate({ width: 708 }, 600, function()
   763   }
   762         {
   764   if ( id == '_blank' )
   763           // avoiding jQuery's fade functions because they insist on toggling display as well
   765   {
   764           changeOpac(0, 'theme-selector-inner');
   766     return null;
   765           $('#theme-selector-inner').html('<h3></h3>');
   767   }
   766           $('#theme-selector-inner > h3').text($lang.get('ajax_thmsel_lbl_choosetheme'));
   768   ajaxGet(stdAjaxPrefix + '&_mode=getstyles&id=' + id, function(ajax) {
   767           $('#theme-selector-inner').append('<ul></ul>');
   769       if ( ajax.readyState == 4 && ajax.status == 200 )
   768           for ( var i = 0; i < data.length; i++ )
   770       {
   769           {
   771         // IE doesn't like substr() on ajax.responseText
   770             var bgi = data[i].have_thumb ? cdnPath + '/themes/' + data[i].theme_id + '/preview.png' : cdnPath + '/images/themepreview.png';
   772         var response = String(ajax.responseText + '');
   771             $('#theme-selector-inner > ul').append('<li id="theme_' + i + '"><a href="#"><span></span></a></li>');
   773         if ( response.substr(0,1) != '[' )
   772             $('#theme-selector-inner li#theme_' + i + ' > a')
   774         {
   773               .css('background-image', 'url(' + bgi + ')')
   775           alert('Invalid or unexpected JSON response from server:\n' + response);
   774               .attr('enano:theme_id', data[i].theme_id);
   776           return null;
   775             $('#theme-selector-inner li#theme_' + i + ' > a > span')
   777         }
   776               .text(data[i].theme_name);
   778         
   777           }
   779         // Build a selector and matching label
   778           $('#theme-selector-inner').append('<span class="menuclear"></span>');
   780         var data = parseJSON(response);
   779           $('#theme-selector-inner').append('<div style="padding-top: 40px;"><a class="abutton abutton_green" style="font-size: larger;" href="#" onclick="ajaxChangeStyleClose(); return false;">' + $lang.get('etc_cancel') + '</a></div>');
   781         var options = new Array();
   780           
   782         for( var i in data )
   781           $('#theme-selector-body').animate({ height: $('#theme-selector-inner').height() + 30 }, 600, function()
   783         {
   782             {
   784           var item = data[i];
   783               opacity('theme-selector-inner', 0, 100, 750);
   785           var title = themeid_to_title(item);
   784             });
   786           var option = document.createElement('option');
   785           
   787           option.value = item;
   786           $('#theme-selector-inner li a').click(function()
   788           option.appendChild(document.createTextNode(title));
   787             {
   789           options.push(option);
   788               var theme_id = $(this).attr('enano:theme_id');
   790         }
   789               $('span', this).html('&nbsp;').addClass('loading').fadeTo('fast', 0.6)
   791         var p_parent = document.createElement('p');
   790               $.get(stdAjaxPrefix + '&_mode=get_styles', { theme_id: theme_id }, function(data, status)
   792         var label  = document.createElement('label');
   791                 {
   793         p_parent.id = 'chtheme_sel_style_parent';
   792                   if ( data.length > 1 )
   794         label.appendChild(document.createTextNode($lang.get('ajax_changestyle_lbl_style') + ' '));
   793                   {
   795         var select = document.createElement('select');
   794                     $('#theme-selector-inner').css('height', $('#theme-selector-inner').height()).fadeOut(600, function()
   796         select.id = 'chtheme_sel_style';
   795                     {
   797         for ( var i in options )
   796                       var div = document.createElement('div');
   798         {
   797                       domObjChangeOpac(0, div);
   799           select.appendChild(options[i]);
   798                       
   800         }
   799                       $(div).attr('id', 'theme-selector-style-list').append('<h3></h3>');
   801         label.appendChild(select);
   800                       $('h3', div).text($lang.get('ajax_thmsel_lbl_choosestyle'));
   802         p_parent.appendChild(label);
   801                       
   803         
   802                       for ( var i = 0; i < data.length; i++ )
   804         // Stick it onto the messagebox
   803                       {
   805         var div = document.getElementById('messageBox');
   804                         $(div).append('<a class="abutton block stylebtn" id="stylebtn_' + i + '" enano:style_id="' + data[i] + '">' + themeid_to_title(data[i]) + '</a>');
   806         var kid = div.firstChild.nextSibling;
   805                       }
   807         
   806                       
   808         kid.appendChild(p_parent);
   807                       $(div).append('<div style="padding-top: 40px;"><a class="abutton abutton_green" style="font-size: larger;" href="#" onclick="ajaxChangeStyleClose(); return false;">' + $lang.get('etc_cancel') + '</a></div>');
   809         
   808                       
   810       }
   809                       changeOpac(0, 'theme-selector-style-list');
   811     }, true);
   810                       $(this).html(div).show();
   812 }
   811                       
   813 
   812                       $('#theme-selector-body').animate({width: 300, height: $('#theme-selector-style-list').height() + 30}, 300, function()
   814 window.ajaxChangeStyleComplete = function()
   813                         {
   815 {
   814                           opacity('theme-selector-style-list', 0, 100, 500);
   816   // IE <6 pseudo-compatibility
   815                         });
   817   if ( KILL_SWITCH )
   816                       
   818     return true;
   817                       $('.stylebtn').click(function()
   819   var theme = $dynano('chtheme_sel_theme');
   818                         {
   820   var style = $dynano('chtheme_sel_style');
   819                           ajaxChangeThemeSetLoading();
   821   if ( !theme.object || !style.object )
   820                           $.post(stdAjaxPrefix + '&_mode=change_theme', { theme_id: theme_id, style_id: $(this).attr('enano:style_id') }, function(data, status)
   822   {
   821                             {
   823     alert($lang.get('ajax_changestyle_pleaseselect_theme'));
   822                               if ( data.error )
   824     return true;
   823                               {
   825   }
   824                                 alert(data.error);
   826   var theme_id = theme.object.value;
   825                                 ajaxChangeStyleClose();
   827   var style_id = style.object.value;
   826                                 return false;
   828   
   827                               }
   829   if ( typeof(theme_id) != 'string' || typeof(style_id) != 'string' )
   828                               ajaxChangeThemeShowSuccess();
   830   {
   829                             }, 2000);
   831     alert('Couldn\'t get theme or style ID');
   830                           
   832     return true;
   831                           return false;
   833   }
   832                         });
   834   
   833                     });
   835   if ( theme_id.length < 1 || style_id.length < 1 )
   834                   }
   836   {
   835                   else
   837     alert('Theme or style ID is zero length');
   836                   {
   838     return true;
   837                     if ( !data[0] )
   839   }
   838                     {
   840   
   839                       alert('Didn\'t find any CSS files. :-/');
   841   ajaxPost(stdAjaxPrefix + '&_mode=change_theme', 'theme_id=' + ajaxEscape(theme_id) + '&style_id=' + ajaxEscape(style_id), function(ajax)
   840                       ajaxChangeStyleClose();
   842     {
   841                     }
   843       if ( ajax.readyState == 4 && ajax.status == 200 )
   842                     
   844       {
   843                     $.post(stdAjaxPrefix + '&_mode=change_theme', { theme_id: theme_id, style_id: data[0] }, function(data, status)
   845         if ( ajax.responseText == 'GOOD' )
   844                       {
   846         {
   845                         if ( data.error )
   847           var c = confirm($lang.get('ajax_changestyle_success'));
   846                         {
   848           if ( c )
   847                           alert(data.error);
   849             window.location.reload();
   848                           ajaxChangeStyleClose();
   850         }
   849                           return false;
   851         else
   850                         }
   852         {
   851                         ajaxChangeThemeShowSuccess();
   853           alert('Error occurred during attempt to change theme:\n' + ajax.responseText);
   852                       }, 'json');
   854         }
   853                   }
   855       }
   854                 }, 'json');
   856     }, true);
   855               return false;
   857   
   856             }); // click function
   858   return false;
   857         }); // animate
   859   
   858     }, 'json'); // get
   860 }
   859 }
   861 
   860 
   862 window.ajaxSwapCSS = function()
   861 window.ajaxChangeThemeSetLoading = function()
   863 {
   862 {
   864   // IE <6 pseudo-compatibility
   863   $('#theme-selector-body').animate({width: 130, height: 130});
   865   if ( KILL_SWITCH )
   864   $('#theme-selector-inner').empty().html('<div class="theme-selector-spinner"></div>');
   866     return true;
   865 }
   867   setAjaxLoading();
   866 
   868   if(_css) {
   867 window.ajaxChangeThemeShowSuccess = function()
   869     document.getElementById('mdgCss').href = main_css;
   868 {
   870     _css = false;
   869   $('#theme-selector-body').animate({width: 400, height: 300 }, 600, function()
   871   } else {
   870       {
   872     document.getElementById('mdgCss').href = print_css;
   871         $('#theme-selector-inner').append('<img src="' + cdnPath + '/images/check-large.png" alt=" " style="display: block; margin: 15px auto;" />');
   873     _css = true;
   872         $('#theme-selector-inner').append('<h3>' + $lang.get('ajax_thmsel_msg_success') + '</h3>');
   874   }
   873         $('#theme-selector-inner').append('<div style="padding-top: 20px;"><a class="abutton abutton_green" style="font-size: larger;" href="#" onclick="window.location.reload(); return false;">' + $lang.get('ajax_thmsel_btn_reload') + '</a></div>');
   875   unsetAjaxLoading();
   874         $('#theme-selector-inner').append('<div style="padding-top: 25px;"><a href="#" style="font-size: smaller;" onclick="ajaxChangeStyleClose(); return false;">' + $lang.get('ajax_thmsel_btn_close') + '</a><br /><small>' + $lang.get('ajax_thmsel_btn_close_hint') + '</small></div>');
   876   menuOff();
   875         $('#theme-selector-inner').fadeIn();
       
   876       });
       
   877   setTimeout(function()
       
   878     {
       
   879       $('#theme-selector-inner').empty();
       
   880     }, 10);
       
   881 }
       
   882 
       
   883 window.ajaxChangeStyleClose = function()
       
   884 {
       
   885   setTimeout(function()
       
   886     {
       
   887       enlighten(false, 'theme-selector-shade');
       
   888       $('#theme-selector-wrapper').fadeOut(500, function()
       
   889         {
       
   890           $(this).remove();
       
   891         });
       
   892     }, 300);
       
   893   opacity('theme-selector-inner', 100, 0, 250);
       
   894 }
       
   895 
       
   896 function themeid_to_title(id)
       
   897 {
       
   898   if ( typeof(id) != 'string' )
       
   899     return false;
       
   900   id = id.substr(0, 1).toUpperCase() + id.substr(1);
       
   901   id = id.replace(/_/g, ' ');
       
   902   id = id.replace(/-/g, ' ');
       
   903   return id;
   877 }
   904 }
   878 
   905 
   879 window.ajaxSetPassword = function()
   906 window.ajaxSetPassword = function()
   880 {
   907 {
   881   // IE <6 pseudo-compatibility
   908   // IE <6 pseudo-compatibility
  1563         fadeInfoBoxes();
  1590         fadeInfoBoxes();
  1564       }
  1591       }
  1565     });
  1592     });
  1566 }
  1593 }
  1567 
  1594 
  1568 function themeid_to_title(id)
       
  1569 {
       
  1570   if ( typeof(id) != 'string' )
       
  1571     return false;
       
  1572   id = id.substr(0, 1).toUpperCase() + id.substr(1);
       
  1573   id = id.replace(/_/g, ' ');
       
  1574   id = id.replace(/-/g, ' ');
       
  1575   return id;
       
  1576 }