summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
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
commitdf6ea17f4b8bb1d45fe480044af80bd19742bf80 (patch)
tree64d15df919343bcd860d2cb818b353d1ef019e18 /ishtar_common
parent4473e91231794ba9082795df9441d49e461b10db (diff)
downloadIshtar-df6ea17f4b8bb1d45fe480044af80bd19742bf80.tar.bz2
Ishtar-df6ea17f4b8bb1d45fe480044af80bd19742bf80.zip
WIP: ajaxify shortcut menu - 2
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/static/js/ishtar.js90
-rw-r--r--ishtar_common/static/media/style.css4
-rw-r--r--ishtar_common/templates/base.html10
-rw-r--r--ishtar_common/templates/ishtar/blocks/shortcut_menu.html2
-rw-r--r--ishtar_common/views.py35
5 files changed, 97 insertions, 44 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;
}
diff --git a/ishtar_common/templates/base.html b/ishtar_common/templates/base.html
index a0cf154ac..cd7b00457 100644
--- a/ishtar_common/templates/base.html
+++ b/ishtar_common/templates/base.html
@@ -32,6 +32,14 @@
{% endblock %}
<script type='text/javascript'>
var shortcut_url = '{% url "shortcut-menu" %}';
+ var get_file_url = '{% url "get-file-shortcut" %}';
+ var get_own_file_url = '{% url "get-own-file-shortcut" %}';
+ var get_operation_url = '{% url "get-operation-shortcut" %}';
+ var get_own_operation_url = '{% url "get-own-operation-shortcut" %}';
+ var get_contextrecord_url = '{% url "get-contextrecord-shortcut" %}';
+ var get_own_contextrecord_url = '{% url "get-own-contextrecord-shortcut" %}';
+ var get_find_url = '{% url "get-find-shortcut" %}';
+ var get_own_find_url = '{% url "get-own-find-shortcut" %}';
var activate_all_search_msg = "{% trans 'Searches in the shortcut menu deals with all items.' %}";
var activate_own_search_msg = "{% trans 'Searches in the shortcut menu deals with only your items.' %}";
</script>
@@ -52,7 +60,7 @@
{% csrf_token %}
<label for='language_selector'>{% trans "Lang" %}{% trans ":"%} </label>
<select name="language" id='language_selector'>
- <option value="">-------</option>
+ <option value="">----------</option>
{% for lang in LANGUAGES %}
<option value="{{ lang.0 }}"{% ifequal LANGUAGE_CODE lang.0 %} selected='selected'{% endifequal %}>{{ lang.1 }}</option>
{% endfor %}
diff --git a/ishtar_common/templates/ishtar/blocks/shortcut_menu.html b/ishtar_common/templates/ishtar/blocks/shortcut_menu.html
index 520218083..8a0f694ae 100644
--- a/ishtar_common/templates/ishtar/blocks/shortcut_menu.html
+++ b/ishtar_common/templates/ishtar/blocks/shortcut_menu.html
@@ -16,7 +16,7 @@
<td><label for="current_{{model_name}}">{{lbl}}</label></td>
<td>
<select class='{{main_cls}} chosen-select' id='current_{{model_name}}'>
- <option class='normal' value=''>--</option>
+ <option class='normal' value=''>----------</option>
{% for val, label, selected, cls in items %}<option{% if cls %} class='{{cls}}'{% endif %} value='{{val}}'{% if selected %} selected="selected"{% endif %}>{% ifequal cls 'basket' %}&#xf291; {% endifequal %}{% ifequal cls 'green' %}&#xf058; {% endifequal %}{% ifequal cls 'orange' %}&#xf06a; {% endifequal %}{% ifequal cls 'red' %}&#xf071; {% endifequal %}{{label}}</option>
{% endfor %}</select>
</td>{% with 'show-'|add:model_name as model_url%}
diff --git a/ishtar_common/views.py b/ishtar_common/views.py
index eb557bb51..27b192e74 100644
--- a/ishtar_common/views.py
+++ b/ishtar_common/views.py
@@ -55,6 +55,7 @@ from xhtml2odt import xhtml2odt
from menus import menu
from archaeological_files.models import File
+from archaeological_operations.models import Operation
from archaeological_context_records.models import ContextRecord
from archaeological_finds.models import Find
@@ -199,11 +200,6 @@ def get_autocomplete_generic(model, extra={'available': True}):
def shortcut_menu(request):
- from archaeological_operations.models import Operation
- from archaeological_files.models import File
- from archaeological_context_records.models import ContextRecord
- from archaeological_finds.models import Find
-
profile = get_current_profile()
CURRENT_ITEMS = []
if profile.files:
@@ -230,8 +226,8 @@ def shortcut_menu(request):
if selected:
cls = item.get_short_menu_class()
new_selected_item = item
- items.append((pk, shortify(unicode(item), 60),
- selected, item.get_short_menu_class()))
+ items.append((pk, shortify(unicode(item), 60),
+ selected, item.get_short_menu_class()))
# selected is not in owns - add it to the list
if not new_selected_item and current:
try:
@@ -241,18 +237,13 @@ def shortcut_menu(request):
True, item.get_short_menu_class()))
except (model.DoesNotExist, ValueError):
pass
- if items:
- dct['current_menu'].append((lbl, model_name, cls, items))
+ dct['current_menu'].append((lbl, model_name, cls, items))
current_selected_item = new_selected_item
return render_to_response('ishtar/blocks/shortcut_menu.html', dct,
context_instance=RequestContext(request))
def get_current_items(request):
- from archaeological_files.models import File
- from archaeological_operations.models import Operation
- from archaeological_context_records.models import ContextRecord
- from archaeological_finds.models import Find
currents = {}
for key, model in (('file', File),
('operation', Operation),
@@ -706,6 +697,22 @@ def get_item(model, func_name, default_name, extra_request_keys=[],
for and_req in and_reqs:
query = query & and_req
+ # manage hierarchic in shortcut menu
+ if full == 'shortcut':
+ ASSOCIATED_ITEMS = {
+ Operation: (File, 'associated_file__pk'),
+ ContextRecord: (Operation, 'operation__pk'),
+ Find: (ContextRecord, 'base_finds__context_record__pk'),
+ }
+ if model in ASSOCIATED_ITEMS:
+ upper_model, upper_key = ASSOCIATED_ITEMS[model]
+ model_name = upper_model.SLUG
+ current = model_name in request.session \
+ and request.session[model_name]
+ if current:
+ dct = {upper_key: current}
+ query = query & Q(**dct)
+
items = model.objects.filter(query).distinct()
# print(items.query)
q = request_items.get('sidx')
@@ -731,7 +738,7 @@ def get_item(model, func_name, default_name, extra_request_keys=[],
for idx, col in enumerate(table_cols):
if col in model.CONTEXTUAL_TABLE_COLS[contxt]:
table_cols[idx] = model.CONTEXTUAL_TABLE_COLS[contxt][col]
- if full == 'cached':
+ if full == 'shortcut':
table_cols = ['cached_label']
# manage sort tables