Ignore:
Timestamp:
Dec 7, 2013, 6:43:09 PM (10 years ago)
Author:
mistic100
Message:

load tags,themes,users,languages list in AJAX + move javascript code to external file

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/AdminTools/template/public_controller.tpl

    r25791 r25817  
    99  {combine_css id='colorbox' path='themes/default/js/plugins/colorbox/style2/colorbox.css'}
    1010
    11   {*<!-- tokeninput -->*}
    12   {combine_script id='jquery.tokeninput' load='footer' require='jquery' path='themes/default/js/plugins/jquery.tokeninput.js'}
    13   {combine_css path='themes/default/js/plugins/jquery.tokeninput.css'}
     11  {if isset($ato.IS_PICTURE)}
     12    {*<!-- tokeninput -->*}
     13    {combine_script id='jquery.tokeninput' load='footer' require='jquery' path='themes/default/js/plugins/jquery.tokeninput.js'}
     14    {combine_css path='themes/default/js/plugins/jquery.tokeninput.css'}
    1415
    15   {*<!-- datepicker -->*}
    16   {combine_script id='jquery.ui.datepicker' load='footer' path='themes/default/js/ui/jquery.ui.datepicker.js'}
     16    {*<!-- datepicker -->*}
     17    {combine_script id='jquery.ui.datepicker' load='footer' path='themes/default/js/ui/jquery.ui.datepicker.js'}
    1718
    18   {assign var=datepicker_language value='themes/default/js/ui/i18n/jquery.ui.datepicker-'|cat:$lang_info.code|cat:'.js'}
    19   {if 'PHPWG_ROOT_PATH'|constant|cat:$datepicker_language|file_exists}
    20   {combine_script id='jquery.ui.datepicker-'|cat:$lang_info.code load='footer' path=$datepicker_language}
     19    {assign var=datepicker_language value='themes/default/js/ui/i18n/jquery.ui.datepicker-'|cat:$lang_info.code|cat:'.js'}
     20    {if 'PHPWG_ROOT_PATH'|constant|cat:$datepicker_language|file_exists}
     21    {combine_script id='jquery.ui.datepicker-'|cat:$lang_info.code load='footer' path=$datepicker_language}
     22    {/if}
     23
     24    {combine_css path='themes/default/js/ui/theme/jquery.ui.core.css'}
     25    {combine_css path='themes/default/js/ui/theme/jquery.ui.theme.css'}
     26    {combine_css path='themes/default/js/ui/theme/jquery.ui.datepicker.css'}
    2127  {/if}
     28{/if}
    2229
    23   {combine_css path='themes/default/js/ui/theme/jquery.ui.core.css'}
    24   {combine_css path='themes/default/js/ui/theme/jquery.ui.theme.css'}
    25   {combine_css path='themes/default/js/ui/theme/jquery.ui.datepicker.css'}
     30{combine_script id='admintools.controller' load='footer' require='jquery' path=$ADMINTOOLS_PATH|cat:'template/public_controller.js'}
     31{/strip}
     32
     33{footer_script require='admintools.controller'}
     34AdminTools.urlWS = '{$ROOT_URL}ws.php?format=json&method=';
     35AdminTools.multiView = {
     36  'view_as': "{$ato.MULTIVIEW.view_as}",
     37  'theme': "{$ato.MULTIVIEW.theme}",
     38  'lang': "{$ato.MULTIVIEW.lang}"
     39};
     40
     41AdminTools.init();
     42{if $themeconf.mobile}
     43  AdminTools.initMobile();
    2644{/if}
    27 {/strip}
     45{if isset($ato.U_SET_REPRESENTATIVE)}
     46  AdminTools.initRepresentative({$current.id}, {$ato.CATEGORY_ID});
     47{/if}
     48{if isset($ato.U_CADDIE) and isset($ato.IS_PICTURE)}
     49  AdminTools.initCaddie({$current.id});
     50{/if}
     51{if isset($ato.QUICK_EDIT)}
     52  AdminTools.initQuickEdit({intval(isset($ato.IS_PICTURE))}, {
     53    hintText: '{'Type in a search term'|@translate}',
     54    noResultsText: '{'No results'|@translate}',
     55    searchingText: '{'Searching...'|@translate}',
     56    newText: ' ({'new'|@translate})'
     57  });
     58{/if}
     59{/footer_script}
    2860
    2961<div id="ato_header_closed"><a href="#" class="icon-tools"></a></div>
     
    6395  {/if}
    6496
    65     <li class="parent right"><a class="icon-cog-alt" href="#">{'Tools'|translate}</a>
     97    <li class="parent right multiview"><a class="icon-cog-alt" href="#">{'Tools'|translate}</a>
    6698      <ul>
    6799        <li><label>{'View as'|translate}</label>
    68           <select class="switcher" data-type="view_as">
    69             {html_options options=$ato.USERS selected=$ato.MULTIVIEW.view_as}
    70           </select>
     100          <select class="switcher" data-type="view_as"></select>
    71101        </li>
    72102        <li><label>{'Theme'|translate}</label>
    73           <select class="switcher" data-type="theme">
    74             {html_options options=$ato.THEMES selected=$ato.MULTIVIEW.theme}
    75           </select>
     103          <select class="switcher" data-type="theme"></select>
    76104        </li>
    77105        <li><label>{'Language'|translate}</label>
    78           <select class="switcher" data-type="lang">
    79             {html_options options=$ato.LANGS selected=$ato.MULTIVIEW.lang}
    80           </select>
     106          <select class="switcher" data-type="lang"></select>
    81107        </li>
    82108        <li><a class="icon-ato-check{if !$ato.MULTIVIEW.show_queries}-empty{/if}" href="{$ato.U_SELF}ato_show_queries={(int)!$ato.MULTIVIEW.show_queries}">{'Show SQL queries'|translate}</a></li>
     
    99125{if isset($ato.QUICK_EDIT)}
    100126<div style="display:none;">
    101   <div id="ato_quick_edit">
     127  <div id="ato_quick_edit" title="{'Quick edit'|translate}">
    102128    <form method="post" action="{$ato.U_SELF}">
    103129      <fieldset class="left">
     
    141167</div>
    142168{/if}
    143 
    144 {footer_script require='jquery'}
    145 (function($){
    146   function moveBody(dir, anim) {
    147     var operator = dir=='show' ? '+=' : '-=';
    148    
    149     if (anim) {
    150       $('body').animate({ldelim}'margin-top': operator+ato_height});
    151      
    152       if ($('#the_page, [data-role="page"]').css('position')=='absolute') {
    153         $('#the_page, [data-role="page"]').animate({ldelim}'top': operator+ato_height});
    154       }
    155     }
    156     else {
    157       $('body').css({ldelim}'margin-top': operator+ato_height});
    158      
    159       if ($('#the_page, [data-role="page"]').css('position')=='absolute') {
    160         $('#the_page, [data-role="page"]').css({ldelim}'top': operator+ato_height});
    161       }
    162     }
    163   }
    164  
    165   var $ato = $('#ato_header'),
    166       $ato_closed = $('#ato_header_closed'),
    167       ato_height = 28,
    168       urlWS = '{$ROOT_URL}ws.php?format=json&method=';
    169 
    170   $('body').prepend($ato); // ensure the bar is at the begining
    171  
    172   {if $themeconf.mobile}
    173     var $headerbar = $('div[data-role="header"] .title');
    174     if ($headerbar.length == 1) {
    175       $ato_closed.addClass('smartpocket');
    176       $ato_closed.find('a').attr({
    177         'data-iconpos':'notext',
    178         'data-role':'button'
    179       });
    180       $headerbar.prepend($ato_closed);   
    181     }
    182   {/if}
    183 
    184   if (window.localStorage.ato_panel_open == null) {
    185     window.localStorage.ato_panel_open = "true";
    186   }
    187 
    188   if (window.localStorage.ato_panel_open == "true") {
    189     $ato.show();
    190     moveBody('show', false);
    191   }
    192   else {
    193     $ato_closed.show();
    194   }
    195 
    196 {*<!-- sub menus -->*}
    197   $ato.find('.parent').on({
    198     'click': function(){
    199       $(this).find('ul').toggle();
    200     },
    201     'mouseleave': function(e) {
    202       if (e.target.tagName.toLowerCase() != "select") {
    203         $(this).find('ul').hide();
    204       }
    205     }
    206   });
    207   $ato.find('.parent>a').on('click', function(e) {
    208     e.preventDefault();
    209   });
    210   $ato.find('.parent ul').on('mouseleave', function(e) {
    211     if (e.target.tagName.toLowerCase() != "select") {
    212       $(this).hide();
    213     }
    214   });
    215 
    216 {*<!-- select boxes -->*}
    217   $ato.find('.switcher').on({
    218     'change': function() {
    219       window.location.href = '{$ato.U_SELF}ato_'+ $(this).data('type') +'='+ $(this).val();
    220     },
    221     'click': function(e) {
    222       e.stopPropagation();
    223     }
    224   });
    225 
    226 {*<!-- toggle toolbar -->*}
    227   $ato.find('.close-panel').on('click', function(e) {
    228     $ato.slideUp();
    229     $ato_closed.slideDown();
    230     moveBody('hide', true);
    231 
    232     window.localStorage.ato_panel_open = "false";
    233     e.preventDefault();
    234   });
    235 
    236   $ato_closed.on('click', function(e) {
    237     $ato.slideDown();
    238     $ato_closed.slideUp();
    239     moveBody('show', true);
    240 
    241     window.localStorage.ato_panel_open = "true";
    242     e.preventDefault();
    243   });
    244 
    245 {*<!-- set representative -->*}
    246 {if isset($ato.U_SET_REPRESENTATIVE)}
    247   $ato.find('.set-representative').on('click', function(e) {
    248 
    249     if (!$(this).parent().hasClass('disabled')) {
    250       $(this).parent().addClass('disabled')
    251 
    252       $.ajax({
    253         method: 'POST',
    254         url: urlWS + 'pwg.categories.setRepresentative',
    255         dataType: 'json',
    256         data: {
    257           image_id: {$current.id},
    258           category_id: {$ato.CATEGORY_ID}
    259         },
    260         success: function() {
    261           alert('ok');
    262         },
    263         fail: function(num, text) {
    264           alert(num + ' ' + text);
    265         }
    266       });
    267     }
    268 
    269     e.preventDefault();
    270   });
    271 {/if}
    272 
    273 {*<!-- add to caddie -->*}
    274 {if isset($ato.U_CADDIE) and isset($ato.IS_PICTURE)}
    275   $ato.find('.add-caddie').on('click', function(e) {
    276 
    277     if (!$(this).parent().hasClass('disabled')) {
    278       $(this).parent().addClass('disabled')
    279 
    280       $.ajax({
    281         method: 'POST',
    282         url: urlWS + 'pwg.caddie.add',
    283         dataType: 'json',
    284         data: {
    285           image_id: {$current.id}
    286         },
    287         success: function() {
    288           alert('ok');
    289         },
    290         fail: function(num, text) {
    291           alert(num + ' ' + text);
    292         }
    293       });
    294     }
    295 
    296     e.preventDefault();
    297   });
    298 {/if}
    299 
    300 {* <!-- quick edit -->*}
    301 {if isset($ato.QUICK_EDIT)}
    302   var $ato_edit = $('#ato_quick_edit');
    303  
    304  
    305   setTimeout(function() {
    306     var bg_color = 'white';
    307     var selectors = ['#the_page #content', '[data-role="page"]', 'body'];
    308    
    309     for (var i=0; i<selectors.length; i++) {
    310       var color = $(selectors[i]).css('background-color');
    311       console.log(selectors[i], color);
    312       if (color && color!='transparent') {
    313         bg_color = color;
    314         break;
    315       }
    316     }
    317 
    318     $ato_edit.css('background-color', bg_color);
    319   }, 1000);
    320 
    321   $ato_edit.find('.close-edit').on('click', function(e) {
    322     $.colorbox.close()
    323     e.preventDefault();
    324   });
    325 
    326 {if isset($ato.IS_PICTURE)}
    327   $ato_edit.find('.datepicker').datepicker({
    328     dateFormat: 'yy-mm-dd'
    329   });
    330 
    331   $ato_edit.find('.tags').tokenInput(
    332     [{foreach from=$ato.QUICK_EDIT.tags item=tag name=tags}{ldelim}"name":"{$tag.name|escape:javascript}","id":"{$tag.id}"{rdelim}{if !$smarty.foreach.tags.last},{/if}{/foreach}],
    333     {
    334       hintText: '{'Type in a search term'|@translate}',
    335       noResultsText: '{'No results'|@translate}',
    336       searchingText: '{'Searching...'|@translate}',
    337       newText: ' ({'new'|@translate})',
    338       animateDropdown: false,
    339       preventDuplicates: true,
    340       allowFreeTagging: true
    341     }
    342   );
    343 {/if}
    344 
    345   $(".edit-quick").colorbox({
    346     inline: true,
    347     transition: 'none',
    348     title: '{'Quick edit'|translate|escape:javascript}',
    349     width: 500,
    350     top: 50
    351   });
    352 {/if}
    353 
    354 }(jQuery));
    355 {/footer_script}
Note: See TracChangeset for help on using the changeset viewer.