Changeset 25817


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

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

Location:
extensions/AdminTools
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • extensions/AdminTools/include/MultiView.class.php

    r25791 r25817  
    212212    }
    213213  }
     214 
     215  /**
     216   * Register custom API methods
     217   */
     218  public static function register_ws($arr)
     219  {
     220    $service = &$arr[0];
     221   
     222    $service->addMethod(
     223      'multiView.getData',
     224      array('MultiView', 'ws_get_data'),
     225      array(),
     226      'AdminTools private method.',
     227      null,
     228      array('admin_only' => true, 'hidden' => true)
     229      );
     230  }
     231 
     232  /**
     233   * API method
     234   * Return full list of users, themes and languages
     235   */
     236  public static function ws_get_data($params)
     237  {
     238    global $conf;
     239   
     240    // get users
     241    $query = '
     242SELECT
     243  '.$conf['user_fields']['id'].' AS id,
     244  '.$conf['user_fields']['username'].' AS username
     245FROM '.USERS_TABLE.'
     246  ORDER BY CONVERT('.$conf['user_fields']['username'].', CHAR)
     247;';
     248    $out['users'] = array_from_query($query);
     249
     250    // get themes
     251    include_once(PHPWG_ROOT_PATH.'admin/include/themes.class.php');
     252    $themes = new themes();
     253    foreach (array_keys($themes->db_themes_by_id) as $theme)
     254    {
     255      if (!empty($theme))
     256      {
     257        $out['themes'][] = $theme;
     258      }
     259    }
     260
     261    // get languages
     262    foreach (get_languages() as $code => $name)
     263    {
     264      $out['languages'][] = array(
     265        'id' => $code,
     266        'name' => $name,
     267        );
     268    }
     269   
     270    return $out;
     271  }
    214272}
  • extensions/AdminTools/include/events.inc.php

    r25791 r25817  
    8181      );
    8282
    83     // gets tags
     83    // gets tags (full available list is loaded in ajax)
    8484    $query = '
    8585SELECT id, name
     
    8989;';
    9090    $tag_selection = get_taglist($query);
    91 
    92     $query = '
    93 SELECT id, name
    94   FROM '.TAGS_TABLE.'
    95 ;';
    96     $tags = get_taglist($query, false);
    9791
    9892    $tpl_vars['QUICK_EDIT'] = array(
     
    10599      'date_creation_time' => substr($picture['current']['date_creation'], 11, 5),
    106100      'tag_selection' =>      $tag_selection,
    107       'tags' =>               $tags,
    108101      );
    109102  }
     
    146139      $tpl_vars['QUICK_EDIT']['img'] = DerivativeImage::get_one(IMG_SQUARE, $image_infos)->get_url();
    147140    }
    148   }
    149 
    150 
    151   // get users
    152   $query = '
    153 SELECT
    154   '.$conf['user_fields']['id'].' AS id,
    155   '.$conf['user_fields']['username'].' AS username
    156 FROM '.USERS_TABLE.'
    157   ORDER BY CONVERT('.$conf['user_fields']['username'].', CHAR)
    158 ;';
    159   $tpl_vars['USERS'] = simple_hash_from_query($query, 'id', 'username');
    160 
    161   // get themes
    162   include_once(PHPWG_ROOT_PATH.'admin/include/themes.class.php');
    163   $themes = new themes();
    164   foreach (array_keys($themes->db_themes_by_id) as $theme)
    165   {
    166     if (!empty($theme))
    167     {
    168       $tpl_vars['THEMES'][$theme] = $theme;
    169     }
    170   }
    171 
    172   // get languages
    173   foreach (get_languages() as $code => $name)
    174   {
    175     $tpl_vars['LANGS'][$code] = $name;
    176141  }
    177142
  • extensions/AdminTools/main.inc.php

    r25791 r25817  
    3535add_event_handler('init', array(&$MultiView, 'init'));
    3636
     37add_event_handler('ws_add_methods', array('MultiView', 'register_ws'));
     38
    3739
    3840// +-----------------------------------------------------------------------+
  • 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.