filter.tpl 9.69 KB
Newer Older
1
{* $Id$ *}
2
<form method="get" action="{$filter_action|escape}" class="filter form-horizontal">
3 4 5
	<div class="form-group">
		<label class="col-sm-2 control-label">{tr}Content{/tr}</label>
		<div class="col-sm-4">
6
			<input type="search" name="filter~content" class="form-control" value="{$filter_content|escape}">
7
		</div>
8
	</div>
chibaguy's avatar
chibaguy committed
9
	{if $prefs.search_show_sort_order eq 'y'}
10
		<div class="form-group">
11 12 13 14 15 16 17 18 19 20
			<label class="col-sm-2 control-label">{tr}Sort By{/tr}</label>
			<div class="col-sm-3">
				<select name="sort_mode" class="sort_mode form-control">
					{$sort_found = false}
					{foreach from=$sort_modes key=k item=t}
						<option value="{$k|escape}"{if $k eq $sort_mode} selected="selected"{$sort_found = true}{/if}>{$t|escape}</option>
					{/foreach}
				</select>
			</div>
			{if preg_match('/desc$/',$sort_mode)}
21
				{icon name='sort-down' class='sort_invert' title="{tr}Sort direction{/tr}" href='#'}
22
			{else}
23
				{icon name='sort-up' class='sort_invert' title="{tr}Sort direction{/tr}" href='#'}
24
			{/if}
25
		</div>
chibaguy's avatar
chibaguy committed
26 27
	{else}
		<input type="hidden" name="sort_mode" value="{$sort_mode}">
28 29 30 31 32 33 34 35
		{/if}
		{if $prefs.feature_search_show_object_filter eq 'y'}
			<div class="form-group">
				<label class="col-sm-2 control-label" for="filter-type">{tr}Type{/tr}</label>
				<div class="col-sm-4">
					<select name="filter~type" id="filter-type" class="form-control">
						<option value="">{tr}Any{/tr}</option>
						{foreach from=$filter_types key=k item=t}
36
							<option value="{$k|escape}"{if $k eq $filter_type} selected="selected"{/if}>{$t|escape}</option>
37 38 39 40 41 42 43 44 45 46 47 48
						{/foreach}
					</select>
				</div>
			</div>
		{else}
			{if is_array($filter_type)}
				{foreach from=$filter_type item=t}
					<input type="hidden" name="filter~type[]" value="{$t|escape}">
				{/foreach}
			{else}
				<input type="hidden" name="filter~type" value="{$filter_type|escape}">
			{/if}
49
		{/if}
50

51 52
		{if $prefs.feature_categories eq 'y' and $tiki_p_view_category eq 'y' and $prefs.search_show_category_filter eq 'y'}
			<div class="form-group">
chibaguy's avatar
chibaguy committed
53
				<label class="col-sm-2 control-label" for="filter-categories">{tr}Categories{/tr}</label>
54
				<div class="col-sm-4">
55
					<a class="category-lookup btn btn-default margin-bottom-sm" href="#">{tr}Lookup{/tr}</a>
chibaguy's avatar
chibaguy committed
56
					<input type="text" name="filter~categories" id="filter-categories" class="category-wizard form-control" value="{$filter_categories|escape}">
57
				</div>
58
				<div class="col-sm-5 checkbox">
59 60 61 62 63
					<label for="filter-deep">
						<input type="checkbox" name="filter~deep" id="filter-deep" {if $filter_deep} checked="checked"{/if}> {tr}Deep search{/tr}
					</label>
				</div>
			</div>
64

65 66 67 68 69 70 71 72 73 74 75 76 77
			<div class="category-picker" title="{tr}Select Categories{/tr}" style="display:none;">
				{$filter_category_picker}
			</div>
		{/if}
		{if $prefs.feature_freetags eq 'y' and $tiki_p_view_freetags eq 'y' and $prefs.search_show_tag_filter eq 'y'}
			<div class="form-group">
				<label class="col-sm-2 control-label" for="filter-tags">{tr}Tags{/tr}</label>
				<div class="col-sm-4">
					<a class="tag-lookup btn btn-default" href="#">{tr}Lookup{/tr}</a>
					<input type="text" name="filter~tags" class="tag-wizard" id="filter-tags" value="{$filter_tags|escape}">
				</div>
				<div class="tag-picker" title="{tr}Select Tags{/tr}" style="display:none;">
					{$filter_tags_picker}
