piler/webui/view/javascript/piler-in.js

1432 lines
36 KiB
JavaScript
Raw Permalink Normal View History

2012-02-08 23:14:28 +01:00
var Piler =
2013-02-11 20:24:19 +01:00
{
/*
2013-02-11 20:24:19 +01:00
* which search type is active, it's set by clicking on the 'Search' button
*/
search:'',
// legacy variable(s)
expsrc: 0,
2013-02-17 10:35:51 +01:00
health_refresh: <?php print HEALTH_REFRESH; ?>,
piler_ui_lang: '<?php LANG == 'en' ? print 'en-GB' : print LANG; ?>',
2013-02-11 20:24:19 +01:00
prev_message_id: 0,
pos: -1,
2013-03-31 14:50:21 +02:00
current_message_id: 0,
folders: '',
extra_folders: '',
2013-11-16 15:34:30 +01:00
bulkrestore_url: '/bulkrestore.php',
bulkpdf_url: '/bulkpdf.php',
2013-03-31 14:50:21 +02:00
2013-02-11 20:24:19 +01:00
/*
* variables used at search listing
*/
Shared: {
page:0,
sort:1,
order:'date',
type: 'search'
},
/*
* search data
*/
2013-04-22 16:52:02 +02:00
Searches: {},
2013-02-11 20:24:19 +01:00
/*
* message meta ids
*/
Messages:[],
/*
* System logger
*/
log:function( )
{
if ( window.console )
{
var
2013-02-11 20:24:19 +01:00
a = arguments,
b = +new Date,
c = window.console;
2013-02-11 20:24:19 +01:00
if ( !a.length )
c.clear();
else if ( a.length > 1 )
c.log(b, a[0], [].slice.call(arguments, 1));
// c.log(b, a[0], JSON.stringify([].slice.call(a, 1)));
else
c.log(b, a[0]);
2013-02-11 20:24:19 +01:00
}
},
/**
* Returns the javascript event source.
*
2013-02-11 20:24:19 +01:00
* @param {Object} a Javascript event
* @param {Logical} [b] If exist the event propagation NOT! stoped
*
* @return {Object<jQuery>} Javascript event source
**/
getSource:function( a, b )
{
Piler.log("[getSource]", a, b );
2013-02-11 20:24:19 +01:00
if ( !b )
{
try {
if ( a.stopPropagation )
a.stopPropagation();
else
a.cancelBubble = !0;
}
catch ( e )
2013-02-11 20:24:19 +01:00
{
Piler.log("[getSource]", e );
2013-02-11 20:24:19 +01:00
}
}
2012-02-08 23:14:28 +01:00
2013-02-11 20:24:19 +01:00
return $( a.target ? a.target : a.srcElement );
},
/*
* Change the list order.
*
2013-02-11 20:24:19 +01:00
* HTML: <a class="VALAMI" onclick="Piler.changeOrder(this)" xid="date" xorder="0"></a>
* CSS: .VALAMI {
* background: url("/view/theme/default/images/arrowup.gif") no-repeat scroll center center transparent;
* cursor: pointer;
* float: left;
* height: 10px;
* width: 10px;
* }
* @param {Object} a Javascript event
*
*/
changeOrder:function( a )
{
a = $( a );// a == DOM element
// a = Piler.getSource( a );// a == Javascript event
Piler.Shared.sort = a.attr('xid');// {String} (date|from|subject|size)
Piler.Shared.order = a.attr('xorder');// {Number} (0|1) -> (ASC|DESC)
Piler.log("[changeOrder]", Piler.Shared.sort, Piler.Shared.order);
Piler.load_search_results( );
},
/*
* load search results to div
*
*/
load_search_results:function( )
2013-02-11 20:24:19 +01:00
{
var url;
2014-09-17 11:24:40 +02:00
Piler.poor_mans_keepalive_for_dummy_browsers();
2013-02-11 20:24:19 +01:00
Piler.Shared.type == 'search' ? url = '/search-helper.php' : url = '/audit-helper.php';
Piler.log("[load_search_results]", url);
2013-03-31 14:50:21 +02:00
2013-02-11 20:24:19 +01:00
Piler.spinner('start');
jQuery.ajax( url, {
data: $.extend(!0, {}, Piler.Shared, Piler.Searches[Piler.search]),
type: "POST"
})
.done( function( a )// data, textStatus, jqXHR
{
2013-04-22 16:52:02 +02:00
if(a.indexOf('<?php print PILER_LOGIN_HELPER_PLACEHOLDER; ?>') > 0) {
document.location.href = '<?php print SITE_URL; ?>';
return true;
}
$('#mailcontframe').html(a);
2013-02-11 20:24:19 +01:00
Piler.fill_current_messages_array();
Piler.spinner('stop');
$('#resultsheader').show();
2013-08-20 14:47:55 +02:00
2013-08-22 11:24:54 +02:00
<?php if(ENABLE_TABLE_RESIZE == 1) { ?>
$("table").resizableColumns({
2013-08-20 14:47:55 +02:00
store: store
2013-08-22 11:24:54 +02:00
});
<?php } ?>
2013-02-11 20:24:19 +01:00
})
.fail(function( a, b )// jqXHR, textStatus, errorThrown
{
alert("Problem retrieving XML data:" + b)
});
2013-02-11 20:24:19 +01:00
},
/*
* show/hide spinner
*/
spinner:function(cmd)
{
Piler.log("[spinner]", cmd);
if(cmd == 'start') {
$('#sspinner').show();
$('#messagelistcontainer').hide();
}
2012-02-08 23:14:28 +01:00
2013-02-11 20:24:19 +01:00
if(cmd == 'stop') {
$('#sspinner').hide();
$('#messagelistcontainer').show();
}
},
2012-02-08 23:14:28 +01:00
2012-09-06 15:27:20 +02:00
2013-02-11 20:24:19 +01:00
/*
* save current search criteria
*/
2012-09-06 15:27:20 +02:00
2013-02-11 20:24:19 +01:00
saved_search_terms:function(msg)
{
Piler.log("[saved_search_terms]");
2012-09-06 15:27:20 +02:00
2014-09-17 11:24:40 +02:00
Piler.poor_mans_keepalive_for_dummy_browsers();
2013-02-11 20:24:19 +01:00
jQuery.ajax( '/index.php?route=search/save', {
data: $.extend(!0, { }, Piler.Shared, Piler.Searches[Piler.search], {save: '1'} ),
type: "POST"
})
.done( function( a )
{
})
.fail(function( a, b )
{
alert("Problem retrieving XML data:" + b)
});
2012-02-10 14:06:00 +01:00
2013-02-11 20:24:19 +01:00
Piler.show_message('messagebox1', msg, 0.85);
},
2012-02-08 23:14:28 +01:00
2013-02-11 20:24:19 +01:00
/*
* load saved search criteria list by ajax
*/
2012-09-17 16:49:27 +02:00
2013-02-11 20:24:19 +01:00
load_saved_search_terms:function()
{
Piler.log("[load_saved_search_terms]");
2012-09-17 16:49:27 +02:00
2013-02-11 20:24:19 +01:00
jQuery.ajax( '/index.php?route=search/load', {
})
.done( function( a )
{
$('#mailcontframe').html( a );
})
.fail(function( a, b )
{
alert("Problem retrieving XML data:" + b)
});
},
2013-07-27 13:10:48 +02:00
2013-08-01 22:28:42 +02:00
remove_saved_search_term:function(ts)
2013-07-27 13:10:48 +02:00
{
2013-08-01 22:28:42 +02:00
Piler.log("[remove_saved_search_term]");
2013-07-27 13:10:48 +02:00
2013-08-01 22:28:42 +02:00
jQuery.ajax('/index.php?route=search/remove&ts=' + ts, {})
.done(function(a) {})
2013-07-27 13:10:48 +02:00
.fail(function(a, b) { alert("Problem retrieving XML data:" + b) });
2013-08-01 22:28:42 +02:00
Piler.load_saved_search_terms();
2013-07-27 13:10:48 +02:00
},
2012-09-15 15:30:35 +02:00
2013-02-11 20:24:19 +01:00
/*
2013-02-27 21:03:46 +01:00
* load the selected message by position to preview area
2013-02-11 20:24:19 +01:00
*/
2012-09-06 15:27:20 +02:00
2013-02-27 21:03:46 +01:00
view_message_by_pos:function(pos)
2013-02-11 20:24:19 +01:00
{
2013-04-18 16:31:30 +02:00
Piler.log("[view_message_by_pos]", pos, Piler.Messages[pos]);
2012-09-06 15:27:20 +02:00
if(pos == -1) return false;
2013-02-11 20:24:19 +01:00
id = Piler.Messages[pos];
2012-02-08 23:14:28 +01:00
2013-02-11 20:24:19 +01:00
Piler.pos = pos;
2012-02-08 23:14:28 +01:00
2013-02-11 20:24:19 +01:00
if(Piler.prev_message_id > 0) { $('#e_' + Piler.prev_message_id).attr('class', 'resultrow'); }
2012-02-08 23:14:28 +01:00
2013-02-11 20:24:19 +01:00
$('#e_' + id).attr('class', 'resultrow selected');
2012-02-08 23:14:28 +01:00
2013-02-11 20:24:19 +01:00
Piler.prev_message_id = id;
2013-02-27 21:03:46 +01:00
Piler.view_message(id);
$('#mailpreviewframe').scrollTop(0);
2013-02-27 21:03:46 +01:00
},
view_message:function(id)
{
var search = $('#_search').val();
2014-09-17 11:24:40 +02:00
Piler.poor_mans_keepalive_for_dummy_browsers();
Piler.log("[view_message]", id, search);
jQuery.ajax('/message.php', {
data: { id: id, search: search },
type: "POST"
})
2013-02-11 20:24:19 +01:00
.done( function(a) {
2013-04-22 16:52:02 +02:00
if(a.indexOf('<?php print PILER_LOGIN_HELPER_PLACEHOLDER; ?>') > 0) {
document.location.href = '<?php print SITE_URL; ?>';
return true;
}
2013-02-11 20:24:19 +01:00
$('#mailpreviewframe').html(a);
})
.fail(function(a, b) { alert("Problem retrieving XML data:" + b) });
},
2012-02-08 23:14:28 +01:00
2013-02-11 20:24:19 +01:00
view_headers:function(id)
{
Piler.log("[view_headers]");
Piler.load_url_to_preview_pane('/index.php?route=message/headers&id=' + id);
},
2012-02-08 23:14:28 +01:00
2013-07-12 11:14:09 +02:00
view_journal:function(id)
{
Piler.log("[view_journal]");
Piler.load_url_to_preview_pane('/index.php?route=message/journal&id=' + id);
},
2014-01-16 12:57:29 +01:00
not_spam:function(id)
{
Piler.log("[not_spam]", id);
2014-09-17 11:24:40 +02:00
Piler.poor_mans_keepalive_for_dummy_browsers();
2014-01-16 12:57:29 +01:00
jQuery.ajax('index.php?route=message/notspam', {
data: { id: id },
type: "POST"
})
.done( function( a ) {})
.fail(function(a, b) { alert("Problem retrieving XML data:" + b) });
Piler.show_message('messagebox1', "OK", 0.8);
},
2016-02-16 15:37:34 +01:00
mark_as_private:function(id, val)
2016-02-10 14:57:30 +01:00
{
2016-02-16 15:37:34 +01:00
Piler.log("[mark_as_private]", id, val);
2016-02-10 14:57:30 +01:00
Piler.poor_mans_keepalive_for_dummy_browsers();
jQuery.ajax('index.php?route=message/private', {
2016-02-16 15:37:34 +01:00
data: { id: id, val: val },
2016-02-10 14:57:30 +01:00
type: "POST"
})
.done( function( a ) {})
.fail(function(a, b) { alert("Problem retrieving XML data:" + b) });
Piler.show_message('messagebox1', "OK", 0.8);
},
2013-02-11 20:24:19 +01:00
restore_message:function(id)
{
Piler.log("[restore_message]");
2014-09-22 11:21:40 +02:00
jQuery.ajax('/index.php?route=message/restore&id=' + id, {})
.done(function(a) {})
.fail(function(a, b) { alert("Problem retrieving XML data:" + b) });
Piler.show_message('messagebox1', "OK", 0.8);
2013-02-11 20:24:19 +01:00
},
2012-02-08 23:14:28 +01:00
show_bulk_remove_modal:function()
{
Piler.log("[show_bulk_remove_modal]");
$('#deletebox-modal').modal('show');
},
bulk_remove_messages:function(reason, text_successfully_removed, text_no_selected_message)
2015-07-07 14:12:35 +02:00
{
Piler.log("[bulk_remove_messages]");
Piler.poor_mans_keepalive_for_dummy_browsers();
var idlist = Piler.get_selected_messages_list();
if(!idlist) {
Piler.show_message('messagebox1', text_no_selected_message, 2.5);
return;
}
2015-07-07 14:12:35 +02:00
jQuery.ajax('/bulkremove.php', {
data: { idlist: idlist, reason: reason },
2015-07-07 14:12:35 +02:00
type: "POST"
})
.done( function( a ) {})
.fail(function( a, b ) { alert("Problem retrieving XML data:" + b) });
Piler.show_message('messagebox1', text_successfully_removed, 0.8);
2015-07-07 14:12:35 +02:00
},
reject_removing_message:function(id, reason2)
{
Piler.log("[reject_removing_message]", id, reason2);
Piler.poor_mans_keepalive_for_dummy_browsers();
jQuery.ajax('/rejectremove.php', {
data: { id: id, confirmed: 1, reason2: reason2 },
type: "POST"
})
.done( function( a ) { location.reload(); })
.fail(function( a, b ) { alert("Problem retrieving XML data:" + b) });
$('#delete-rejected-modal').modal('hide')
},
bulk_restore_messages:function(msg, email)
2013-02-11 20:24:19 +01:00
{
Piler.log("[bulk_restore_messages]", email);
2012-02-08 23:14:28 +01:00
2014-09-17 11:24:40 +02:00
Piler.poor_mans_keepalive_for_dummy_browsers();
2013-02-11 20:24:19 +01:00
var idlist = Piler.get_selected_messages_list();
2012-02-08 23:14:28 +01:00
2013-02-11 20:24:19 +01:00
if(!idlist) return;
2012-02-08 23:14:28 +01:00
2013-02-11 20:24:19 +01:00
jQuery.ajax('/bulkrestore.php', {
data: { download: '0', idlist: idlist, email: email },
2013-02-11 20:24:19 +01:00
type: "POST"
})
.done( function( a ) {})
.fail(function( a, b ) { alert("Problem retrieving XML data:" + b) });
2012-02-08 23:14:28 +01:00
2013-02-11 20:24:19 +01:00
Piler.show_message('messagebox1', msg, 0.8);
},
2012-02-10 14:06:00 +01:00
2012-02-08 23:14:28 +01:00
2013-02-11 20:24:19 +01:00
/*
* bulk toggle all the checkboxes for the result set
*/
2012-02-08 23:14:28 +01:00
toggle_bulk_check:function(i)
2013-02-11 20:24:19 +01:00
{
Piler.log("[toggle_bulk_check]", Piler.Messages.length);
2012-02-08 23:14:28 +01:00
$('#bulkcheck' + i).prop('checked') ? bulkcheck = 1 : bulkcheck = 0;
2012-02-08 23:14:28 +01:00
2013-02-11 20:24:19 +01:00
Piler.log("[toggle_bulk_check], bulkcheck=", bulkcheck);
2012-02-08 23:14:28 +01:00
2013-02-11 20:24:19 +01:00
for(i=0; i<Piler.Messages.length; i++) {
bulkcheck == 1 ? $("#r_" + Piler.Messages[i]).prop('checked', true) : $("#r_" + Piler.Messages[i]).prop('checked', false);
}
if(bulkcheck == 1) {
$("#bulkcheck").prop('checked', true);
$("#bulkcheck2").prop('checked', true);
} else {
$("#bulkcheck").prop('checked', false);
$("#bulkcheck2").prop('checked', false);
}
2013-02-11 20:24:19 +01:00
},
2012-02-08 23:14:28 +01:00
2013-02-11 20:24:19 +01:00
add_note_to_message:function(id, msg)
{
Piler.log("[add_note_to_message]", id, msg);
2012-02-08 23:14:28 +01:00
2014-09-17 11:24:40 +02:00
Piler.poor_mans_keepalive_for_dummy_browsers();
2013-02-11 20:24:19 +01:00
jQuery.ajax('index.php?route=message/note', {
data: { id: id, note: encodeURI($('#note').val()) },
type: "POST"
})
.done( function(a) {})
.fail(function(a, b) { alert("Problem retrieving XML data:" + b) });
2012-02-08 23:14:28 +01:00
2013-02-11 20:24:19 +01:00
Piler.show_message('messagebox1', msg, 0.85);
},
2012-02-10 14:06:00 +01:00
2012-02-08 23:14:28 +01:00
2015-09-18 14:56:09 +02:00
update_message_folder:function(id, msg)
{
Piler.log("[update_message_folder]", id, msg);
Piler.poor_mans_keepalive_for_dummy_browsers();
jQuery.ajax('index.php?route=message/folder', {
data: { id: id, folder_id: $('#folder_id').val() },
type: "POST"
})
.done( function(a) {})
.fail(function(a, b) { alert("Problem retrieving XML data:" + b) });
Piler.show_message('messagebox1', msg, 0.85);
},
2013-02-11 20:24:19 +01:00
tag_search_results:function(msg)
{
Piler.log("[tag_search_results]", msg);
2012-02-08 23:14:28 +01:00
2014-09-17 11:24:40 +02:00
Piler.poor_mans_keepalive_for_dummy_browsers();
2013-02-11 20:24:19 +01:00
var idlist = Piler.get_selected_messages_list();
2012-02-08 23:14:28 +01:00
Piler.log("[tag_search_results, idlist]", idlist);
if(!idlist) return false;
2012-02-08 23:14:28 +01:00
2013-02-11 20:24:19 +01:00
jQuery.ajax('index.php?route=search/tag', {
data: { tag: encodeURI($('#tag_value').val()), idlist: idlist },
type: "POST"
})
.done( function(a) {})
.fail(function(a, b) { alert("Problem retrieving XML data:" + b) });
2012-02-08 23:14:28 +01:00
2013-02-11 20:24:19 +01:00
Piler.show_message('messagebox1', msg, 0.85);
},
2012-02-08 23:14:28 +01:00
2013-02-11 20:24:19 +01:00
/*
* load the given url to the preview pane
*/
2012-02-08 23:14:28 +01:00
2013-02-11 20:24:19 +01:00
load_url_to_preview_pane:function(url)
{
Piler.log("[load_url_to_preview_pane]", url);
2012-02-08 23:14:28 +01:00
2014-09-17 11:24:40 +02:00
Piler.poor_mans_keepalive_for_dummy_browsers();
2013-02-11 20:24:19 +01:00
jQuery.ajax(url, { cache: true })
.done( function(a) { $('#mailpreviewframe').html(a); })
.fail(function(a, b) { alert("Problem retrieving XML data:" + b) });
},
2012-02-08 23:14:28 +01:00
2013-02-11 20:24:19 +01:00
/*
* return a comma separated list of selected messages
*/
2012-02-08 23:14:28 +01:00
2013-02-11 20:24:19 +01:00
get_selected_messages_list:function()
{
Piler.log("[get_selected_messages_list]");
2012-02-08 23:14:28 +01:00
2013-02-11 20:24:19 +01:00
var idlist = '';
2012-02-08 23:14:28 +01:00
2013-02-11 20:24:19 +01:00
for(i=0; i<Piler.Messages.length; i++) {
if($('#r_' + Piler.Messages[i]).prop('checked')) {
if(idlist) idlist += ",";
idlist += Piler.Messages[i];
//Piler.log("[selected message, id:]", Piler.Messages[i]);
}
}
2012-02-08 23:14:28 +01:00
2013-02-11 20:24:19 +01:00
Piler.log("[get_selected_messages_list], result:", idlist);
2012-02-08 23:14:28 +01:00
2013-02-11 20:24:19 +01:00
return idlist;
},
2012-02-08 23:14:28 +01:00
2013-11-16 15:34:30 +01:00
get_messages_list:function()
{
var idlist = '';
for(i=0; i<Piler.Messages.length; i++) {
if(idlist) idlist += ",";
idlist += Piler.Messages[i];
}
return idlist;
},
2013-02-11 20:24:19 +01:00
/*
* fill Messages array with search results
*/
fill_current_messages_array:function()
2013-02-11 20:24:19 +01:00
{
Piler.log("[fill_current_messages_array]");
var z = $('#results tbody').children(), y = z.length, x;
2013-02-11 20:24:19 +01:00
var u = [];
2012-02-08 23:14:28 +01:00
Piler.log("[fill_current_messages_array] y", y );
2012-02-08 23:14:28 +01:00
2013-02-11 20:24:19 +01:00
for (i=0; i<y; i++)
{
x = z[i];
2012-02-08 23:14:28 +01:00
if ( x.nodeName == "TR" && x.id.charAt( 0 ) == 'e' && x.id.charAt( 1 ) == '_' )
2013-02-11 20:24:19 +01:00
{
2013-02-27 21:03:46 +01:00
Piler.log("[fill_current_messages_array], pos/id", i, x.id.substring(2, 1000));
2012-02-08 23:14:28 +01:00
2013-02-11 20:24:19 +01:00
u[i] = x.id.substring(2, 1000);
}
}
2012-02-08 23:14:28 +01:00
2013-02-11 20:24:19 +01:00
Piler.Messages = u;
Piler.pos = -1;
Piler.prev_message_id = 0;
2013-03-31 14:50:21 +02:00
Piler.current_message_id = 0;
},
2012-02-08 23:14:28 +01:00
2013-02-11 20:24:19 +01:00
show_next_message:function()
{
if(Piler.pos < Piler.Messages.length-1) { Piler.pos++; }
2012-03-10 14:52:50 +01:00
2013-02-11 20:24:19 +01:00
Piler.log("[show_next_message]", Piler.pos);
2012-03-10 14:52:50 +01:00
2013-03-02 15:25:24 +01:00
Piler.view_message_by_pos(Piler.pos);
2013-02-11 20:24:19 +01:00
},
2012-03-10 14:52:50 +01:00
2013-02-11 20:24:19 +01:00
show_prev_message:function()
{
if(Piler.pos > 0) { Piler.pos--; }
2012-03-10 14:52:50 +01:00
2013-02-11 20:24:19 +01:00
Piler.log("[show_prev_message]", Piler.pos);
2012-03-10 14:52:50 +01:00
2013-03-02 15:25:24 +01:00
Piler.view_message_by_pos(Piler.pos);
2013-02-11 20:24:19 +01:00
},
2012-03-10 14:52:50 +01:00
2013-02-11 20:24:19 +01:00
/*
* load the search results for a saved query
* TODO: fix searchtype, it can be even 'complex', too
*/
2012-03-10 14:52:50 +01:00
2013-02-11 20:24:19 +01:00
load_search_results_for_saved_query:function(terms)
{
Piler.log("[load_search_results_for_saved_query]", terms);
2012-03-10 14:52:50 +01:00
terms = decodeURIComponent(terms);
2013-02-11 20:24:19 +01:00
var pairs = terms.split('&');
$.each(pairs, function(i, v){
var pair = v.split('=');
if(pair[0] == 'search') {
var search = decodeURIComponent(pair[1]);
$("input#_search").val(search.replace(/\+/g, " "));
2013-02-11 20:24:19 +01:00
}
});
2012-05-07 09:38:47 +02:00
2013-02-11 20:24:19 +01:00
Piler.expsrc++;
$('#_search').css('color', 'black');
2012-05-07 09:38:47 +02:00
2013-02-11 20:24:19 +01:00
Piler.expert();
},
2012-05-07 09:38:47 +02:00
2013-02-11 20:24:19 +01:00
/*
* expert search
*
2013-02-11 20:24:19 +01:00
* HTML: <button onclick="Piler.simple(this)">Search</button>
* <button onclick="script:var a=document.getElementById('ref'); if(a) a.value=''; a = document.getElementById('prefix'); if(a) a.value='';
* load_search_results('http://demo.mailpiler.org/search-helper.php', assemble_search_term(count), 0);"
* style="margin-left: 10px; margin-right: 0px; height: 20px; width: 70px;" class="active" id="button_search">Search</button>
2013-02-11 20:24:19 +01:00
**/
expert:function( )// a )
{
Piler.log("[expert]")//, a );
2012-05-07 09:38:47 +02:00
2013-02-11 20:24:19 +01:00
// a = $( a );// a == DOM element
// a = Piler.getSource( a );// a == Javascript event
2012-05-07 09:38:47 +02:00
2013-02-11 20:24:19 +01:00
$('#prefix').val('');
2012-05-07 09:38:47 +02:00
2013-02-11 20:24:19 +01:00
Piler.search = 'Expert';
2013-02-11 20:24:19 +01:00
Piler.Shared.page = 0;
Piler.Shared.type = 'search';
2013-03-31 14:50:21 +02:00
Piler.assemble_folder_restrictions();
2013-02-11 20:24:19 +01:00
Piler.Searches.Expert = {
search: $.trim($('input#_search').val()),
searchtype: 'expert',
ref: $.trim($('#ref').val()),
2013-03-31 14:50:21 +02:00
folders: Piler.folders,
extra_folders: Piler.extra_folders
2013-02-11 20:24:19 +01:00
}
2013-02-11 20:24:19 +01:00
$('#ref').val('');
2013-02-11 20:24:19 +01:00
Piler.load_search_results();
},
2013-02-11 20:24:19 +01:00
/**
* complex search
*
2013-02-11 20:24:19 +01:00
* HTML: <button id="simple" class="active" onclick="Piler.complex(this)">Search</button>
* CSS: #expert { margin-left: 10px; margin-right: 0px; height: 20px; width: 70px; }
*
2013-02-11 20:24:19 +01:00
**/
complex:function( )// a )
{
Piler.log("[complex]")//, a );
2013-02-11 20:24:19 +01:00
// a = $( a );// a == DOM element
// a = Piler.getSource( a );// a == Javascript event
2013-03-31 14:50:21 +02:00
2013-02-11 20:24:19 +01:00
var z = $('div#searchpopup1');
2013-03-31 14:50:21 +02:00
2013-02-11 20:24:19 +01:00
Piler.search = 'Complex';
2013-04-05 10:16:33 +02:00
2013-02-11 20:24:19 +01:00
Piler.Shared.page = 0;
Piler.Shared.type = 'search';
2013-03-31 14:50:21 +02:00
Piler.assemble_folder_restrictions();
var attachments_type = '';
if($('input#xhas_attachment_any', z)[0].checked) { attachments_type += ',any'; }
if($('input#xhas_attachment_doc', z)[0].checked) { attachments_type += ',word'; }
if($('input#xhas_attachment_xls', z)[0].checked) { attachments_type += ',excel'; }
if($('input#xhas_attachment_pdf', z)[0].checked) { attachments_type += ',pdf'; }
if($('input#xhas_attachment_image', z)[0].checked) { attachments_type += ',image'; }
if(attachments_type) { attachments_type = attachments_type.substring(1, attachments_type.length); }
2013-02-11 20:24:19 +01:00
Piler.Searches.Complex = {
from : $.trim($('input#xfrom', z).val()),
to : $.trim($('input#xto', z).val()),
subject : $.trim($('input#xsubject', z).val()),
body : $.trim($('input#xbody', z).val()),
tag : $.trim($('input#xtag', z).val()),
note : $.trim($('input#xnote', z).val()),
attachment_type : attachments_type,
date1 : $.trim($('input#date1', z).val()),
date2 : $.trim($('input#date2', z).val()),
2013-03-31 14:57:55 +02:00
searchtype : 'simple',
folders: Piler.folders,
extra_folders: Piler.extra_folders
2013-02-11 20:24:19 +01:00
}
2013-03-31 14:50:21 +02:00
Piler.load_search_results();
2013-02-11 20:24:19 +01:00
$('#searchpopup1').hide();
},
2013-04-05 10:16:33 +02:00
2013-02-11 20:24:19 +01:00
/*
* paging function
*
2013-02-11 20:24:19 +01:00
* HTML: <a onclick="Piler.navigation(${PHP_PAGE})" class="navlink">${next page}</a>
*
2013-02-11 20:24:19 +01:00
*/
navigation:function( a )
{
Piler.log("[navigation]")//, a );
2013-02-11 20:24:19 +01:00
// a = $( a );// a == DOM element
// a = Piler.getSource( a );// a == Javascript event
2013-02-11 20:24:19 +01:00
Piler.Shared.page = a;
2013-02-11 20:24:19 +01:00
Piler.load_search_results();
},
/*
* reset search fields
*
2013-02-11 20:24:19 +01:00
* HTML: <input type="button" onclick="Piler.cancel()" value="Cancel">
* CSS: input.advsecondary[type="button"]{ height: 20px; width: 70px; }
*/
cancel:function( )//a )
{
Piler.log("[cancel]")//, a );
2013-02-11 20:24:19 +01:00
// a = $( a );// a == DOM element
// a = Piler.getSource( a );// a == Javascript event
$('#_search').val('');
2013-02-11 20:24:19 +01:00
$('#ref').val( '' );
Piler.Searches.Expert = {};
$('input#xfrom').val('');
$('input#xto').val('');
$('input#xsubject').val('');
$('input#xbody').val('');
$('input#xtag').val('');
$('input#xnote').val('');
2013-08-06 06:36:56 +02:00
$('input#xhas_attachment_doc')[0].checked = 0;
$('input#xhas_attachment_xls')[0].checked = 0;
$('input#xhas_attachment_pdf')[0].checked = 0;
$('input#xhas_attachment_image')[0].checked = 0;
$('input#xhas_attachment_any')[0].checked = 0;
2013-02-11 20:24:19 +01:00
$('input#date1').val('');
$('input#date2').val('');
Piler.Searches.Complex = {};
},
2013-08-06 06:36:56 +02:00
/*
* when clicked on the "any" attachment type, clear the other types
*/
clear_attachment_others: function()
{
$('input#xhas_attachment_doc')[0].checked = 0;
$('input#xhas_attachment_xls')[0].checked = 0;
$('input#xhas_attachment_pdf')[0].checked = 0;
$('input#xhas_attachment_image')[0].checked = 0;
},
/*
* when clicked on any of the named attachment types, clear the "any" type
*/
clear_attachment_any: function()
{
$('input#xhas_attachment_any')[0].checked = 0;
2013-08-06 06:36:56 +02:00
},
2013-02-11 20:24:19 +01:00
/*
* show a temporary message to the user
*/
show_message:function(id, msg, timeout)
{
msg = '<p>' + msg.replace("\n", "<br />") + '</p>';
2013-02-11 20:24:19 +01:00
Piler.log("[show_message]", id, msg);
$('#'+id).html(msg);
$('#'+id).show();
setTimeout(function() { $('#'+id).hide(); }, timeout*1000);
},
load_health:function()
{
Piler.log("[load_health]");
document.body.style.cursor = 'wait';
jQuery.ajax('/index.php?route=health/worker', { })
.done( function(a) {
$('#A1').html(a);
document.body.style.cursor = 'default';
2013-02-16 12:51:43 +01:00
//setInterval('Piler.load_health()', Piler.health_refresh * 1000);
2013-02-11 20:24:19 +01:00
})
.fail(function(a, b) { alert("Problem retrieving XML data:" + b) });
},
/*
* show a hint message for an autocomplete field on user/group editing
*/
toggle_hint:function(id, s, focus)
{
Piler.log("[toggle_hint]", id);
if(focus == 1){
if($('#' + id).val() == s) $('#' + id).val('');
}
else {
if($('#' + id).val() == '') $('#' + id).val(s);
}
},
2012-05-07 09:38:47 +02:00
2012-05-11 23:42:55 +02:00
2013-02-11 20:24:19 +01:00
/*
* assemble a space separated list of the selected email addresses of the given message
*/
2012-05-07 09:38:47 +02:00
2013-02-11 20:24:19 +01:00
restore_message_for_recipients:function(id, msgok, msgerr)
{
Piler.log("[restore_message_for_recipients]", id);
2012-05-07 09:38:47 +02:00
2014-09-17 11:24:40 +02:00
Piler.poor_mans_keepalive_for_dummy_browsers();
2013-02-11 20:24:19 +01:00
var z = $('#restorebox').children(), y = z.length, x;
var emails = '';
2012-05-07 09:38:47 +02:00
2013-02-11 20:24:19 +01:00
for ( ; --y >= 0 ; )
{
x = z[y];
2012-05-07 09:38:47 +02:00
2013-02-11 20:24:19 +01:00
if (x.id.substring(0, 5) == "rcpt_" )
{
if(document.getElementById(x.id).checked == 1){
if(emails) emails += ' ';
emails += x.id.substring(5, 1000);
}
2012-05-07 09:38:47 +02:00
}
2013-02-11 20:24:19 +01:00
}
2012-05-07 09:38:47 +02:00
2013-02-11 20:24:19 +01:00
if(emails) {
jQuery.ajax('index.php?route=message/restore', {
data: { rcpt: encodeURI(emails), id: id },
type: "POST"
})
.done( function(a) {})
.fail(function(a, b) { alert("Problem retrieving XML data:" + b) });
2012-05-07 09:38:47 +02:00
2013-02-11 20:24:19 +01:00
Piler.show_message('messagebox1', msgok, 0.85);
$('#restorebox').hide();
}
else {
Piler.show_message('messagebox1', msgerr, 0.85);
}
2012-05-11 23:42:55 +02:00
2013-02-11 20:24:19 +01:00
},
2012-05-11 23:42:55 +02:00
2013-11-16 15:34:30 +01:00
download_messages_real:function(idlist, url)
2013-02-11 20:24:19 +01:00
{
2013-09-30 16:40:01 +02:00
Piler.log("[download_messages_real]", idlist);
2012-05-11 23:42:55 +02:00
2013-02-11 20:24:19 +01:00
if(idlist) {
var form = document.createElement("form");
2012-05-11 23:42:55 +02:00
2013-02-11 20:24:19 +01:00
form.setAttribute("method", "post");
2013-11-16 15:34:30 +01:00
form.setAttribute("action", url);
2013-02-11 20:24:19 +01:00
form.setAttribute("name", "download");
2012-05-11 23:42:55 +02:00
2013-02-11 20:24:19 +01:00
var hiddenField = document.createElement("input");
2012-05-11 23:42:55 +02:00
2013-02-11 20:24:19 +01:00
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", "download");
hiddenField.setAttribute("value", "1");
form.appendChild(hiddenField);
2012-05-11 23:42:55 +02:00
2013-02-11 20:24:19 +01:00
hiddenField = document.createElement("input");
2012-05-11 23:42:55 +02:00
2013-02-11 20:24:19 +01:00
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", "idlist");
hiddenField.setAttribute("value", idlist);
form.appendChild(hiddenField);
2012-05-11 23:42:55 +02:00
2013-02-11 20:24:19 +01:00
document.body.appendChild(form);
form.submit();
2013-08-15 14:34:25 +02:00
document.body.removeChild(form);
2013-02-11 20:24:19 +01:00
}
},
2012-05-11 23:42:55 +02:00
2013-09-30 16:40:01 +02:00
download_messages:function()
{
var idlist = Piler.get_selected_messages_list();
2013-11-16 15:34:30 +01:00
Piler.download_messages_real(idlist, Piler.bulkrestore_url);
2013-09-30 16:40:01 +02:00
},
download_all_search_hits:function()
{
2013-11-16 20:23:15 +01:00
Piler.log("[download_all_search_hits]");
2013-09-30 16:40:01 +02:00
2013-11-16 20:23:15 +01:00
jQuery.ajax('/index.php?route=message/dl', {
2013-09-30 16:40:01 +02:00
type: "POST"
})
2013-11-16 20:23:15 +01:00
.done( function( a )
2013-09-30 16:40:01 +02:00
{
2013-11-16 15:34:30 +01:00
Piler.download_messages_real(a, Piler.bulkrestore_url);
2013-09-30 16:40:01 +02:00
})
2013-11-16 20:23:15 +01:00
.fail(function( a, b )
2013-09-30 16:40:01 +02:00
{
alert("Problem retrieving XML data:" + b)
});
},
2013-11-16 15:34:30 +01:00
download_selected_as_pdf:function()
{
2013-11-16 20:23:15 +01:00
Piler.log("[download_selected_as_pdf]");
2013-11-16 15:34:30 +01:00
var idlist = Piler.get_selected_messages_list();
if(idlist) {
Piler.download_messages_real(idlist, Piler.bulkpdf_url);
}
},
2013-02-11 20:24:19 +01:00
auditexpert:function()
{
Piler.log("[auditexpert]");
2012-05-11 23:42:55 +02:00
2013-02-11 20:24:19 +01:00
Piler.search = 'Expert';
2012-05-11 23:42:55 +02:00
2013-02-11 20:24:19 +01:00
Piler.Shared.page = 0;
Piler.Shared.type = 'audit';
2012-05-11 23:42:55 +02:00
2013-02-11 20:24:19 +01:00
Piler.Searches.Expert = {
search : $('input#_search').val().trim(),
searchtype : 'expert'
}
2012-05-11 23:42:55 +02:00
2013-02-11 20:24:19 +01:00
Piler.load_search_results();
},
2012-05-11 23:42:55 +02:00
2013-02-11 20:24:19 +01:00
/*
* add shortcuts on the search page
*/
2012-05-11 23:42:55 +02:00
2013-02-11 20:24:19 +01:00
add_shortcuts:function()
{
Piler.log("[add_shortcuts]");
2012-05-07 09:38:47 +02:00
2013-02-11 20:24:19 +01:00
$(document).keypress(function(e){
if(e.which == 13){
$("#button_search").click();
}
2012-03-10 14:52:50 +01:00
2013-02-11 20:24:19 +01:00
// 37: left, 38: up, 39: right, 40: down
2012-06-27 11:17:23 +02:00
2013-02-11 20:24:19 +01:00
if(e.keyCode == 38){
Piler.show_prev_message();
}
2012-06-27 11:17:23 +02:00
2013-02-11 20:24:19 +01:00
if(e.keyCode == 40){
Piler.show_next_message();
}
2012-06-27 11:17:23 +02:00
2013-02-11 20:24:19 +01:00
});
2012-06-27 11:17:23 +02:00
2013-03-31 14:50:21 +02:00
},
reload_piler:function()
{
Piler.log("[reload_piler]");
jQuery.ajax('index.php?route=policy/apply', { cache: true })
.done( function(a) {
$('#applyChangesOutput').html(a);
})
.fail(function(a, b) { alert("Problem retrieving XML data:" + b) });
},
2013-03-31 14:50:21 +02:00
assemble_folder_restrictions: function()
{
Piler.log("[assemble_folder_restrictions]");
Piler.folders = '';
Piler.extra_folders = '';
a = document.getElementById('folders');
if(!a) { return false; }
childNodeArray = a.getElementsByTagName('*');
if(childNodeArray) {
for(i=0; i<childNodeArray.length; i++) {
b = childNodeArray[i];
if(b.name && b.name.substring(0, 7) == 'folder_' && b.checked) {
Piler.folders = Piler.folders + " " + b.name.substring(7);
}
if(b.name && b.name.substring(0, 13) == 'extra_folder_' && b.checked) {
Piler.extra_folders = Piler.extra_folders + " " + b.name.substring(13);
}
}
}
if(Piler.folders) {
Piler.folders = Piler.folders.substring(1);
}
if(Piler.extra_folders) {
Piler.extra_folders = Piler.extra_folders.substring(1);
}
Piler.log("[folder/extra_folders]", Piler.folders, Piler.extra_folders);
},
copy_message_to_folder: function(folder_id, id, msg)
{
Piler.log("[copy_message_to_folder]", folder_id, id);
if(id <= 0) { return 0; }
var folder_copy_url = '<?php print SITE_URL; ?>/index.php?route=folder/copy'
2014-09-17 11:24:40 +02:00
Piler.poor_mans_keepalive_for_dummy_browsers();
2013-03-31 14:50:21 +02:00
jQuery.ajax('index.php?route=folder/copy', {
data: { folder_id: folder_id, id: id },
type: "POST"
})
.done( function(a) {})
.fail(function(a, b) { alert("Problem retrieving XML data:" + b) });
Piler.show_message('messagebox1', msg, 0.85);
2013-03-31 14:50:21 +02:00
Piler.current_message_id = 0;
},
open_folder: function(id)
{
$('#fldr_' + id).show();
$('#fldr_collapse_' + id).show();
$('#fldr_open_' + id).hide();
},
close_folder: function(id)
{
$('#fldr_' + id).hide();
$('#fldr_collapse_' + id).hide();
$('#fldr_open_' + id).show();
2013-07-08 11:31:17 +02:00
},
2013-07-10 14:11:27 +02:00
stop_propagation: function(event) {
Piler.log("[stop_propagation]");
try {
event.stopPropagation();
}
catch ( e ) {
Piler.log("[stop_propagation]", e );
}
},
2013-07-08 11:31:17 +02:00
test_ldap_connection:function()
{
Piler.log("[test_ldap_connection]");
2013-07-08 11:31:17 +02:00
jQuery.ajax('index.php?route=ldap/test', {
data: {
description: $('#description').val(),
ldap_host: $('#ldap_host').val(),
ldap_base_dn: $('#ldap_base_dn').val(),
ldap_bind_dn: $('#ldap_bind_dn').val(),
ldap_bind_pw: $('#ldap_bind_pw').val()
},
type: "POST"
})
.done( function(a) {
$('#LDAPTEST').html(a);
})
.fail(function(a, b) { alert("Problem retrieving XML data:" + b) });
},
2013-08-23 13:02:51 +02:00
test_pop3_connection:function()
{
Piler.log("[test_pop3_connection]");
jQuery.ajax('index.php?route=import/test', {
data: {
type: $('#type').val(),
server: $('#server').val(),
username: $('#username').val(),
password: $('#password').val()
},
type: "POST"
})
.done( function(a) {
$('#LDAPTEST').html(a);
})
.fail(function(a, b) { alert("Problem retrieving XML data:" + b) });
},
2013-07-08 11:31:17 +02:00
clear_ldap_test: function()
{
$('#LDAPTEST').html('');
2013-07-25 11:56:52 +02:00
},
2013-01-05 16:42:36 +01:00
2013-07-25 11:56:52 +02:00
reload_page: function()
{
location.reload(true);
2013-08-01 22:28:42 +02:00
},
go_to_default_page: function()
{
document.location.href = 'search.php';
},
2013-08-09 22:11:16 +02:00
change_box_colour: function(srcid, dstid)
2013-08-01 22:28:42 +02:00
{
2013-08-09 22:11:16 +02:00
var colour = $('#' + srcid).val();
$('#' + dstid).css('background', colour);
},
new_qr: function()
{
Piler.log("[new_qr]");
document.body.style.cursor = 'wait';
2013-10-17 10:11:17 +02:00
jQuery.ajax('qr.php?refresh=1', { cache: false })
.done( function(a) {
$('#QR').html(a);
document.body.style.cursor = 'default';
})
.fail(function(a, b) { alert("Problem retrieving XML data:" + b) });
},
toggle_ga: function()
{
var ga = 0;
if(document.getElementById('ga_enabled').checked == 1){ ga = 1; }
Piler.log("[toggle GA]", ga);
2013-10-17 10:11:17 +02:00
jQuery.ajax('qr.php?toggle=' + ga, { cache: false })
.done( function(a) {
})
.fail(function(a, b) { alert("Problem retrieving XML data:" + b) });
2013-10-17 10:11:17 +02:00
},
2013-01-05 16:42:36 +01:00
2014-01-15 14:47:30 +01:00
fix_ldap_display: function()
{
if($('#ldap_type').val() == '<?php print LDAP_TYPE_GENERIC; ?>') {
$('#ldap_mail_attr_id').show();
$('#ldap_account_objectclass_id').show();
$('#ldap_distributionlist_attr_id').show();
$('#ldap_distributionlist_objectclass_id').show();
}
else {
$('#ldap_mail_attr').val('');
$('#ldap_account_objectclass').val('');
$('#ldap_distributionlist_attr').val('');
$('#ldap_distributionlist_objectclass').val('');
$('#ldap_mail_attr_id').hide();
$('#ldap_account_objectclass_id').hide();
$('#ldap_distributionlist_attr_id').hide();
$('#ldap_distributionlist_objectclass_id').hide();
}
},
2013-10-17 10:11:17 +02:00
fix_page: function()
{
<?php if(OUTLOOK == 1) { ?>
$('#mainscreen').css('top', '60px');
<?php } ?>
2013-11-15 22:02:44 +01:00
},
print_div: function(divID) {
var divElements = document.getElementById(divID).innerHTML;
var oldPage = document.body.innerHTML;
document.body.innerHTML = "<html><head><title></title></head><body>" + divElements + "</body></html>";
window.print();
document.body.innerHTML = oldPage;
2014-09-17 11:24:40 +02:00
},
poor_mans_keepalive_for_dummy_browsers: function()
{
2014-09-17 15:51:35 +02:00
<?php if(ENABLE_SSO_LOGIN == 1) { ?>
2014-09-17 11:24:40 +02:00
2014-09-17 15:51:35 +02:00
// MSIE 11 and Outlook 2013 match this condition
2014-09-17 11:24:40 +02:00
2014-09-17 15:51:35 +02:00
if(Object.hasOwnProperty.call(window, "ActiveXObject") && !window.ActiveXObject) {
Piler.log("[poor_mans_keepalive_for_dummy_browsers]");
jQuery.ajax('/ok.txt', { async: false })
.done( function(a) { } )
.fail(function(a, b) { alert("Problem retrieving XML data:" + b) });
}
2014-09-17 11:24:40 +02:00
<?php } ?>
2013-10-17 10:11:17 +02:00
}
2013-07-08 11:31:17 +02:00
2013-11-15 22:02:44 +01:00
2013-01-05 16:42:36 +01:00
}
2013-02-11 20:24:19 +01:00
var split = new rcube_webmail();
2013-02-11 20:24:19 +01:00
$.datepicker.setDefaults($.datepicker.regional[Piler.piler_ui_lang]);
2012-02-08 23:14:28 +01:00
$(function() {
$("#s_piler_email").autocomplete({
2013-02-11 20:24:19 +01:00
source: '/index.php?route=group/email&',
minLength: 2,
select: function( event, ui ) {
if(ui.item){
var prefix = '\n';
2013-02-11 20:24:19 +01:00
if($('#email').val() == '') prefix = '';
$('#email').val($('#email').val() + prefix + ui.item.value);
}
ui.item.value = '';
}
});
2013-01-05 16:42:36 +01:00
$("#s_piler_domain").autocomplete({
2013-02-11 20:24:19 +01:00
source: '/index.php?route=domain/domains&',
2013-01-05 16:42:36 +01:00
minLength: 2,
select: function( event, ui ) {
if(ui.item){
var prefix = '\n';
2013-02-11 20:24:19 +01:00
if($('#domains').val() == '') prefix = '';
2013-01-05 16:42:36 +01:00
$('#domains').val($('#domains').val() + prefix + ui.item.value);
}
ui.item.value = '';
}
});
$("#s_piler_group").autocomplete({
2013-02-11 20:24:19 +01:00
source: '/index.php?route=group/group&',
minLength: 2,
select: function( event, ui ) {
if(ui.item){
var prefix = '\n';
2013-02-11 20:24:19 +01:00
if($('#group').val() == '') prefix = '';
$('#group').val($('#group').val() + prefix + ui.item.value);
}
ui.item.value = '';
}
});
2012-09-06 15:27:20 +02:00
$("#s_piler_folder").autocomplete({
2013-02-11 20:24:19 +01:00
source: '/index.php?route=folder/folder&',
2012-09-06 15:27:20 +02:00
minLength: 2,
select: function( event, ui ) {
if(ui.item){
var prefix = '\n';
2013-02-11 20:24:19 +01:00
if($('#folder').val() == '') prefix = '';
2012-09-06 15:27:20 +02:00
$('#folder').val($('#folder').val() + prefix + ui.item.value);
}
ui.item.value = '';
}
});
2012-09-15 15:30:35 +02:00
2013-02-11 20:24:19 +01:00
$("ul.dropdown li").hover(function(){
2013-02-11 20:24:19 +01:00
$(this).addClass("hover");
$('ul:first',this).css('visibility', 'visible');
2013-02-11 20:24:19 +01:00
}, function(){
2013-02-11 20:24:19 +01:00
$(this).removeClass("hover");
$('ul:first',this).css('visibility', 'hidden');
2013-02-11 20:24:19 +01:00
});
$("#date1").datepicker( {dateFormat: '<?php print JQUERY_DATE_FORMAT; ?>' });
$("#date2").datepicker( {dateFormat: '<?php print JQUERY_DATE_FORMAT; ?>' });
2013-02-11 20:24:19 +01:00
});
2013-08-14 23:40:52 +02:00
// modal additions
2013-08-14 23:40:52 +02:00
$(document).on("click", ".confirm-delete", function (e) {
e.preventDefault();
var id = $(this).data('id'),
name = $(this).data('name'),
url = $(".modal-footer #id").attr("href");
2013-08-14 23:40:52 +02:00
//set id
url = UpdateQueryString('id',id,url);
//set name
url = UpdateQueryString('name',encodeURIComponent(name),url);
//set confirmation
url = UpdateQueryString('confirmed',1,url);
//set href
$(".modal-footer #id").attr("href",url);
//set display text
$(".modal-body #name").html( name );
//finally, display the confirm modal box
$('#deleteconfirm-modal').modal('show');
});
function UpdateQueryString(key, value, url) { // from http://stackoverflow.com/questions/5999118/add-or-update-query-string-parameter/11654596#11654596
if (!url) url = window.location.href;
var re = new RegExp("([?|&])" + key + "=.*?(&|#|$)(.*)", "gi");
if (re.test(url)) {
if (typeof value !== 'undefined' && value !== null)
return url.replace(re, '$1' + key + "=" + value + '$2$3');
else {
return url.replace(re, '$1$3').replace(/(&|\?)$/, '');
}
}
else {
if (typeof value !== 'undefined' && value !== null) {
var separator = url.indexOf('?') !== -1 ? '&' : '?',
hash = url.split('#');
url = hash[0] + separator + key + '=' + value;
if (hash[1]) url += '#' + hash[1];
return url;
}
else
return url;
}
}