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 | |
| parent | 4473e91231794ba9082795df9441d49e461b10db (diff) | |
| download | Ishtar-df6ea17f4b8bb1d45fe480044af80bd19742bf80.tar.bz2 Ishtar-df6ea17f4b8bb1d45fe480044af80bd19742bf80.zip | |
WIP: ajaxify shortcut menu - 2
| -rw-r--r-- | archaeological_context_records/urls.py | 6 | ||||
| -rw-r--r-- | archaeological_context_records/views.py | 1 | ||||
| -rw-r--r-- | archaeological_files/urls.py | 6 | ||||
| -rw-r--r-- | archaeological_files/views.py | 1 | ||||
| -rw-r--r-- | archaeological_finds/urls.py | 6 | ||||
| -rw-r--r-- | archaeological_finds/views.py | 1 | ||||
| -rw-r--r-- | archaeological_operations/urls.py | 16 | ||||
| -rw-r--r-- | ishtar_common/static/js/ishtar.js | 90 | ||||
| -rw-r--r-- | ishtar_common/static/media/style.css | 4 | ||||
| -rw-r--r-- | ishtar_common/templates/base.html | 10 | ||||
| -rw-r--r-- | ishtar_common/templates/ishtar/blocks/shortcut_menu.html | 2 | ||||
| -rw-r--r-- | ishtar_common/views.py | 35 | 
12 files changed, 126 insertions, 52 deletions
| diff --git a/archaeological_context_records/urls.py b/archaeological_context_records/urls.py index 8e218102d..368fd6d98 100644 --- a/archaeological_context_records/urls.py +++ b/archaeological_context_records/urls.py @@ -89,6 +89,12 @@ urlpatterns += patterns(      url(r'get-contextrecord-full/(?P<type>.+)?$',          'get_contextrecord', name='get-contextrecord-full',          kwargs={'full': True}), +    url(r'get-contextrecord-shortcut/own/(?P<type>.+)?$', +        'get_contextrecord', name='get-own-contextrecord-shortcut', +        kwargs={'full': 'shortcut', 'force_own': True}), +    url(r'get-contextrecord-shortcut/(?P<type>.+)?$', +        'get_contextrecord', name='get-contextrecord-shortcut', +        kwargs={'full': 'shortcut'}),      url(r'show-contextrecordsource(?:/(?P<pk>.+))?/(?P<type>.+)?$',          'show_contextrecordsource', name=models.ContextRecordSource.SHOW_URL),      url(r'get-contexrecordsource/(?P<type>.+)?$', diff --git a/archaeological_context_records/views.py b/archaeological_context_records/views.py index 5c8bb63cc..bc95473e6 100644 --- a/archaeological_context_records/views.py +++ b/archaeological_context_records/views.py @@ -46,6 +46,7 @@ contextrecord_extra_keys = {      'parcel_2': 'operation__parcels__public_domain',      'label': 'label__icontains',      'archaeological_sites': 'operation__archaeological_sites__pk', +    'cached_label': 'cached_label__icontains',  } diff --git a/archaeological_files/urls.py b/archaeological_files/urls.py index c6b932fec..914872a1f 100644 --- a/archaeological_files/urls.py +++ b/archaeological_files/urls.py @@ -75,6 +75,12 @@ urlpatterns += patterns(          name='get-file'),      url(r'get-file-full/(?P<type>.+)?$', 'get_file',          name='get-file-full', kwargs={'full': True}), +    url(r'get-file-shortcut/own/(?P<type>.+)?$', +        'get_file', name='get-own-file-shortcut', +        kwargs={'full': 'shortcut', 'force_own': True}), +    url(r'get-file-shortcut/(?P<type>.+)?$', +        'get_file', name='get-file-shortcut', +        kwargs={'full': 'shortcut'}),      url(r'get-administrativeactfile/(?P<type>.+)?$',          'get_administrativeactfile', name='get-administrativeactfile'),      url(r'show-file(?:/(?P<pk>.+))?/(?P<type>.+)?$', 'show_file', diff --git a/archaeological_files/views.py b/archaeological_files/views.py index e457c2ce7..a8053214f 100644 --- a/archaeological_files/views.py +++ b/archaeological_files/views.py @@ -91,6 +91,7 @@ get_file = get_item(          'towns__numero_insee__startswith':          'towns__numero_insee__startswith',          'name': 'name__icontains', +        'cached_label': 'cached_label__icontains',          'comment': 'comment__icontains',          'permit_reference': 'permit_reference__icontains',          'general_contractor__attached_to': diff --git a/archaeological_finds/urls.py b/archaeological_finds/urls.py index 63bc01bed..7cd261516 100644 --- a/archaeological_finds/urls.py +++ b/archaeological_finds/urls.py @@ -119,6 +119,12 @@ urlpatterns += patterns(          name='get-own-find-full', kwargs={'full': True, 'force_own': True}),      url(r'get-find-full/(?P<type>.+)?$', 'get_find',          name='get-find-full', kwargs={'full': True}), +    url(r'get-find-shortcut/own/(?P<type>.+)?$', +        'get_find', name='get-own-find-shortcut', +        kwargs={'full': 'shortcut', 'force_own': True}), +    url(r'get-find-shortcut/(?P<type>.+)?$', +        'get_find', name='get-find-shortcut', +        kwargs={'full': 'shortcut'}),      url(r'get-findsource/(?P<type>.+)?$',          'get_findsource', name='get-findsource'),      url(r'get-findsource-full/(?P<type>.+)?$', diff --git a/archaeological_finds/views.py b/archaeological_finds/views.py index 80cc6fd8c..d441559cc 100644 --- a/archaeological_finds/views.py +++ b/archaeological_finds/views.py @@ -64,6 +64,7 @@ find_extra_keys = {          'base_finds__find__description__icontains',      'base_finds__batch': 'base_finds__batch',      'basket': 'basket', +    'cached_label': 'cached_label__icontains',      'image': 'image__isnull'}  get_find = get_item( diff --git a/archaeological_operations/urls.py b/archaeological_operations/urls.py index a20eccfe5..f637fd23b 100644 --- a/archaeological_operations/urls.py +++ b/archaeological_operations/urls.py @@ -100,17 +100,17 @@ urlpatterns += patterns(          kwargs={'force_own': True}),      url(r'get-operation/(?P<type>.+)?$', 'get_operation',          name='get-operation'), -    url(r'get-operation-full/(?P<type>.+)?$', 'get_operation', -        name='get-operation-full', kwargs={'full': True}),      url(r'get-operation-full/own/(?P<type>.+)?$',          'get_operation', name='get-own-operation-full',          kwargs={'full': True, 'force_own': True}), -    url(r'get-operation-cached/(?P<type>.+)?$', -        'get_operation', name='get-own-operation-cached', -        kwargs={'full': 'cached'}), -    url(r'get-operation-cached/own/(?P<type>.+)?$', -        'get_operation', name='get-own-operation-cached', -        kwargs={'full': 'cached', 'force_own': True}), +    url(r'get-operation-full/(?P<type>.+)?$', 'get_operation', +        name='get-operation-full', kwargs={'full': True}), +    url(r'get-operation-shortcut/own/(?P<type>.+)?$', +        'get_operation', name='get-own-operation-shortcut', +        kwargs={'full': 'shortcut', 'force_own': True}), +    url(r'get-operation-shortcut/(?P<type>.+)?$', +        'get_operation', name='get-operation-shortcut', +        kwargs={'full': 'shortcut'}),      url(r'get-available-operation-code/(?P<year>.+)?$',          'get_available_operation_code', name='get_available_operation_code'),      url(r'revert-operation/(?P<pk>.+)/(?P<date>.+)$', 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' %} {% endifequal %}{% ifequal cls 'green' %} {% endifequal %}{% ifequal cls 'orange' %} {% endifequal %}{% ifequal cls 'red' %} {% 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 | 
