diff options
Diffstat (limited to 'ishtar_common/static/js/ishtar.js')
| -rw-r--r-- | ishtar_common/static/js/ishtar.js | 210 | 
1 files changed, 175 insertions, 35 deletions
| diff --git a/ishtar_common/static/js/ishtar.js b/ishtar_common/static/js/ishtar.js index 318c17315..c3e36d77b 100644 --- a/ishtar_common/static/js/ishtar.js +++ b/ishtar_common/static/js/ishtar.js @@ -37,6 +37,18 @@ function get_next_table_id(){}  function get_previous_table_id(){}  var shortcut_url = ''; +var datatables_i18n; +var current_modal; + +var datatables_default = { +    "processing": true, +    "serverSide": true, +    "scrollX": true, +    "scrollY": true, +    "searching": false, +    "scrollCollapse": true +}; +  var advanced_menu = false;  var shortcut_menu_hide = false;  var activate_all_search_url = '/activate-all-search/'; @@ -47,9 +59,10 @@ var shortcut_menu_hide_url = '/hide-shortcut-menu/'  var shortcut_menu_show_url = '/show-shortcut-menu/'  function init_shortcut_menu(html){ -    $("#progress").hide(); -    $("#context_menu").html(html); -    $(".chosen-select").chosen(); +    close_wait(); +    $("#context-menu").html(html); +    $("#shortcut-menu .chosen-select").chosen(); +    $("#shortcut-menu .chosen-container").css('width', '100%');      if (advanced_menu) {          init_advanced_shortcut_fields();      } else { @@ -57,14 +70,16 @@ function init_shortcut_menu(html){      }      $("#short-menu-advanced").click(function(){          $.get(url_path + activate_advanced_url, -               load_shortcut_menu +               load_opened_shortcut_menu          );      });      $("#short-menu-simple").click(function(){          $.get(url_path + activate_simple_url, -               load_shortcut_menu +               load_opened_shortcut_menu          );      }); + +    /*      $(".short-menu-close").click(function(){          $('#shortcut-menu div').hide();          $('#shortcut-menu table').hide(); @@ -85,43 +100,44 @@ function init_shortcut_menu(html){          $(".short-menu-close").hide();          $(".short-menu-open").show();      } +    */  }  function init_shortcut_fields(){      $("#current_file").change(function(){          $.post('/' + url_path + 'update-current-item/',                 {item:'file', value:$("#current_file").val()}, -               load_shortcut_menu +               load_opened_shortcut_menu          );      });      $("#current_operation").change(function(){          $.post('/' + url_path + 'update-current-item/',                 {item:'operation', value:$("#current_operation").val()}, -               load_shortcut_menu +               load_opened_shortcut_menu          );      });      $("#current_contextrecord").change(function(){          $.post('/' + url_path + 'update-current-item/',                 {item:'contextrecord', value:$("#current_contextrecord").val()}, -               load_shortcut_menu +               load_opened_shortcut_menu          );      });      $("#current_find").change(function(){          $.post('/' + url_path + 'update-current-item/',                 {item:'find', value:$("#current_find").val()}, -               load_shortcut_menu +               load_opened_shortcut_menu          );      });      $("#current_treatment").change(function(){          $.post('/' + url_path + 'update-current-item/',                 {item:'treatment', value:$("#current_treatment").val()}, -               load_shortcut_menu +               load_opened_shortcut_menu          );      });      $("#current_treatmentfile").change(function(){          $.post('/' + url_path + 'update-current-item/',                 {item:'treatmentfile', value:$("#current_treatmentfile").val()}, -               load_shortcut_menu +               load_opened_shortcut_menu          );      });  } @@ -132,7 +148,7 @@ function init_advanced_shortcut_fields(){              'title', $('#id_select_file-shortcut').val());          $.post('/' + url_path + 'update-current-item/',                 {item: "file", value:$("#id_file-shortcut").val()}, -               load_shortcut_menu +               load_opened_shortcut_menu          );      });      $('#id_operation-shortcut').change(function(){ @@ -140,7 +156,7 @@ function init_advanced_shortcut_fields(){              'title', $('#id_select_operation-shortcut').val());          $.post('/' + url_path + 'update-current-item/',                 {item: "operation", value:$("#id_operation-shortcut").val()}, -               load_shortcut_menu +               load_opened_shortcut_menu          );      });      $('#id_contextrecord-shortcut').change(function(){ @@ -148,7 +164,7 @@ function init_advanced_shortcut_fields(){              'title', $('#id_select_contextrecord-shortcut').val());          $.post('/' + url_path + 'update-current-item/',                 {item: "contextrecord", value:$("#id_contextrecord-shortcut").val()}, -               load_shortcut_menu +               load_opened_shortcut_menu          );      });      $('#id_find-shortcut').change(function(){ @@ -156,7 +172,7 @@ function init_advanced_shortcut_fields(){              'title', $('#id_select_find-shortcut').val());          $.post('/' + url_path + 'update-current-item/',                 {item: "find", value:$("#id_find-shortcut").val()}, -               load_shortcut_menu +               load_opened_shortcut_menu          );      });  } @@ -172,21 +188,46 @@ function display_info(msg){          }, 5000);  } -function load_shortcut_menu(){ +function load_opened_shortcut_menu(){ +    load_shortcut_menu(true); +} + +function load_shortcut_menu(opened){      if (!shortcut_url) return; -    $("#progress").show(); +    $('.modal-progress').modal('show');      $.ajax({          url: shortcut_url,          cache: false,          success:function(html){              init_shortcut_menu(html); +            if(opened){ +                $("#dropdown-toggle-shortcut-menu").click(); +            }          },          error:function(XMLHttpRequest, textStatus, errorThrows){ -            $("#progress").hide(); +            close_wait();          }      });  } +function dynamic_load(url, target){ +    $.ajax({ +        url: url, +        success: function(data, textStatus, jqXHR) { +            $(target).html(jqXHR.responseText); +            var response = $(jqXHR.responseText); +            var responseScript = response.find("script"); +            $.each(responseScript, function(idx, val) { +                eval(val.text); +            } ); +            responseScript = response.filter("script"); +            $.each(responseScript, function(idx, val) { +                eval(val.text); +            } ); +   } +    }); +} +  $(document).ready(function(){      $("#main_menu > ul > li > ul").hide();      $("#main_menu ul ul .selected").parents().show(); @@ -195,13 +236,12 @@ $(document).ready(function(){          $('#to_bottom_arrow').hide();          $('#to_top_arrow').hide();      } -    $('#language_selector').change(function(){ -        $('#language_form').submit(); +    $('#language-selector a').click(function(){ +        $('#language-selector input[name="language"]').val( +            $(this).attr("data-lang")); +        $('#language-form').submit();      });      load_shortcut_menu(); -    if ($.isFunction($(".prettyPhoto a").prettyPhoto)){ -        $(".prettyPhoto a").prettyPhoto({'social_tools':''}); -    }      $('#current_items select').change(function(){          $(this).attr('class', $(this).children("option:selected").attr('class'));      }); @@ -237,12 +277,11 @@ $(document).on("click", '.help_display', function(){  });  $(document).on("click", '#progress-content', function(){ -    $('#progress').hide(); +    $('.modal-progress').hide();  });  function long_wait(){ -    $('#progress').addClass('long'); -    $('#progress').show(); +    $('.modal-progress').modal('show');      $('.progress-1').show('slow');      setTimeout(function(){          $('.progress-1').hide('slow'); @@ -262,22 +301,41 @@ function long_wait(){      }, 240000);  } +function close_wait(){ +    $('.modal-progress').modal('hide'); +    if (current_modal){ +        $('body').addClass('modal-open'); +    } +} +  var last_window; -function load_window(url, speed, on_success){ -    $("#progress").show(); +function load_window(url, speed, on_success, no_jump){ +    $('.modal-progress').modal('show');      $.ajax({          url: url,          cache: false,          success:function(html){ -            $("#progress").hide(); +            close_wait(); +            $(".previous_page").remove(); +            $(".next_page").remove(); +            var register_id = $(html).find(".card-header").attr("data-sheet-id"); +            var current_sheet = $('[data-sheet-id="' + register_id + '"]'); +            if (current_sheet.length){ +                current_sheet.parent().remove(); +            }              $("#window").append(html); -            $("#"+last_window).show(); -            $("a[rel^='prettyPhoto']").prettyPhoto({'social_tools':''}); +            $("#" + last_window).show(); +            if (!no_jump){ +                // jump to this window +                var url = location.href; +                location.href = "#" + last_window; +                history.replaceState(null, null, url); +            }              if (on_success) on_success();          },          error:function(XMLHttpRequest, textStatus, errorThrows){ -            $("#progress").hide(); +            close_wait();          }      });  } @@ -297,15 +355,15 @@ function load_current_window(url, model_name){  }  function load_url(url){ -    $("#progress").show(); +    $('.modal-progress').modal('show');      $.ajax({          url: url,          cache: false,          success:function(html){ -            $("#progress").hide(); +            close_wait();          },          error:function(XMLHttpRequest, textStatus, errorThrows){ -            $("#progress").hide(); +            close_wait();          }      });  } @@ -385,3 +443,85 @@ function activate_own_search(){      });      return false;  } + +function get_label_from_input(input){ +    if (input.parent().filter('.input-group').length){ +        input = input.parent(); +    } +    return "<strong>" + input.prev().html() + "</strong>"; +} + + +function update_search_resume(){ +    var summary = ""; +    var inputs = $('#wizard-form input').map( +        function(){ +            var v = ""; +            var item_for_label = $(this); +            if ($(this).filter(":checkbox:checked").length){ +                var check = $(this).val(); +                if (check == "on"){ +                    v = YES; +                } else { +                    v = $(this).parent().first().contents().filter(function() { +                        return this.nodeType == 3; +                    }).text(); +                    item_for_label = $(this).parent().parent().parent(); +                } +            } else if ($(this).filter(":text").length){ +                v = $(this).val(); +            } else if ($(this).filter('input[type="number"]').length){ +                v = $(this).val(); +            } +            if (v == "") return; +            if (summary) summary += " ; "; +            summary += get_label_from_input(item_for_label) + " " + v; +        } +    ).get(); +    var selects = $('#wizard-form select').each( +        function(){ +            $(this).find('option').not(':first').filter(':selected').map( +                function(){ +                    var item_for_label = $(this).parent(); +                    if(item_for_label.filter('optgroup').length){ +                        item_for_label = item_for_label.parent(); +                    } +                    if (summary) summary += " ; "; +                    summary += get_label_from_input(item_for_label) + " " + $(this).text(); +            }); +        } +    ); + +    if (summary != ""){ +        $('#advanced-search-resume-content').html(summary); +        $('#advanced-search-resume').show(); +    } else { +        $('#advanced-search-resume').hide(); +    } +} + + +function register_advanced_search(){ +    $(".advanced-search-reset").click( +        function(){ +            document.getElementById('wizard-form').reset(); +            $('#advanced-search-resume').hide(); +        } +    ); +    $(".advanced-search-valid").click(update_search_resume); +} + + +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]); +        } +    } +    if ($('#pinned_search_content_' + name).html()){ +        $('#pinned_search_' + name).show(); +    } else { +        $('#pinned_search_' + name).hide(); +    } +} | 
