diff options
Diffstat (limited to 'ishtar_common/static/js/ishtar.js')
-rw-r--r-- | ishtar_common/static/js/ishtar.js | 90 |
1 files changed, 62 insertions, 28 deletions
diff --git a/ishtar_common/static/js/ishtar.js b/ishtar_common/static/js/ishtar.js index 70b056c63..393603b6c 100644 --- a/ishtar_common/static/js/ishtar.js +++ b/ishtar_common/static/js/ishtar.js @@ -23,8 +23,6 @@ beforeSend: function(xhr, settings) { } }}); -var shortcut_url = ''; - function manage_async_link(event){ event.preventDefault(); var url = $(this).attr('href'); @@ -38,6 +36,24 @@ function manage_async_link(event){ function get_next_table_id(){} function get_previous_table_id(){} +var shortcut_url = ''; +var get_file_url = '/get-file-shortcut/'; +var get_own_file_url = '/get-file-shortcut/own/'; +var get_operation_url = '/get-operation-shortcut/'; +var get_own_operation_url = '/get-operation-shortcut/own/'; +var get_contextrecord_url = '/get-contextrecord-shortcut/'; +var get_own_contextrecord_url = '/get-contextrecord-shortcut/own/'; +var get_find_url = '/get-find-shortcut/'; +var get_own_find_url = '/get-find-shortcut/own/'; +var shortcut_get_attr = '?submited=1&page=1&rows=10&cached_label='; + +var current_file_change = function(){ + $.post('/' + url_path + 'update-current-item/', + {item:'file', value:$("#current_file").val()}, + load_shortcut_menu + ); +}; + var current_operation_change = function(){ $.post('/' + url_path + 'update-current-item/', {item:'operation', value:$("#current_operation").val()}, @@ -45,30 +61,45 @@ var current_operation_change = function(){ ); }; +var current_contextrecord_change = function(){ + $.post('/' + url_path + 'update-current-item/', + {item:'contextrecord', value:$("#current_contextrecord").val()}, + load_shortcut_menu + ); +}; + +var current_find_change = function(){ + $.post('/' + url_path + 'update-current-item/', + {item:'find', value:$("#current_find").val()}, + load_shortcut_menu + ); +}; + +function init_shortcut_fields(){ + var is_own = $('.activate_all_search').hasClass('disabled'); + var file_url = get_file_url; + if (is_own) file_url = get_own_file_url; + chosen_ajaxify("current_file", file_url + shortcut_get_attr, + current_file_change); + var operation_url = get_operation_url; + if (is_own) operation_url = get_own_operation_url; + chosen_ajaxify("current_operation", operation_url + shortcut_get_attr, + current_operation_change); + var contextrecord_url = get_contextrecord_url; + if (is_own) contextrecord_url = get_own_contextrecord_url; + chosen_ajaxify("current_contextrecord", contextrecord_url + shortcut_get_attr, + current_contextrecord_change); + var find_url = get_find_url; + if (is_own) find_url = get_own_find_url; + chosen_ajaxify("current_find", find_url + shortcut_get_attr, + current_find_change); +} + function init_shortcut_menu(html){ $("#progress").hide(); $("#context_menu").html(html); $(".chosen-select").chosen(); - chosen_ajaxify("current_operation", '/get-operation-cached/?cached_label=', - current_operation_change); - $("#current_file").change(function(){ - $.post('/' + url_path + 'update-current-item/', - {item:'file', value:$("#current_file").val()}, - load_shortcut_menu - ); - }); - $("#current_contextrecord").change(function(){ - $.post('/' + url_path + 'update-current-item/', - {item:'contextrecord', value:$("#current_contextrecord").val()}, - load_shortcut_menu - ); - }); - $("#current_find").change(function(){ - $.post('/' + url_path + 'update-current-item/', - {item:'find', value:$("#current_find").val()}, - load_shortcut_menu - ); - }); + init_shortcut_fields(); } function display_info(msg){ @@ -291,22 +322,23 @@ function chosen_ajaxify(id, ajax_url, current_change_callback){ url: ajax_url + keyword, dataType: "json", success: function(response){ - $('#'+id).append('<option value="">--</option>'); - $.map(response['rows'], function(item){ - $('#'+id).append('<option value="' + item['id'] + '">' + item['cached_label'] + '</option>'); - }); + $('#'+id).append('<option value="">----------</option>'); + if ('rows' in response){ + $.map(response['rows'], function(item){ + $('#'+id).append('<option value="' + item['id'] + '">' + item['cached_label'] + '</option>'); + }); + } $("#"+id).trigger("chosen:updated"); $('div#' + id + '_chosen .chosen-search input').val(keyword); $('div#' + id + '_chosen').removeClass('chosen-container-single-nosearch'); $('div#' + id + '_chosen .chosen-search input').removeAttr('readonly'); $('div#' + id + '_chosen .chosen-search input').focus(); - /* $('div#' + id + '_chosen .active-result').each(function(){ var html = $('div#' + id + '_chosen ul.chosen-results').html(); $('div#' + id + '_chosen ul.chosen-results').html(html.replace(keyword_pattern, function(matched){ return '<em>' + matched + '</em>'; })); - });*/ + }); $("#" + id).change(current_change_callback); } }); @@ -321,6 +353,7 @@ var activate_own_search_msg = "Searches in the shortcut menu deals with only you function activate_all_search(){ $('.activate_all_search').removeClass('disabled'); $('.activate_own_search').addClass('disabled'); + init_shortcut_fields(); display_info(activate_all_search_msg); return false; } @@ -328,6 +361,7 @@ function activate_all_search(){ function activate_own_search(){ $('.activate_own_search').removeClass('disabled'); $('.activate_all_search').addClass('disabled'); + init_shortcut_fields(); display_info(activate_own_search_msg); return false; } |