78 79
				</div>
			</div>
80
		{/if}
81 82 83 84 85 86 87 88
		{if isset($filter.tracker_id)}
			<div class="form-group">
				<label class="col-sm-2 control-label" for="filter-tracker_id">{tr}Tracker{/tr}</label>
				<div class="col-sm-4">
					{object_selector type=tracker _simplevalue=$filter.tracker_id _simplename="filter~tracker_id" _simpleid="filter-tracker_id"}
				</div>
			</div>
		{/if}
89 90 91 92 93 94 95 96 97 98 99 100
		{if $prefs.feature_multilingual eq 'y'}
			{if $prefs.search_default_interface_language neq 'y'}
				<div class="form-group">
					<label class="col-sm-2 control-label" for="filter-language">{tr}Language{/tr}</label>
					<div class="col-sm-4">
						<select name="filter~language" class="form-control" id="filter-language">
							<option value="">{tr}Any{/tr}</option>
							{foreach from=$filter_languages item=l}
								<option value="{$l.value|escape}"{if $filter_language eq $l.value} selected="selected"{/if}>{$l.name|escape}</option>
							{/foreach}
						</select>
					</div>
101 102 103 104 105
					<div class="col-sm-5">
						<label for="filter-language-unspecified-checkbox" class="checkbox-inline">
							<input type="checkbox" id="filter-language-unspecified-checkbox" name="filter~language_unspecified"{if $filter_language_unspecified} checked="checked"{/if}>
							{tr}Include objects without a specified language{/tr}
						</label>
106 107 108 109 110 111 112
					</div>
				</div>
			{else}
				<input type="hidden" name="filter~language" value="{$prefs.language}">
				<input type="hidden" name="filter~language_unspecified" value="1">
			{/if}
		{/if}
113

114 115
	<div class="text-center">
		<input type="submit" class="btn btn-primary" value="{tr}Search{/tr}">
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
		{if $prefs.tracker_tabular_enabled eq 'y' && ! empty($smarty.get.tabularId)}
			<input type="hidden" name="tabularId" value="{$smarty.get.tabularId|escape}">
			<button class="tabular-export btn btn-default">
				{icon name=export} {tr}Export{/tr}
			</button>
			{jq}
				$(document).on('click', '.tabular-export', function (e) {
					var href = $.service('tabular', 'export_search_csv', {
						tabularId: "{{$smarty.get.tabularId}}"
					});
					e.preventDefault();
					document.location.href = href + '&' + $(this).closest('form').serialize();
				});
			{/jq}
		{elseif $prefs.tracker_tabular_enabled eq 'y' && ! empty($filter.tracker_id)}
			<button class="tabular-export btn btn-default">
				{icon name=export} {tr}Export{/tr}
			</button>
			{jq}
				$(document).on('click', '.tabular-export', function (e) {
					var href = $.service('tabular', 'export_search_csv', {
						trackerId: "{{$filter.tracker_id}}"
					});
					e.preventDefault();
					$.openModal({
						remote: href + '&' + $(this).closest('form').serialize()
					});
				});
			{/jq}
		{/if}
146
		{if $prefs.storedsearch_enabled eq 'y' and $user}
147
			<input type="hidden" name="storeAs" value=""/>
148 149
			<a href="{service controller=search_stored action=select modal=true}" id="store-query" class="btn btn-default">{tr}Save Search{/tr}</a>
			<a href="{service controller=search_stored action=list}" class="btn btn-link">{tr}View Saved Searches{/tr}</a>
150
			{jq}
151 152 153 154 155 156 157 158
				$('#store-query').clickModal({
					success: function (data) {
						var form = $(this).closest('form')[0];

						$(form.storeAs).val(data.queryId);
						$(form).attr('method', 'post');
						$(form).submit();
					}
159 160 161
				});
			{/jq}
		{/if}
lindonb's avatar
lindonb committed
162
		<a href="{bootstrap_modal controller=search action=help}">{tr}Search Help{/tr} {icon name='help'}</a>
