From e6b894db4362daef594396a993477f1d10988840 Mon Sep 17 00:00:00 2001 From: Alessandro Gubitosi Date: Fri, 8 Aug 2014 16:51:37 +0200 Subject: [PATCH] Summaries foundation --- common/css/bootstrap/bootstrap.css | 2 +- common/include/conf/menu.php | 6 +- common/js/_main/form.js | 186 ++++++++++-------- .../search_panels/search_panel_summary.tpl | 6 +- 4 files changed, 107 insertions(+), 93 deletions(-) diff --git a/common/css/bootstrap/bootstrap.css b/common/css/bootstrap/bootstrap.css index 9e1e90fa..36d032b9 100755 --- a/common/css/bootstrap/bootstrap.css +++ b/common/css/bootstrap/bootstrap.css @@ -5132,7 +5132,7 @@ a.list-group-item-danger.active:focus { } .panel-group .panel { margin-bottom: 0; - overflow: hidden; + /*overflow: hidden;*/ border-radius: 4px; } .panel-group .panel + .panel { diff --git a/common/include/conf/menu.php b/common/include/conf/menu.php index 1b79423b..a2b821b4 100644 --- a/common/include/conf/menu.php +++ b/common/include/conf/menu.php @@ -127,8 +127,8 @@ "class" => "btn btn-link" ), "divider" => "vertical-divider" - //) - ), + ) + //), /* "Map" => array( "content" => array( @@ -159,7 +159,6 @@ ), "divider" => "vertical-divider" ), - */ "Sign in" => array( "content" => array( "icon" => "fa fa-refresh fa-spin", @@ -173,6 +172,7 @@ "class" => "btn btn-link disabled" ) ) + */ ); $menu["menu"]["map_toolbox"] = array( "Find_location" => array( diff --git a/common/js/_main/form.js b/common/js/_main/form.js index 9926c109..5fd7664f 100644 --- a/common/js/_main/form.js +++ b/common/js/_main/form.js @@ -31,7 +31,7 @@ $("#left_panel div.panel-body.autocomplete").addTraitAutocomplete({ id: "main_search", class: "", - placeholder: oprst[kAPI_RESPONSE_RESULTS].placeholder, + placeholder: oprst[kAPI_RESPONSE_RESULTS].placeholder, op: operators }, "remote", function() { operators = operators; @@ -44,8 +44,9 @@ $("#collapsed_group_form .panel.panel-default-white").addAutocomplete({ id: "filter_search_summary", class: "", - placeholder: oprst[kAPI_RESPONSE_RESULTS].placeholder, - op: operators + placeholder: oprst[kAPI_RESPONSE_RESULTS].placeholder, + op: operators, + operator: kAPI_OP_MATCH_TAG_SUMMARY_LABELS }, "remote", function() { operators = operators; }); @@ -341,44 +342,47 @@ $form.find(".dropdown-menu .dropdown-content > ul").append($.create_tree(v, $panel)); }); $item.removeClass("disabled"); - }); - - $form.find(".dropdown-menu > *").click(function(e) { - e.stopPropagation(); - }); - $form.on("shown.bs.dropdown", function () { - $form.find(".dropdown-menu .dropdown-header input.form-control").focus(); - $form.find(".dropdown-menu .dropdown-header input.form-control").keyup(function() { - var that = this; - // affect all table rows on in systems table - var tableBody = $form.find(".dropdown-menu .dropdown-content > ul"); - var tableRowsClass = $form.find(".dropdown-menu .dropdown-content > ul li"); - - tableRowsClass.each(function(i, val) { - //Lower text for case insensitive - var rowText = $(val).text().toLowerCase(); - var inputText = $(that).val().toLowerCase(); - - if(rowText.indexOf(inputText) == -1) { - //hide rows - tableRowsClass.eq(i).hide(); - } else { - $(".search-sf").remove(); - tableRowsClass.eq(i).show(); + $form.find(".dropdown-toggle").dropdown("toggle"); + $form.find(".dropdown-menu > *").click(function(e) { + e.stopPropagation(); + }); + if($form.find(".dropdown-menu").is(":visible")) { + $form.find(".dropdown-menu .dropdown-header input").focus(); + + console.log("ok"); + $form.find(".dropdown-menu .dropdown-header input.form-control").focus(); + $form.find(".dropdown-menu .dropdown-header input.form-control").keyup(function() { + var that = this; + // affect all table rows on in systems table + var tableBody = $form.find(".dropdown-menu .dropdown-content > ul"); + var tableRowsClass = $form.find(".dropdown-menu .dropdown-content > ul li"); + + tableRowsClass.each(function(i, val) { + //Lower text for case insensitive + var rowText = $(val).text().toLowerCase(); + var inputText = $(that).val().toLowerCase(); + + if(rowText.indexOf(inputText) == -1) { + //hide rows + tableRowsClass.eq(i).hide(); + } else { + $(".search-sf").remove(); + tableRowsClass.eq(i).show(); + } + }); + //all tr elements are hidden + if(tableRowsClass.children(":visible").length === 0) { + if(tableBody.find(".search-sf").length === 0) { + tableBody.prepend('
No entries found.
'); + } } + //$form.find(".dropdown-header input").focus(); }); - //all tr elements are hidden - if(tableRowsClass.children(":visible").length === 0) { - if(tableBody.find(".search-sf").length === 0) { - tableBody.prepend('
No entries found.
'); - } - } - //$form.find(".dropdown-header input").focus(); + } + $form.on("submit", function(){ + return false; }); }); - $form.on("submit", function(){ - return false; - }); } $panel_mask.fadeOut(300); $(".save_btn").removeClass("disabled"); @@ -489,7 +493,8 @@ options = $.extend({ id: "", class: "", - placeholder: "Choose..." + placeholder: "Choose...", + operator: kAPI_OP_MATCH_TAG_LABELS }, options); var op_btn_list = "", selected_label = "Operator", @@ -535,7 +540,7 @@ remote: { url: service_url + "%QUERY", replace: function(url, query) { - var state = "true&query=" + $.utf8_to_b64("{SERVICE_URL}?" + kAPI_REQUEST_OPERATION + "=" + kAPI_OP_MATCH_TAG_LABELS + "&" + kAPI_REQUEST_LANGUAGE + "=" + lang + "&" + kAPI_REQUEST_PARAMETERS + "=" + $.rawurlencode('{"' + kAPI_PAGING_LIMIT + '":50,"' + kAPI_PARAM_REF_COUNT + '":"' + kAPI_PARAM_COLLECTION_UNIT + '","' + kAPI_PARAM_PATTERN + '":"' + $("#" + options.id).val() + '","' + kAPI_PARAM_OPERATOR + '": ["$' + $("#" + options.id + "_operator").attr("class") + '"' + ($("#main_search_operator_i").is(":checked") ? ',"$i"' : "") + ']}')); + var state = "true&query=" + $.utf8_to_b64("{SERVICE_URL}?" + kAPI_REQUEST_OPERATION + "=" + options.operator + "&" + kAPI_REQUEST_LANGUAGE + "=" + lang + "&" + kAPI_REQUEST_PARAMETERS + "=" + $.rawurlencode('{"' + kAPI_PAGING_LIMIT + '":50,"' + kAPI_PARAM_REF_COUNT + '":"' + kAPI_PARAM_COLLECTION_UNIT + '","' + kAPI_PARAM_PATTERN + '":"' + $("#" + options.id).val() + '","' + kAPI_PARAM_OPERATOR + '": ["$' + $("#" + options.id + "_operator").attr("class") + '"' + ($("#main_search_operator_i").is(":checked") ? ',"$i"' : "") + ']}')); //var state = "true&address=" + $.utf8_to_b64("{SERVICE_URL}?" + kAPI_REQUEST_OPERATION + "=" + kAPI_OP_MATCH_TAG_LABELS + "&" + kAPI_REQUEST_LANGUAGE + "=" + lang + "&" + kAPI_REQUEST_PARAMETERS + "=" + $.rawurlencode('{"' + kAPI_PAGING_LIMIT + '":50,"' + kAPI_PARAM_REF_COUNT + '": "' + kAPI_PARAM_COLLECTION_UNIT + '","' + kAPI_PARAM_PATTERN + '":"' + $("#" + options.id).val() + '","' + kAPI_PARAM_OPERATOR + '": ["$' + $("#" + options.id + "_operator").attr("class") + '"' + ($("#main_search_operator_i").is(":checked") ? ',"$i"' : "") + ']}')); return url.replace("%QUERY", state); }, @@ -955,36 +960,14 @@ $("#" + type + "-body .content-body").html(""); if(type !== "results") { - console.log(options.res.results); - $.each(options.res.results, function(domain, values) { - var result_panel = $('
'), - result_h4 = $('

'), - result_title = $(''), - result_description = $('

'), - result_content_container = $('

'), - result_description_span_muted = $(''), - result_description_span_right = $(''); - - result_title.html($.trim(values[kAPI_PARAM_RESPONSE_FRMT_NAME]) + ' ' + values[kAPI_PARAM_RESPONSE_COUNT] + '').appendTo(result_h4); - result_h4.appendTo(result_panel); - result_description.html(values[kAPI_PARAM_RESPONSE_FRMT_INFO]).appendTo(result_panel); - - result_description_span_muted.html('' + values[kAPI_PARAM_RESPONSE_COUNT] + ' items').appendTo(result_content_container); - result_description_span_right.append('View raw data'); - if(values.points > 0) { - result_description_span_right.append(' View on map ' + values.points + ''); - } - result_description_span_right.appendTo(result_content_container); - result_content_container.appendTo(result_panel); - - $("#" + type + "-body .content-body").attr("id", options.res.id).append(result_panel); - + $.generate_summaries(options.res, function(result_panel){ + $("#" + type + "-body .content-body").attr("id", options.res[kAPI_PARAM_ID]).append(result_panel); //$("#" + type + "-body .content-body").attr("id", options.res.id).append("

" + $.trim(values[kTAG_LABEL]) + " " + values[kAPI_PARAM_RESPONSE_COUNT] + "

"); }); } else { var cols = options.res[kAPI_RESULTS_DICTIONARY][kAPI_DICTIONARY_LIST_COLS], rows = options.res[kAPI_RESPONSE_RESULTS]; - $("#" + type + "-body .content-body").append('
'); + $("#" + type + "-body .content-body").append('
'); /** * Parse cell content and display helps if present * @param {string|object} disp The text or object that will be parsed @@ -1110,6 +1093,39 @@ }; + /** + * Create summary content pane + * @param {object} the result of previous query (eg. Search or Autocomplete) + */ + $.generate_summaries = function(options, callback) { + console.log(options[kAPI_RESPONSE_RESULTS]); + $.each(options[kAPI_RESPONSE_RESULTS], function(domain, values) { + var result_panel = $('
'), + result_h4 = $('

'), + result_title = $(''), + result_description = $('

'), + result_content_container = $('

'), + result_description_span_muted = $(''), + result_description_span_right = $(''); + + result_title.html($.trim(values[kAPI_PARAM_RESPONSE_FRMT_NAME]) + ' ' + values[kAPI_PARAM_RESPONSE_COUNT] + '').appendTo(result_h4); + result_h4.appendTo(result_panel); + result_description.html(values[kAPI_PARAM_RESPONSE_FRMT_INFO]).appendTo(result_panel); + + result_description_span_muted.html('').appendTo(result_content_container); + result_description_span_right.append('View raw data'); + if(values.points > 0) { + result_description_span_right.append(' View on map ' + values.points + ''); + } + result_description_span_right.appendTo(result_content_container); + result_content_container.appendTo(result_panel); + + if (jQuery.type(callback) == "function") { + callback.call(this, result_panel); + } + }); + }; + /*======================================================================================= * RAW DATA *======================================================================================*/ @@ -1719,9 +1735,17 @@ var $panel = item, panel_input_term_id = $panel.find('input[name="term"]').attr("id"), content = "", - triangle = '', - checkbox = '
'; - checkbox_inline = '
'; + triangle = '', + checkbox = '
'; + checkbox += '
'; if (v.children !== undefined && v.children > 0) { content += '
  • ' + triangle + '' + ((v.value !== undefined && v.value) ? checkbox_inline.replace("{LABEL}", v.label) : '' + v.label + '') + '
  • '; @@ -1868,7 +1892,8 @@ options = $.extend({ id: "", class: "", - placeholder: "Choose..." + placeholder: "Choose...", + op: kAPI_OP_MATCH_TAG_LABELS }, options); var op_btn_list = "", selected_label = "Operator", @@ -1914,8 +1939,8 @@ remote: { url: service_url + "%QUERY", replace: function(url, query) { - var state = "true&query=" + $.utf8_to_b64("{SERVICE_URL}?" + kAPI_REQUEST_OPERATION + "=" + kAPI_OP_MATCH_TAG_LABELS + "&" + kAPI_REQUEST_LANGUAGE + "=" + lang + "&" + kAPI_REQUEST_PARAMETERS + "=" + $.rawurlencode('{"' + kAPI_PAGING_LIMIT + '":50,"' + kAPI_PARAM_REF_COUNT + '":"' + kAPI_PARAM_COLLECTION_UNIT + '","' + kAPI_PARAM_PATTERN + '":"' + $("#" + options.id).val() + '","' + kAPI_PARAM_OPERATOR + '": ["$' + $("#" + options.id + "_operator").attr("class") + '"' + ($("#main_search_operator_i").is(":checked") ? ',"$i"' : "") + ']}')); - //var state = "true&address=" + $.utf8_to_b64("{SERVICE_URL}?" + kAPI_REQUEST_OPERATION + "=" + kAPI_OP_MATCH_TAG_LABELS + "&" + kAPI_REQUEST_LANGUAGE + "=" + lang + "&" + kAPI_REQUEST_PARAMETERS + "=" + $.rawurlencode('{"' + kAPI_PAGING_LIMIT + '":50,"' + kAPI_PARAM_REF_COUNT + '": "' + kAPI_PARAM_COLLECTION_UNIT + '","' + kAPI_PARAM_PATTERN + '":"' + $("#" + options.id).val() + '","' + kAPI_PARAM_OPERATOR + '": ["$' + $("#" + options.id + "_operator").attr("class") + '"' + ($("#main_search_operator_i").is(":checked") ? ',"$i"' : "") + ']}')); + var state = "true&query=" + $.utf8_to_b64("{SERVICE_URL}?" + kAPI_REQUEST_OPERATION + "=" + options.operator + "&" + kAPI_REQUEST_LANGUAGE + "=" + lang + "&" + kAPI_REQUEST_PARAMETERS + "=" + $.rawurlencode('{"' + kAPI_PARAM_LOG_REQUEST + '":true,"' + kAPI_PAGING_LIMIT + '":50,"' + kAPI_PARAM_REF_COUNT + '":"' + kAPI_PARAM_COLLECTION_UNIT + '","' + kAPI_PARAM_PATTERN + '":"' + $("#" + options.id).val() + '","' + kAPI_PARAM_OPERATOR + '": ["$' + $("#" + options.id + "_operator").attr("class") + '"' + ($("#filter_search_summary_operator_i").is(":checked") ? ',"$i"' : "") + ']}')); + //var state = "true&address=" + $.utf8_to_b64("{SERVICE_URL}?" + kAPI_REQUEST_OPERATION + "=" + kAPI_OP_MATCH_TAG_LABELS + "&" + kAPI_REQUEST_LANGUAGE + "=" + lang + "&" + kAPI_REQUEST_PARAMETERS + "=" + $.rawurlencode('{"' + kAPI_PAGING_LIMIT + '":50,"' + kAPI_PARAM_REF_COUNT + '": "' + kAPI_PARAM_COLLECTION_UNIT + '","' + kAPI_PARAM_PATTERN + '":"' + $("#" + options.id).val() + '","' + kAPI_PARAM_OPERATOR + '": ["$' + $("#" + options.id + "_operator").attr("class") + '"' + ($("#filter_search_summary_operator_i").is(":checked") ? ',"$i"' : "") + ']}')); return url.replace("%QUERY", state); }, filter: function (parsedResponse) { @@ -1938,7 +1963,6 @@ remoteAutocomplete.clearPrefetchCache(); remoteAutocomplete.initialize(); - var form_help_text = "Click on the green rectangle to activate the field: if you press the search button the system will select all data containing the selected field, regardless of its value.
    To search for specific field values, fill the field search value or select the provided options."; $("#" + options.id).typeahead({ hint: true, highlight: true, @@ -1950,11 +1974,9 @@ source: remoteAutocomplete.ttAdapter() }).on("typeahead:selected", function(){ // Autocomplete - $.manage_url("Forms"); - var kAPI = {}; kAPI.storage_group = "forms"; - kAPI[kAPI_REQUEST_OPERATION] = kAPI_OP_MATCH_TAG_BY_LABEL; + kAPI[kAPI_REQUEST_OPERATION] = kAPI_OP_MATCH_SUMMARY_TAG_BY_LABEL; kAPI.parameters = {}; kAPI.parameters[kAPI_REQUEST_LANGUAGE] = lang; kAPI.parameters[kAPI_REQUEST_PARAMETERS] = {}; @@ -1962,20 +1984,12 @@ kAPI.parameters[kAPI_REQUEST_PARAMETERS][kAPI_PAGING_LIMIT] = 50; kAPI.parameters[kAPI_REQUEST_PARAMETERS][kAPI_PARAM_REF_COUNT] = kAPI_PARAM_COLLECTION_UNIT; kAPI.parameters[kAPI_REQUEST_PARAMETERS][kAPI_PARAM_PATTERN] = $("#" + options.id).val(); - kAPI.parameters[kAPI_REQUEST_PARAMETERS][kAPI_PARAM_OPERATOR] = ["$EQ"]; - console.log("ok"); + kAPI.parameters[kAPI_REQUEST_PARAMETERS][kAPI_PARAM_OPERATOR] = ["$" + $("#" + options.id + "_operator").attr("class"), ($("#filter_search_summary_operator_i").is(":checked") ? '$i' : '""')]; + $.ask_to_service(kAPI, function(response) { + console.log(response); - return false; - }).bind("keydown", "return", function(event) { - $(this).trigger("typeahead:_changed"); - return false; - }).bind("keydown", "alt+left", function(e) { - $.left_panel("close", "", function() { - $("#" + options.id).blur(); }); - return false; - }).bind("keydown", "alt+right", function(e) { - $.left_panel("open"); + is_autocompleted = true; return false; }); diff --git a/common/tpl/search_panels/search_panel_summary.tpl b/common/tpl/search_panels/search_panel_summary.tpl index a980001a..1d8c71aa 100644 --- a/common/tpl/search_panels/search_panel_summary.tpl +++ b/common/tpl/search_panels/search_panel_summary.tpl @@ -2,11 +2,11 @@

    -
    - +