diff options
Diffstat (limited to 'ishtar_common/static/js/ishtar.js')
| -rw-r--r-- | ishtar_common/static/js/ishtar.js | 222 | 
1 files changed, 195 insertions, 27 deletions
| diff --git a/ishtar_common/static/js/ishtar.js b/ishtar_common/static/js/ishtar.js index f05eb5a1b..9846b4f1a 100644 --- a/ishtar_common/static/js/ishtar.js +++ b/ishtar_common/static/js/ishtar.js @@ -53,14 +53,22 @@ var datatables_default = {      "scrollX": true,      "scrollY": true,      "searching": false, -    "scrollCollapse": true +    "scrollCollapse": true, +    "pageLength": 10, +    "lengthMenu": [ 5, 10, 25, 50, 100 ]  };  var datatables_static_default = {      "searching": false, -    "scrollCollapse": true +    "scrollCollapse": true, +    "pageLength": 10, +    "lengthMenu": [ 5, 10, 25, 50, 100 ]  }; +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."; +var added_message = " items added."; +  var advanced_menu = false;  var shortcut_menu_hide = false;  var activate_all_search_url = '/activate-all-search/'; @@ -128,6 +136,12 @@ function init_shortcut_fields(){                 load_opened_shortcut_menu          );      }); +    $("#current_site").change(function(){ +        $.post('/' + url_path + 'update-current-item/', +               {item:'site', value:$("#current_site").val()}, +               load_opened_shortcut_menu +        ); +    });      $("#current_contextrecord").change(function(){          $.post('/' + url_path + 'update-current-item/',                 {item:'contextrecord', value:$("#current_contextrecord").val()}, @@ -140,6 +154,12 @@ function init_shortcut_fields(){                 load_opened_shortcut_menu          );      }); +    $("#current_warehouse").change(function(){ +        $.post('/' + url_path + 'update-current-item/', +               {item:'warehouse', value:$("#current_warehouse").val()}, +               load_opened_shortcut_menu +        ); +    });      $("#current_treatment").change(function(){          $.post('/' + url_path + 'update-current-item/',                 {item:'treatment', value:$("#current_treatment").val()}, @@ -171,6 +191,14 @@ function init_advanced_shortcut_fields(){                 load_opened_shortcut_menu          );      }); +    $('#id_site-shortcut').change(function(){ +        $("#id_select_site-shortcut").attr( +            'title', $('#id_select_site-shortcut').val()); +        $.post('/' + url_path + 'update-current-item/', +               {item: "site", value:$("#id_site-shortcut").val()}, +               load_opened_shortcut_menu +        ); +    });      $('#id_contextrecord-shortcut').change(function(){          $("#id_select_contextrecord-shortcut").attr(              'title', $('#id_select_contextrecord-shortcut').val()); @@ -187,6 +215,30 @@ function init_advanced_shortcut_fields(){                 load_opened_shortcut_menu          );      }); +    $('#id_warehouse-shortcut').change(function(){ +        $("#id_select_warehouse-shortcut").attr( +            'title', $('#id_select_warehouse-shortcut').val()); +        $.post('/' + url_path + 'update-current-item/', +               {item: "warehouse", value:$("#id_warehouse-shortcut").val()}, +               load_opened_shortcut_menu +        ); +    }); +    $('#id_treatment-shortcut').change(function(){ +        $("#id_select_treatment-shortcut").attr( +            'title', $('#id_select_treatment-shortcut').val()); +        $.post('/' + url_path + 'update-current-item/', +               {item: "treatment", value:$("#id_treatment-shortcut").val()}, +               load_opened_shortcut_menu +        ); +    }); +    $('#id_treatmentfile-shortcut').change(function(){ +        $("#id_select_treatmentfile-shortcut").attr( +            'title', $('#id_select_treatmentfile-shortcut').val()); +        $.post('/' + url_path + 'update-current-item/', +               {item: "treatmentfile", value:$("#id_treatmentfile-shortcut").val()}, +               load_opened_shortcut_menu +        ); +    });  }  function display_info(msg){ @@ -330,6 +382,7 @@ $(document).on("click", '#to_top_arrow', function(){  });  var bookmark_url = ""; +var bookmark_delete_url = "/bookmark/delete/";  var load_bookmark_list = function(){      if (!bookmark_url) return; @@ -337,9 +390,13 @@ var load_bookmark_list = function(){          var bookmark_list = "";          for (idx in data['bookmarks']){              var bookmark = data['bookmarks'][idx]; -            bookmark_list += '<span class="dropdown-item input-link" ' + -                'data-query="' + bookmark['query'].replace(/"/g, "''") + -                '" href="#">' + bookmark['label'] + '</span>'; +            bookmark_list += '<span class="dropdown-item d-flex">' + +                '<a data-query="' + bookmark['query'].replace(/"/g, "''") + +                '" href="#" class="flex-grow-1 input-link">' + bookmark['label'] + +                '</a>' + +                '<a class="close" href="#" data-id="' + bookmark['id'] + '">' + +                '<i class="fa fa-times text-danger" aria-hidden="true"></i>' + +                '</a></span>';          }          $('#bookmark-list').html(bookmark_list);          if (!bookmark_list){ @@ -347,11 +404,17 @@ var load_bookmark_list = function(){          } else {              $('#load-bookmark').removeClass('disabled');          } -        $("#bookmark-list span").click(function(){ +        $("#bookmark-list span a.input-link").click(function(){              $("#id_search_vector").val(                  $(this).attr('data-query').replace(/''/g, '"'));              enable_save();              $(".search_button").click(); +            return false; +        }); +        $("#bookmark-list span a.close").click(function(){ +            var id = $(this).attr('data-id'); +            dt_qa_open(bookmark_delete_url + id + '/'); +            return false;          });      }, 'json');  } @@ -413,7 +476,23 @@ $(document).on("click", '#progress-content', function(){      $('.modal-progress').hide();  }); -function long_wait(){ + +var closed_wait = true; + +function short_wait(check_wait){ +    if (check_wait && closed_wait){ +        return +    } +    closed_wait = false; +    $('.modal-progress').modal('show'); +    $('.progress-1').show('slow'); +} + +function long_wait(check_wait){ +    if (check_wait && closed_wait){ +        return +    } +    closed_wait = false;      $('.modal-progress').modal('show');      $('.progress-1').show('slow');      setTimeout(function(){ @@ -430,11 +509,12 @@ function long_wait(){      }, 180000);      setTimeout(function(){          $('.progress-4').hide('slow'); -        long_wait(); +        long_wait(true);      }, 240000);  }  function close_wait(){ +    closed_wait = true;      $('.modal-progress').modal('hide');      if (current_modal){          $('body').addClass('modal-open'); @@ -586,9 +666,6 @@ function show_hide_flex(id){      }  } -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'); @@ -630,6 +707,23 @@ function clear_search_field(){      enable_save();  } +function _clear_search_criteria_fields(query){ +    var datatables_length = $(".dataTables_length select").val(); +    document.getElementById('wizard-form').reset(); +    // hidden input are not cleared +    $("#modal-advanced-search input[type='hidden']").each( +        function(){ +            if($(this).attr("name") != 'csrfmiddlewaretoken'){ +                $(this).val("") +            } +        } +    ); +    $(".dataTables_length select").val(datatables_length); +    $('.dataTables_length select option[value="' + datatables_length + '"]' +        ).prop('selected', true); +    if(query) $("#id_search_vector").val(query); +} +  function update_search_field(){      var query = $("#id_search_vector").val();      if (!query){ @@ -677,14 +771,11 @@ function update_search_field(){              });          }      ); -    document.getElementById('wizard-form').reset(); -    // some input seems to be not cleared... -    $('#wizard-form input').each(function(){$(this).val("")}); -    $("#id_search_vector").val(query); +    _clear_search_criteria_fields(query);      if (query){ -        add_message(query, 'info', "#advanced-search-info", true, false); +        add_message(query, 'secondary', "#advanced-search-info", true, false);      } else { -        add_message("-", 'info', "#advanced-search-info", true, false); +        add_message("-", 'secondary', "#advanced-search-info", true, false);      }      enable_save();  } @@ -713,11 +804,18 @@ function toggle_window_menu(){      return false;  } +var register_qa_on_sheet = function(){ +    $(".btn-qa").click(function(){ +        var target = $(this).attr('data-target'); +        dt_qa_open(target); +    }); +}; +  function register_advanced_search(){      $(".advanced-search-reset").click(          function(){ -            document.getElementById('wizard-form').reset(); +            _clear_search_criteria_fields();          }      );      $('#modal-advanced-search input').keypress(function(e) { @@ -733,9 +831,7 @@ function register_advanced_search(){      $('#modal-advanced-search').on('hidden.bs.modal', function (e) {          var base_query = $("#id_search_vector").val();          // reset all criteria -        document.getElementById('wizard-form').reset(); -        // restore main input -        $("#id_search_vector").val(base_query); +        _clear_search_criteria_fields(base_query);          $(".search_button").click();          setTimeout(function(){              $("#id_search_vector").focus(); @@ -747,17 +843,89 @@ function register_advanced_search(){  } +var _pinned_search_init = false; +  function manage_pinned_search(name, data){      $('#pinned_search_content_' + name).html('');      for (idx in data){          if (idx == 'pinned-search' && data[idx] != ''){ -           $('#pinned_search_content_' + name).html(data[idx]); +           $("#id_search_vector").val(data[idx]); +           if(!_pinned_search_init){ +               update_search_field(); +               _pinned_search_init = true; +           }          }      } -    if ($('#pinned_search_content_' + name).html()){ -        $('#pinned_search_' + name).show(); -    } else { -        $('#pinned_search_' + name).hide(); -    }  } +var dt_generate_qa_url = function (table, url){ +    var data = table.rows( { selected: true } ).data(); +    var value = ""; +    for (k in data){ +        if (!data[k]['id']) continue; +        if (k > 0) value += "-"; +        value += data[k]['id']; +    } +    url += value + "/"; +    return url; +}; + +var dt_qa_open = function (url){ +    short_wait(); +    $.ajax({ +        url: url, +        cache: false, +        success: function(data, textStatus, jqXHR) { +            close_wait(); +            var text = jqXHR.responseText; +            $('#modal-dynamic-form').html(text); +            var response = $(text); +            var responseScript = response.find("script"); +            $.each(responseScript, function(idx, val){ +                    eval(val.text); +                } +            ); +            $('#modal-dynamic-form').modal("show"); +        }, +        error: function() { +            close_wait(); +        } +    }); +    return false; +}; + +var ajax_post = function(url, data, target, callback){ +    $.ajax({ +        url : url, +        type : "POST", +        data : data, +        success : function(data) { +            close_wait(); +            $(target).html(data); +            if(callback) callback(); +        }, +        error : function(xhr,errmsg,err) { +            close_wait(); +            $(target).html("<div class='alert-box alert'>Oops! We have encountered an error: " +                + errmsg + "</div>"); +            console.log(xhr.status + ": " + xhr.responseText); +            if(callback) callback(); +        } +    }); + +}; + +var qa_action_register = function(url) { + +    $('#qa-action').on('submit', function(event){ +        event.preventDefault(); +        $('#modal-dynamic-form').modal("hide"); +        short_wait(); +        ajax_post( +            url, $(this).serialize(), "#modal-dynamic-form", +            function(){ +                $('#modal-dynamic-form').modal("show"); +            } +        ); +    }); +}; | 