163
	</div>
164 165
</form>
{jq}
166
	$('.filter:not(.init)').addClass('init').each(function () {
167 168

{{if $prefs.feature_categories eq 'y'}}
169
		var categoryInput = $('.category-wizard', this).fancy_filter('init', {
170
			map: {{$filter_categmap|json_encode}}
171 172 173
		});

		var categoryPicker = $('.category-picker', this).dialog({
174
			maxHeight: $(window).height()-50,
175
			width: 'auto',
176 177 178 179 180 181 182
			autoOpen: false,
			modal: true,
			buttons: {
				"{tr}Add to filter{/tr}": function () {
					$(':checked', this).each(function () {
						categoryInput.fancy_filter('add', {
							token: $(this).val(),
183 184
							label: $(this).parent().text(),
							join: ' or '
185 186 187 188 189 190 191 192 193
						});
					});
					$(this).dialog('close');
				},
				"{tr}Cancel{/tr}": function () {
					$(this).dialog('close');
				}
			},
			close: function () {
194
				$(':checked', this).prop('checked', false);
195 196 197 198 199 200 201
			}
		});

		$('.category-lookup', this).click(function () {
			categoryPicker.dialog('open');
			return false;
		});
202
{{/if}}
203 204 205 206 207 208 209 210 211 212 213 214 215 216

{{if $prefs.feature_freetags eq 'y'}}
		var tagInput = $('.tag-wizard', this).fancy_filter('init', {
			map: {{$filter_tagmap}}
		});

		$('.tag-picker a', this).click(function () {
			$(this).toggleClass('highlight');

			return false;
		});
		var tagPicker = $('.tag-picker', this).dialog({
			autoOpen: false,
			modal: true,
217
			maxHeight: $window.height() - 50,
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
			buttons: {
				"{tr}Add to filter{/tr}": function () {
					$('.highlight', this).each(function () {
						tagInput.fancy_filter('add', {
							token: $(this).attr('href'),
							label: $(this).text(),
							join: ' and '
						});
					});
					$(this).dialog('close');
				},
				"{tr}Cancel{/tr}": function () {
					$(this).dialog('close');
				}
			},
			close: function () {
234
				$(':checked', this).prop('checked', false);
235 236 237 238 239 240 241 242
			}
		});

		$('.tag-lookup', this).click(function () {
			tagPicker.dialog('open');
			return false;
		});
{{/if}}
243 244 245 246 247 248 249 250 251 252 253

{{if $prefs.search_show_sort_order eq 'y'}}
		var $invert = $(".sort_invert", this);
		var $sort_mode = $(".sort_mode", this);
{{if not $sort_found}}
		var opts = $sort_mode.prop("options");
		for (var o = 0; o < opts.length; o++) {	// sort_mode not in intially rendered list, so try and find the opposite direction
			var tofind = "{{$sort_mode}}";
			tofind = tofind.replace(/(:?asc|desc)$/, "");
			if (opts[o].value.search(tofind) === 0) {
				opts[o].value = "{{$sort_mode}}";
254
				$sort_mode.prop("selectedIndex", o).trigger("chosen:updated");
255 256 257 258 259
				break;
			}
		}
{{/if}}

260
		$sort_mode.change(function () {	// update direction arrow
261 262
			$(".icon", $invert).setIcon($(this).val().search(/desc$/) > -1 ? "sort-down" : "sort-up");
		});
263

264
		$invert.click(function () {	// change the value of the option to opposite direction
265 266 267
			var v = $sort_mode.prop("options")[$sort_mode.prop("selectedIndex")].value;
			if (v.search(/desc$/) > -1) {
				$sort_mode.prop("options")[$sort_mode.prop("selectedIndex")].value = v.replace(/desc$/, "asc");
268
				$(".icon", $invert).setIcon("sort-up");
269 270
			} else {
				$sort_mode.prop("options")[$sort_mode.prop("selectedIndex")].value = v.replace(/asc$/, "desc");
271
				$(".icon", $invert).setIcon("sort-down");
272
			}
273
			$(this).parents("form").submit();
274 275 276 277
			return false;
		});
{{/if}}

278 279
	});
{/jq}