diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-09-22 19:10:49 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-09-24 16:48:04 +0200 |
commit | df6ea17f4b8bb1d45fe480044af80bd19742bf80 (patch) | |
tree | 64d15df919343bcd860d2cb818b353d1ef019e18 /ishtar_common/static | |
parent | 4473e91231794ba9082795df9441d49e461b10db (diff) | |
download | Ishtar-df6ea17f4b8bb1d45fe480044af80bd19742bf80.tar.bz2 Ishtar-df6ea17f4b8bb1d45fe480044af80bd19742bf80.zip |
WIP: ajaxify shortcut menu - 2
Diffstat (limited to 'ishtar_common/static')
-rw-r--r-- | ishtar_common/static/js/ishtar.js | 90 | ||||
-rw-r--r-- | ishtar_common/static/media/style.css | 4 |
2 files changed, 66 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; } diff --git a/ishtar_common/static/media/style.css b/ishtar_common/static/media/style.css index 2ef0ab8ac..d74e0aaa2 100644 --- a/ishtar_common/static/media/style.css +++ b/ishtar_common/static/media/style.css @@ -60,6 +60,10 @@ a.add-button, font-family: 'FontAwesome', Arial, Helvetica, sans-serif; } +#context_menu .chosen-select{ + width: 400px; +} + #context_menu option.basket{ color:#000; } |