1 <?php
defined('SYSPATH') OR die('No direct access allowed.');
2 if (isset($searches) && !empty($searches)) { ?
>
5 $
('<span id="my_saved_searches" style="padding: 4px; vertical-align: text-bottom; cursor: pointer;"><img id="my_saved_searches_img" title="Click to view your saved searches" src="/monitor/application/views/icons/16x16/save_search.png" /></span>').insertBefore('#query');
7 var name
= $
("#search_name"),
9 allFields
= $
([]).add(name
).add(query
),
10 tips
= $
(".validateTips"),
11 description
= $
('#search_description');
14 function check_save_search_fields(o
, n
, min
, max
)
16 if ( o
.val
.length
> max || o
.val().length
< min
) {
17 o
.addClass("ui-state-error");
18 updateTips(_search_save_error
, n
, min
, max
);
25 function updateTips(t
, n
, min
, max
) {
26 tips
.text( sprintf(t
, n
, min
, max
) ).addClass( "ui-state-highlight" );
27 setTimeout(function() {
28 tips
.removeClass( "ui-state-highlight", 1500 );
32 $
( "#save-search-form" ).dialog({
40 $
(this
).dialog( "close" );
42 "Save this search": function() {
44 allFields
.removeClass( "ui-state-error" );
45 bValid
= bValid
&& check_save_search_fields(query
, _search_string_field
, 1, 100);
46 bValid
= bValid
&& check_save_search_fields(name
, _search_name_field
, 1, 100);
49 $
(this
).dialog("close");
54 url
:_site_domain + _index_page +
'/' +
'/ajax/save_search',
56 data
: {name
: name
.val(), query
: query
.val(), description
: description
.val(), search_id
: $
('#search_id').val()},
57 success
: function(data
) {
58 data
= parseInt(data
, 10);
59 if (isNaN(data
)) { // return value should be an integer if OK
60 jgrowl_message(_search_saved_error
, _search_save_error
);
63 jgrowl_message(_search_saved_ok
, _search_save_ok
);
66 if ($
('#search_id').val() !== 0 && $
('#saved_searchrow_' + $
('#search_id').val())) {
67 // update list of saved searches
68 $
('#searchname_' + $
('#search_id').val()).html(name
.val());
69 $
('#searchquery_' + $
('#search_id').val()).html('<a href="' + _site_domain + _index_page +
'/' +
'search/lookup?query=' + query
.val() +
'">' + query
.val() +
'</a>');
70 $
('#searchqueryimg_' + $
('#search_id').val()).html('<a href="' + _site_domain + _index_page +
'/' +
'search/lookup?query=' + query
.val() +
'"><img src="' + _site_domain +
'icons/16x16/use_search.png" /></a>');
71 $
('#searchdescription_' + $
('#search_id').val()).html(description
.val());
73 } else if($
('#search_id').val() === 0) {
74 var previously_saved_searches_for_same_query
= $
('#saved_searches_table td[id^=searchquery_]:contains("'+query
.val()+
'")');
75 if(previously_saved_searches_for_same_query
.length
) {
76 previously_saved_searches_for_same_query
.parent('tr').remove();
78 // created new search - add rows
79 var new_data
= '<td class="edit_search_query" id="searchquery_' + data +
'"><a href="' + _site_domain + _index_page +
'/' +
'search/lookup?query=' + query
.val() +
'">' + query
.val() +
'</a></td>';
80 new_data +
= '<td class="edit_search_name" id="searchname_' + data +
'">' + name
.val() +
'</td>';
81 new_data +
= '<td class="edit_search_description" id="searchdescription_' + data +
'">' + description
.val() +
'</td>';
82 new_data +
= '<td id="searchqueryimg_' + data +
'"><a href="' + _site_domain + _index_page +
'/' +
'search/lookup?query=' + query
.val() +
'"><img src="' + _site_domain +
'icons/16x16/use_search.png" /></a></td>';
83 new_data +
= '<td class="edit_search_item" id="editsearch_' + data +
'"><img style="cursor:pointer" src="' + _site_domain +
'icons/16x16/edit.png" id="editsearchimg_' + data +
'" /></td>';
84 new_data +
= '<td class="remove_search_item" id="removesearch_' + data +
'"><img style="cursor:pointer" src="' + _site_domain +
'icons/16x16/remove.png" id="removesearchimg_' + data +
'" /></td>';
85 $
('#saved_searches_table').append('<tr id="saved_searchrow_' + data +
'">' + new_data +
'</tr>');
86 if (!$
('#my_saved_searches').is(':visible')) {
87 $
('#my_saved_searches').show();
90 $
('#search_id').attr('value', data
);
94 $
(this
).dialog("close");
99 $
('.edit_search_item').css('cursor', 'pointer');
100 $
('.remove_search_item').css('cursor', 'pointer');
101 $
('#save_search').css('cursor', 'pointer');
103 $
('#save_search').click(function() {
104 $
( "#save-search-form" ).dialog("open");
107 var old_query
= query
.val(); // stash current query
109 query
.val(old_query
);
110 $
('#search_id').val(0);
113 // ... unless there's already a saved search for the same query
115 _site_domain + _index_page +
'/ajax/fetch_saved_search_by_query',
120 error
: function(data
) {
121 jgrowl_message(data
.responseText
);
122 $
('#search_query').attr('value', old_query
);
124 complete
: function(data
) {
125 // set fetched values to edit dialog
126 $
('#search_name').attr('value', data
['search_name']);
127 $
('#search_description').attr('value', data
['search_description']);
128 $
('#search_id').attr('value', data
['search_id']);
135 // hide/show layer with saved searches
136 $
('#my_saved_searches').click(function() {
137 // try to position the dialog box
138 if ($
( "#saved_searches_table" ).is(':visible')) {
139 $
('#saved_searches_table').dialog('close');
141 $
( "#saved_searches_table" ).dialog( "open" );
145 $
("#saved_searches_table").dialog({
146 dialogClass
: 'saved_searches',
153 $
(this
).dialog( "close" );
158 // handle edit click for saved searches
159 $
('.edit_search_item').live('click', function() {
160 var the_id
= $
(this
).attr('id');
161 the_id
= the_id
.replace('editsearch_', '');
162 var original_img_src
= $
('#editsearchimg_' + the_id
).attr('src');
163 switch_image('editsearchimg_' + the_id
, loadimg_sml
.src
);
166 url
:_site_domain + _index_page +
'/' +
'/ajax/fetch_saved_search',
168 data
: {search_id
: the_id
},
169 success
: function(data
) {
170 if (data
== 'Error') {
171 jgrowl_message(_search_saved_error
, _search_save_error
);
173 data
= eval( "(" + data +
")" );
175 // set fetched values to edit dialog
176 $
('#saved_searches_table').dialog('close');
177 $
( "#save-search-form" ).dialog('open');
178 $
('#search_name').attr('value', data
['search_name']);
179 $
('#search_query').attr('value', data
['search_query']);
180 $
('#search_description').attr('value', data
['search_description']);
181 $
('#search_id').attr('value', data
['search_id']);
186 // restore original image with a timeout
187 setTimeout(function() {switch_image('editsearchimg_' + the_id
, original_img_src
);}, 3000);
190 // handle remove click for saved searches
191 $
('.remove_search_item').live('click', function() {
192 if (!confirm(_search_remove_confirm
)) {
196 var the_id
= $
(this
).attr('id');
197 the_id
= the_id
.replace('removesearch_', '');
198 var original_img_src
= $
('#removesearchimg_' + the_id
).attr('src');
199 switch_image('removesearchimg_' + the_id
, loadimg_sml
.src
);
202 url
:_site_domain + _index_page +
'/' +
'/ajax/remove_search',
204 data
: {search_id
: the_id
},
205 success
: function(data
) {
208 $
('#saved_searchrow_' + the_id
).remove();
209 if ($
('#saved_searches_table tr').length
== 1) {
210 $
('#saved_searches_table').dialog('close');
211 $
('#my_saved_searches').hide();
217 // restore original image with a timeout
218 setTimeout(function() {switch_image('removesearchimg_' + the_id
, original_img_src
);}, 3000);
222 <div id
="save-search-form" title
="<?php echo _('Save search') ?>" style
="display:none">
224 <p
class="validateTips"></p
>
226 <label
for="search_query"><?php
echo _('Search string') ?
></label
>
227 <input type
="text" name
="search_query" id
="search_query" value
="<?php echo isset($query_str) ? $query_str : '' ?>" class="texts search_query ui-widget-content ui-corner-all" />
228 <label
for="search_name"><?php
echo _('Name') ?
></label
>
229 <input type
="text" name
="search_name" id
="search_name" class="texts ui-widget-content ui-corner-all" />
230 <label
for="search_description"><?php
echo _('Description') ?
></label
>
231 <textarea cols
="30" rows
="3" name
="search_description" id
="search_description" class="texts ui-widget-content ui-corner-all"></textarea
>
232 <input type
="hidden" name
="search_id" id
="search_id" value
="0">
237 <table id
="saved_searches_table" title
="<?php echo _('Saved searches') ?>" style
="display:none">
238 <tr style
="height:20px">
239 <td
><strong
><?php
echo _('Search string') ?
></strong
></td
>
240 <td
><strong
><?php
echo _('Name') ?
></strong
></td
>
241 <td
><strong
><?php
echo _('Description') ?
></strong
></td
>
242 <td colspan
="3"></td
>
244 <?php
foreach ($searches as $s) { ?
>
245 <tr id
="saved_searchrow_<?php echo $s->id ?>">
246 <td id
="searchquery_<?php echo $s->id ?>"><?php
echo html
::anchor('search/lookup?query='.$s->search_query
, $s->search_query
, array('title' => _('Use this search'))) ?
></td
>
247 <td id
="searchname_<?php echo $s->id ?>"><?php
echo $s->search_name ?
></td
>
248 <td id
="searchdescription_<?php echo $s->id ?>"><?php
echo $s->search_description ?
></td
>
249 <td id
="searchqueryimg_<?php echo $s->id ?>"><?php
echo html
::anchor('search/lookup?query='.$s->search_query
, html
::image($this->add_path('icons/16x16/use_search.png'), array('title' => _('Use this search'))) ) ?
></td
>
250 <td
class="edit_search_item" id
="editsearch_<?php echo $s->id ?>"><?php
echo html
::image($this->add_path('icons/16x16/edit.png'), array('title' => _('Edit this search'), 'id' => 'editsearchimg_'.$s->id
)) ?
></td
>
251 <td
class="remove_search_item" id
="removesearch_<?php echo $s->id ?>"><?php
echo html
::image($this->add_path('icons/16x16/remove.png'), array('title' => _('Remove this search'), 'id' => 'removesearchimg_'.$s->id
)) ?
></td
>