source: extensions/SmartAlbums/template/cat_modify.tpl @ 11333

Last change on this file since 11333 was 11333, checked in by mistic100, 13 years ago

clean code, use TokenInput

File size: 5.5 KB
Line 
1{combine_css path=$SMART_PATH|@cat:"template/style.css"}
2{include file='include/datepicker.inc.tpl'}
3{combine_script id='jquery.tokeninput' load='async' require='jquery' path='themes/default/js/plugins/jquery.tokeninput.js'}
4
5{footer_script require='jquery.tokeninput'}
6var lang = new Array();
7lang['tags filter'] = "{'tags filter'|@translate}";
8lang['date filter'] = "{'date filter'|@translate}";
9lang['limit filter'] = "{'limit filter'|@translate}";
10lang['remove this filter'] = "{'remove this filter'|@translate}";
11
12var options = new Array();
13{capture assign="options_tags"}{html_options options=$options.tags}{/capture}
14{capture assign="options_date"}{html_options options=$options.date}{/capture}
15{capture assign="options_limit"}{html_options options=$options.limit}{/capture}
16options['tags'] = "{$options_tags|escape:javascript}";
17options['date'] = "{$options_date|escape:javascript}";
18options['limit'] = "{$options_limit|escape:javascript}";
19
20{literal}
21jQuery(document).ready(function() {
22  $('#addFilter').change(function() {
23    add_filter($(this).attr('value'));
24    $(this).attr('value', '-1');
25  });
26   
27  $('#removeFilters').click(function() {
28    $('#filterList li').each(function() {
29      $(this).remove();
30    });
31    return false;
32  });
33 
34  $('input[name="is_smart"]').change(function() {
35    $('#SmartAlbum_options').toggle();
36    $('input[name="countImages"]').toggle();
37  });
38 
39  $('input[name="countImages"]').click(function() {
40    countImages($(this).closest('form'));
41    return false;
42  });
43 
44  function add_filter(type) {
45    // add line
46    $('<li class="filter_'+ type +'" id="filter_'+ i +'"></li>').appendTo('#filterList');
47   
48    //set content
49    content = '<a href="#" class="removeFilter" title="'+ lang['remove this filter'] +'"><span>[x]</span></a>'+
50    '<input type="hidden" name="filters['+ i +'][type]" value="'+ type +'"/>&nbsp;'+ lang[type +' filter'] +
51    '&nbsp;<select name="filters['+ i +'][cond]">'+ options[type] +'</select>';
52   
53    if (type == 'tags') {
54      content += '&nbsp;<select name="filters['+ i +'][value]" class="tagSelect"></select>';
55    } else {
56      content += '&nbsp;<input type="text" name="filters['+ i +'][value]"/>';
57    }
58   
59    $('#filter_'+ i).html(content);
60   
61    // reinit handlers
62    init_jquery_handlers();
63    i++;
64  }
65 
66  function init_jquery_handlers() { 
67    $('.removeFilter').click(function() {
68      $(this).parent('li').remove();
69      return false;
70    });
71 
72    $('.filter_date input[type="text"]').each(function() {
73      $(this).datepicker({dateFormat:'yy-mm-dd', firstDay:1});
74    });
75   
76    jQuery(".tagSelect").tokenInput(
77    {/literal}
78      [{foreach from=$tags item=tag name=tags}{ldelim}"name":"{$tag.name|@escape:'javascript'}","id":"{$tag.id}"{rdelim}{if !$smarty.foreach.tags.last},{/if}{/foreach}],
79      {ldelim}
80        hintText: '{'Type in a search term'|@translate}',
81        noResultsText: '{'No results'|@translate}',
82        searchingText: '{'Searching...'|@translate}',
83        animateDropdown: false,
84        preventDuplicates: true,
85        allowCreation: false
86    {literal}
87      }
88    );
89  }
90 
91  function countImages(form) {
92{/literal}
93                jQuery.post("{$COUNT_SCRIPT_URL}", 'cat_id={$CAT_ID}&'+form.serialize(),
94{literal}
95                        function success(data) {
96                                jQuery('.count_images_display').html(data);
97                        }
98                );
99        }
100 
101  init_jquery_handlers();
102});
103{/literal}
104{/footer_script}
105
106<div id="batchManagerGlobal">
107<form action="{$F_ACTION}" method="POST" id="smart">
108<fieldset>
109
110  <legend>{'SmartAlbums'|@translate}</legend>
111 
112  <label><input type="checkbox" name="is_smart" {if isset($filters)}checked="checked"{/if}/> {'This album is a SmartAlbum'|@translate}</label>
113 
114<div id="SmartAlbum_options" style="margin-top:1em;{if !isset($filters)}display:none;{/if}">
115  <ul id="filterList">
116    {counter start=0 assign=i}
117    {foreach from=$filters item=filter}
118      <li class="filter_{$filter.TYPE}" id="filter_{$i}">
119        <a href="#" class="removeFilter" title="{'remove this filter'|@translate}"><span>[x]</span></a>
120        <input type="hidden" name="filters[{$i}][type]" value="{$filter.TYPE}"/>
121        {$filter.TYPE|cat:' filter'|@translate}
122       
123        <select name="filters[{$i}][cond]">
124          {html_options options=$options[$filter.TYPE] selected=$filter.COND}
125        </select>
126       
127      {if $filter.TYPE == 'tags'}
128        <select name="filters[{$i}][value]" class="tagSelect">
129        {foreach from=$filter.VALUE item=tag}
130          <option value="{$tag.id}" class="selected">{$tag.name}</option>
131        {/foreach}
132        </select>
133      {else}
134        <input type="text" name="filters[{$i}][value]" value="{$filter.VALUE}"/>
135      {/if}
136      </li>
137                        {counter}
138                {/foreach}
139   
140    {footer_script}var i={$i};{/footer_script}
141  </ul>
142
143  <p class="actionButtons">
144      <select id="addFilter">
145        <option value="-1">{'Add a filter'|@translate}</option>
146        <option disabled="disabled">------------------</option>
147        <option value="tags">{'tags filter'|@translate}</option>
148        <option value="date">{'date filter'|@translate}</option>
149        <option value="limit">{'limit filter'|@translate}</option>
150      </select>
151      <a id="removeFilters">{'Remove all filters'|@translate}</a>
152  </p>
153</div>
154   
155  <p class="actionButtons" id="applyFilterBlock">
156    <input class="submit" type="submit" value="{'Submit'|@translate}" name="submitFilters"/>
157    <input class="submit" type="submit" value="{'Count'|@translate}" name="countImages" {if !isset($filters)}style="display:none;"{/if}/>
158    <span class="count_images_display">{$IMAGE_COUNT}</span>
159  </p>
160
161</fieldset>
162</form>
163</div>
Note: See TracBrowser for help on using the repository browser.