diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-09-24 16:13:16 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-09-24 16:48:04 +0200 |
commit | f60470064e73bf874c96db8f4217c4c8ba603c39 (patch) | |
tree | 354a5f8d9b9c2b226c7fae104a4f799d6a8fceef /ishtar_common/static | |
parent | df6ea17f4b8bb1d45fe480044af80bd19742bf80 (diff) | |
download | Ishtar-f60470064e73bf874c96db8f4217c4c8ba603c39.tar.bz2 Ishtar-f60470064e73bf874c96db8f4217c4c8ba603c39.zip |
WIP: ajaxify shortcut menu - 3
Diffstat (limited to 'ishtar_common/static')
-rw-r--r-- | ishtar_common/static/js/ishtar.js | 144 | ||||
-rw-r--r-- | ishtar_common/static/media/style.css | 10 |
2 files changed, 50 insertions, 104 deletions
diff --git a/ishtar_common/static/js/ishtar.js b/ishtar_common/static/js/ishtar.js index 393603b6c..9021dc4f5 100644 --- a/ishtar_common/static/js/ishtar.js +++ b/ishtar_common/static/js/ishtar.js @@ -37,62 +37,43 @@ 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 activate_all_search_url = '/activate-all-search/'; +var activate_own_search_url = '/activate-own-search/'; -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()}, - load_shortcut_menu - ); -}; - -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); + $('#id_file-shortcut').change(function(){ + $("#id_select_file-shortcut").attr( + 'title', $('#id_select_file-shortcut').val()); + $.post('/' + url_path + 'update-current-item/', + {item: "file", value:$("#id_file-shortcut").val()}, + load_shortcut_menu + ); + }); + $('#id_operation-shortcut').change(function(){ + $("#id_select_operation-shortcut").attr( + 'title', $('#id_select_operation-shortcut').val()); + $.post('/' + url_path + 'update-current-item/', + {item: "operation", value:$("#id_operation-shortcut").val()}, + load_shortcut_menu + ); + }); + $('#id_contextrecord-shortcut').change(function(){ + $("#id_select_contextrecord-shortcut").attr( + 'title', $('#id_select_contextrecord-shortcut').val()); + $.post('/' + url_path + 'update-current-item/', + {item: "contextrecord", value:$("#id_contextrecord-shortcut").val()}, + load_shortcut_menu + ); + }); + $('#id_find-shortcut').change(function(){ + $("#id_select_find-shortcut").attr( + 'title', $('#id_select_find-shortcut').val()); + $.post('/' + url_path + 'update-current-item/', + {item: "find", value:$("#id_find-shortcut").val()}, + load_shortcut_menu + ); + }); } function init_shortcut_menu(html){ @@ -225,7 +206,7 @@ function load_window(url, speed, on_success){ } function load_current_window(url, model_name){ - var id = $("#current_" + model_name).val(); + var id = $("#id_" + model_name + "-shortcut").val(); if (!id) return; url = url.split('/'); url[url.length - 1] = id; @@ -302,66 +283,23 @@ function show_hide_flex(id){ } } -var delay = (function(){ - var timer = 0; - return function(callback, ms){ - clearTimeout (timer); - timer = setTimeout(callback, ms); - }; -})(); - - -function chosen_ajaxify(id, ajax_url, current_change_callback){ - $('div#' + id + '_chosen .chosen-search input').keyup(function(){ - var keyword = $('div#' + id + '_chosen .chosen-search input').val(); - var keyword_pattern = new RegExp(keyword, 'gi'); - $('div#' + id + '_chosen ul.chosen-results').empty(); - $("#"+id).empty(); - delay(function(){ - $.ajax({ - url: ajax_url + keyword, - dataType: "json", - success: function(response){ - $('#'+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); - } - }); - }, 1000); - }); -} - - var activate_all_search_msg = "Searches in the shortcut menu deals with all items."; var activate_own_search_msg = "Searches in the shortcut menu deals with only your items."; function activate_all_search(){ $('.activate_all_search').removeClass('disabled'); $('.activate_own_search').addClass('disabled'); - init_shortcut_fields(); - display_info(activate_all_search_msg); + $.get(activate_all_search_url, function(data) { + display_info(activate_all_search_msg); + }); return false; } function activate_own_search(){ $('.activate_own_search').removeClass('disabled'); $('.activate_all_search').addClass('disabled'); - init_shortcut_fields(); - display_info(activate_own_search_msg); + $.get(activate_own_search_url, function(data) { + 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 d74e0aaa2..fff2fad78 100644 --- a/ishtar_common/static/media/style.css +++ b/ishtar_common/static/media/style.css @@ -29,10 +29,16 @@ a, a.remove { color:#D14; } +span.disabled, a.disabled { color:#ccc; } +span.disabled:hover, +a.disabled:hover { + color:#DB5C7C; +} + .badge, a.add-button, #reset_wizards, @@ -812,7 +818,9 @@ table.confirm tr.spacer td:last-child{ /* jquery widget customizations */ .ui-autocomplete{ - font-size:0.7em + font-size:0.7em; + z-index:10000 !important; + width:350px; } .ui-autocomplete-loading { |