commit
f2ef73bd3a
9 changed files with 322 additions and 154 deletions
|
|
@ -1288,7 +1288,7 @@
|
|||
"issingle": 0,
|
||||
"istable": 1,
|
||||
"max_attachments": 0,
|
||||
"modified": "2017-02-17 16:14:33.670631",
|
||||
"modified": "2017-02-22 21:43:00.771400",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Core",
|
||||
"name": "DocField",
|
||||
|
|
|
|||
|
|
@ -255,7 +255,7 @@
|
|||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"depends_on": "eval:([\"Data\", \"Select\", \"Table\", \"Text\", \"Text Editor\", \"Link\", \"Small Text\", \"Long Text\", \"Read Only\", \"Heading\"].indexOf(doc.fieldtype) !== -1)",
|
||||
"depends_on": "eval:([\"Data\", \"Select\", \"Table\", \"Text\", \"Text Editor\", \"Link\", \"Small Text\", \"Long Text\", \"Read Only\", \"Heading\", \"Dynamic Link\"].indexOf(doc.fieldtype) !== -1)",
|
||||
"fieldname": "in_global_search",
|
||||
"fieldtype": "Check",
|
||||
"hidden": 0,
|
||||
|
|
@ -1104,7 +1104,7 @@
|
|||
"issingle": 0,
|
||||
"istable": 1,
|
||||
"max_attachments": 0,
|
||||
"modified": "2017-01-30 02:49:36.834130",
|
||||
"modified": "2017-02-22 21:43:19.748233",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Custom",
|
||||
"name": "Customize Form Field",
|
||||
|
|
@ -1113,6 +1113,7 @@
|
|||
"quick_entry": 0,
|
||||
"read_only": 0,
|
||||
"read_only_onload": 0,
|
||||
"show_name_in_global_search": 0,
|
||||
"sort_order": "ASC",
|
||||
"track_changes": 0,
|
||||
"track_seen": 0
|
||||
|
|
|
|||
|
|
@ -687,16 +687,46 @@ fieldset[disabled] .form-control {
|
|||
padding: 0px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
.search-dialog .layout-side-section .module-sidebar-nav {
|
||||
margin-top: 0px;
|
||||
}
|
||||
.search-dialog .layout-side-section .help-link {
|
||||
padding-top: 20px;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
.search-dialog .layout-side-section .nav > li > a {
|
||||
.search-dialog .layout-side-section .nav > li a {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding-left: 20px;
|
||||
}
|
||||
.search-dialog .results-area a {
|
||||
color: #5E64FF;
|
||||
.search-dialog .layout-side-section .nav li a i {
|
||||
visibility: hidden;
|
||||
}
|
||||
.search-dialog .layout-side-section .nav .active i {
|
||||
visibility: visible;
|
||||
}
|
||||
.search-dialog .results-area .search-intro-placeholder {
|
||||
color: #d4d9dd;
|
||||
height: inherit;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
.search-dialog .results-area .search-intro-placeholder span {
|
||||
text-align: center;
|
||||
}
|
||||
.search-dialog .results-area .search-intro-placeholder span i{
|
||||
font-size: 120px;
|
||||
display: block;
|
||||
}
|
||||
.search-dialog .results-area .search-intro-placeholder span p{
|
||||
font-size: 20px;
|
||||
display: block;
|
||||
}
|
||||
/*.search-dialog .results-area a {
|
||||
color: #5E64FF;
|
||||
}*/
|
||||
.search-dialog .results-area .single-link a {
|
||||
color: #36414c;
|
||||
}
|
||||
|
|
@ -709,13 +739,16 @@ fieldset[disabled] .form-control {
|
|||
content: '\f0a4';
|
||||
}
|
||||
.search-dialog .full-list .result {
|
||||
border-bottom: 1px solid #d1d8dd;
|
||||
margin-top: 10px;
|
||||
margin-top: 15px;
|
||||
}
|
||||
.search-dialog .full-list .result .result-subtype {
|
||||
float: right;
|
||||
margin-left: 10px;
|
||||
}
|
||||
.search-dialog .full-list .result-with-subtype {
|
||||
border-bottom: 1px solid #d1d8dd;
|
||||
margin-top: 10px;
|
||||
}
|
||||
.search-dialog .full-list .section-head {
|
||||
margin-bottom: 25px;
|
||||
}
|
||||
|
|
@ -746,6 +779,11 @@ fieldset[disabled] .form-control {
|
|||
margin: 30px 0px;
|
||||
}
|
||||
}
|
||||
@media (min-width: 600px) {
|
||||
.search-dialog .results-area .back-link {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
.result p {
|
||||
margin-top: 0.2em;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,9 +4,11 @@ frappe.provide('frappe.search');
|
|||
|
||||
frappe.search.AwesomeBar = Class.extend({
|
||||
setup: function(element) {
|
||||
var me = this;
|
||||
|
||||
var $input = $(element);
|
||||
var input = $input.get(0);
|
||||
var me = this;
|
||||
|
||||
this.search = new frappe.search.UnifiedSearch();
|
||||
this.global = new frappe.search.GlobalSearch();
|
||||
this.nav = new frappe.search.NavSearch();
|
||||
|
|
@ -56,7 +58,7 @@ frappe.search.AwesomeBar = Class.extend({
|
|||
sort: function(a, b) {
|
||||
var a_index = a.split("%%%")[3];
|
||||
var b_index = b.split("%%%")[3];
|
||||
return (a_index - b_index);
|
||||
return (a_index*10 - b_index*10);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -102,7 +104,7 @@ frappe.search.AwesomeBar = Class.extend({
|
|||
}
|
||||
});
|
||||
awesomplete.list = out;
|
||||
}, 200));
|
||||
}, 100));
|
||||
|
||||
});
|
||||
|
||||
|
|
@ -215,7 +217,7 @@ frappe.search.AwesomeBar = Class.extend({
|
|||
out.label = match[0].bold();
|
||||
out.value = match[0];
|
||||
}
|
||||
out.index = 29;
|
||||
out.index = 30;
|
||||
out.default = "Recent";
|
||||
return out;
|
||||
}, true);
|
||||
|
|
@ -261,9 +263,7 @@ frappe.search.AwesomeBar = Class.extend({
|
|||
|
||||
var ilen = item.length;
|
||||
var tlen = txt.length;
|
||||
var match_level1 = 0.5;
|
||||
var match_level2 = 0.8;
|
||||
var index = ((tlen/ilen) > match_level1) ? 24 : index;
|
||||
var match_level = tlen/ilen;
|
||||
var rendered_label = "";
|
||||
var i, j, skips = 0, mismatches = 0;
|
||||
|
||||
|
|
@ -271,14 +271,9 @@ frappe.search.AwesomeBar = Class.extend({
|
|||
return [];
|
||||
}
|
||||
if (item.indexOf(txt) !== -1) {
|
||||
// prefer single words
|
||||
index = (item.indexOf(' ') === -1) ? index-1 : index;
|
||||
index = ((tlen/ilen) > match_level2) ? 21 : index;
|
||||
|
||||
var regEx = new RegExp("("+ txt +")", "ig");
|
||||
rendered_label = _item.replace(regEx, '<b>$1</b>');
|
||||
|
||||
return [_item, index, rendered_label];
|
||||
return [_item, ilen/50, rendered_label];
|
||||
}
|
||||
outer: for (i = 0, j = 0; i < tlen; i++) {
|
||||
var t_ch = txt.charCodeAt(i);
|
||||
|
|
@ -305,7 +300,7 @@ frappe.search.AwesomeBar = Class.extend({
|
|||
return [];
|
||||
}
|
||||
rendered_label += _item.slice(j);
|
||||
return [_item, index + 10, rendered_label];
|
||||
return [_item, 20 + ilen/50, rendered_label];
|
||||
},
|
||||
|
||||
set_specifics: function(txt, end_txt) {
|
||||
|
|
@ -313,9 +308,6 @@ frappe.search.AwesomeBar = Class.extend({
|
|||
var results = this.build_options(txt);
|
||||
results.forEach(function(r) {
|
||||
if((r.type).toLowerCase().indexOf(end_txt.toLowerCase()) === 0) {
|
||||
if(r.index < 25) {
|
||||
r.index = 21;
|
||||
}
|
||||
me.options.push(r);
|
||||
}
|
||||
});
|
||||
|
|
@ -346,11 +338,11 @@ frappe.search.AwesomeBar = Class.extend({
|
|||
label: __("Search for '" + txt.bold() + "'"),
|
||||
value: __("Search for '" + txt + "'"),
|
||||
match: txt,
|
||||
index: 22,
|
||||
index: 10,
|
||||
default: "Search",
|
||||
onclick: function() {
|
||||
me.search.search_dialog.show();
|
||||
me.search.setup_search(txt, [me.global, me.nav, me.help]);
|
||||
me.search.setup_search(txt, [me.nav, me.global, me.help]);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
|
@ -367,7 +359,7 @@ frappe.search.AwesomeBar = Class.extend({
|
|||
label: __('Find {0} in {1}', [txt.bold(), route[1].bold()]),
|
||||
value: __('Find {0} in {1}', [txt, route[1]]),
|
||||
route_options: options,
|
||||
index: 23,
|
||||
index: 11,
|
||||
onclick: function() {
|
||||
cur_list.refresh();
|
||||
},
|
||||
|
|
@ -390,7 +382,7 @@ frappe.search.AwesomeBar = Class.extend({
|
|||
label: formatted_value,
|
||||
value: __('{0} = {1}', [txt, val]),
|
||||
match: val,
|
||||
index: 24,
|
||||
index: 12,
|
||||
default: "Calculator",
|
||||
onclick: function() {
|
||||
msgprint(formatted_value, "Result");
|
||||
|
|
@ -408,13 +400,13 @@ frappe.search.AwesomeBar = Class.extend({
|
|||
if(in_list(txt.split(" "), "in") && (txt.slice(-2) !== "in")) {
|
||||
parts = txt.split(" in ");
|
||||
frappe.boot.user.can_read.forEach(function (item) {
|
||||
var target = me.fuzzy_search(parts[1], item, 21)[0];
|
||||
var target = me.fuzzy_search(parts[1], item, 13)[0];
|
||||
if(target) {
|
||||
out.push({
|
||||
label: __('Find {0} in {1}', [__(parts[0]).bold(), __(target).bold()]),
|
||||
value: __('Find {0} in {1}', [__(parts[0]), __(target)]),
|
||||
route_options: {"name": ["like", "%" + parts[0] + "%"]},
|
||||
index: 21,
|
||||
index: 13,
|
||||
default: "In List",
|
||||
route: ["List", target]
|
||||
});
|
||||
|
|
@ -429,14 +421,15 @@ frappe.search.AwesomeBar = Class.extend({
|
|||
var out = [];
|
||||
if(txt.split(" ")[0]==="new") {
|
||||
frappe.boot.user.can_create.forEach(function (item) {
|
||||
var result = me.fuzzy_search(txt.substr(4), item, 21);
|
||||
var result = me.fuzzy_search(txt.substr(4), item, 14);
|
||||
var target = result[0];
|
||||
var index = result[1];
|
||||
var rendered_label = result[2];
|
||||
if(target) {
|
||||
out.push({
|
||||
label: rendered_label,
|
||||
value: __("New {0}", [target]),
|
||||
index: 21,
|
||||
index: 14 + index,
|
||||
type: "New",
|
||||
prefix: "New",
|
||||
match: target,
|
||||
|
|
@ -453,23 +446,23 @@ frappe.search.AwesomeBar = Class.extend({
|
|||
var out = [];
|
||||
|
||||
var result, target, index, rendered_label;
|
||||
var option = function(type, route) {
|
||||
var option = function(type, route, order) {
|
||||
return {
|
||||
label: rendered_label,
|
||||
value: __(target),
|
||||
route: route,
|
||||
index: index,
|
||||
index: 15 + index + order,
|
||||
match: target,
|
||||
type: type
|
||||
}
|
||||
};
|
||||
frappe.boot.user.can_read.forEach(function (item) {
|
||||
result = me.fuzzy_search(txt, item, 25);
|
||||
result = me.fuzzy_search(txt, item, 15);
|
||||
target = result[0];
|
||||
index = result[1];
|
||||
rendered_label = result[2];
|
||||
if(target) {
|
||||
// include 'making new' option (not working)
|
||||
// include 'making new' option
|
||||
// if(in_list(frappe.boot.user.can_create, target)) {
|
||||
// out.push({
|
||||
// label: rendered_label,
|
||||
|
|
@ -481,19 +474,19 @@ frappe.search.AwesomeBar = Class.extend({
|
|||
// });
|
||||
// }
|
||||
if(in_list(frappe.boot.single_types, target)) {
|
||||
out.push(option("", ["Form", target, target]));
|
||||
out.push(option("", ["Form", target, target], 0));
|
||||
|
||||
} else if(in_list(frappe.boot.treeviews, target)) {
|
||||
out.push(option("Tree", ["Tree", target]));
|
||||
out.push(option("Tree", ["Tree", target], 0));
|
||||
|
||||
} else {
|
||||
out.push(option("List", ["List", target]));
|
||||
out.push(option("List", ["List", target], 0));
|
||||
if(frappe.model.can_get_report(target)) {
|
||||
out.push(option("Report", ["Report", target]));
|
||||
out.push(option("Report", ["Report", target], 0.001));
|
||||
}
|
||||
if(frappe.boot.calendars.indexOf(target) !== -1) {
|
||||
out.push(option("Calendar", ["List", target, "Calendar"]));
|
||||
out.push(option("Gantt", ["List", target, "Gantt"]));
|
||||
out.push(option("Calendar", ["List", target, "Calendar"], 0.002));
|
||||
out.push(option("Gantt", ["List", target, "Gantt"], 0.003));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -506,7 +499,7 @@ frappe.search.AwesomeBar = Class.extend({
|
|||
var me = this;
|
||||
var out = [];
|
||||
Object.keys(frappe.boot.user.all_reports).forEach(function(item) {
|
||||
var result = me.fuzzy_search(txt, item, 26);
|
||||
var result = me.fuzzy_search(txt, item, 20);
|
||||
var target = result[0];
|
||||
var index = result[1];
|
||||
var rendered_label = result[2];
|
||||
|
|
@ -522,7 +515,7 @@ frappe.search.AwesomeBar = Class.extend({
|
|||
label: rendered_label,
|
||||
value: __("Report {0}" , [__(target)]),
|
||||
match: txt,
|
||||
index: index,
|
||||
index: 20 + index,
|
||||
type: "Report",
|
||||
prefix: "Report",
|
||||
route: route
|
||||
|
|
@ -541,7 +534,7 @@ frappe.search.AwesomeBar = Class.extend({
|
|||
p.name = name;
|
||||
});
|
||||
Object.keys(this.pages).forEach(function(item) {
|
||||
var result = me.fuzzy_search(txt, item, 27);
|
||||
var result = me.fuzzy_search(txt, item, 21);
|
||||
var target = result[0];
|
||||
var index = result[1];
|
||||
var rendered_label = result[2];
|
||||
|
|
@ -551,7 +544,7 @@ frappe.search.AwesomeBar = Class.extend({
|
|||
label: rendered_label,
|
||||
value: __("Open {0}", [__(target)]),
|
||||
match: txt,
|
||||
index: index,
|
||||
index: 21 + index,
|
||||
type: "Page",
|
||||
prefix: "Open",
|
||||
route: [page.route || page.name]
|
||||
|
|
@ -565,7 +558,7 @@ frappe.search.AwesomeBar = Class.extend({
|
|||
label: rendered_label,
|
||||
value: __("Open {0}", [__(target)]),
|
||||
route: [target, 'Event'],
|
||||
index: 27,
|
||||
index: 21,
|
||||
type: "Calendar",
|
||||
prefix: "Open",
|
||||
match: target
|
||||
|
|
@ -578,7 +571,7 @@ frappe.search.AwesomeBar = Class.extend({
|
|||
var me = this;
|
||||
var out = [];
|
||||
Object.keys(frappe.modules).forEach(function(item) {
|
||||
var result = me.fuzzy_search(txt, item, 28);
|
||||
var result = me.fuzzy_search(txt, item, 22);
|
||||
var target = result[0];
|
||||
var index = result[1];
|
||||
var rendered_label = result[2];
|
||||
|
|
@ -589,7 +582,7 @@ frappe.search.AwesomeBar = Class.extend({
|
|||
label: rendered_label,
|
||||
value: __("Open {0}", [__(target)]),
|
||||
match: txt,
|
||||
index: index,
|
||||
index: 22 + index,
|
||||
type: "Module",
|
||||
prefix: "Open"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
<div class="row">
|
||||
<div class="col-md-2 col-sm-2 hidden-xs layout-side-section search-sidebar">
|
||||
<ul class="module-sidebar-nav overlay-sidebar nav nav-pills nav-stacked search-sidelist">
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
<div class="col-md-10 col-sm-10 layout-main-section results-area">
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,15 @@ frappe.provide('frappe.search');
|
|||
frappe.search.UnifiedSearch = Class.extend({
|
||||
|
||||
setup: function() {
|
||||
var d = new frappe.ui.Dialog();
|
||||
var d;
|
||||
if(!frappe.search.dialog) {
|
||||
d = new frappe.ui.Dialog();
|
||||
frappe.search.dialog = d;
|
||||
} else {
|
||||
d = frappe.search.dialog;
|
||||
$(d.body).empty();
|
||||
}
|
||||
|
||||
$(frappe.render_template("search")).appendTo($(d.body));
|
||||
$(d.header).html($(frappe.render_template("search_header")));
|
||||
|
||||
|
|
@ -12,51 +20,95 @@ frappe.search.UnifiedSearch = Class.extend({
|
|||
this.search_modal.addClass('search-dialog');
|
||||
|
||||
this.input = this.search_modal.find(".search-input");
|
||||
this.sidelist = this.search_modal.find(".search-sidelist");
|
||||
this.sidebar = this.search_modal.find(".search-sidebar");
|
||||
this.results_area = this.search_modal.find(".results-area");
|
||||
},
|
||||
|
||||
setup_search: function(keywords, search_objects) {
|
||||
setup_search: function(init_keywords, search_objects) {
|
||||
var me = this;
|
||||
var keywords = init_keywords;
|
||||
this.search_objects = search_objects;
|
||||
this.search_types = search_objects.map(function(s) {
|
||||
return s.search_type;
|
||||
});
|
||||
this.current_type = '';
|
||||
this.current_type = "All Results";
|
||||
this.reset();
|
||||
this.bind_keyboard_events();
|
||||
this.input.val(keywords);
|
||||
this.input.on("input", function() {
|
||||
var $this = $(this);
|
||||
clearTimeout($this.data('timeout'));
|
||||
|
||||
$this.data('timeout', setTimeout(function(){
|
||||
var keywords = me.input.val();
|
||||
$this.data('timeout', setTimeout(function() {
|
||||
if(me.input.val() === keywords) return;
|
||||
keywords = me.input.val();
|
||||
me.reset();
|
||||
if(keywords.length > 2) {
|
||||
me.build_results(keywords);
|
||||
} else {
|
||||
me.current_type = '';
|
||||
}
|
||||
}, 600));
|
||||
}, 300));
|
||||
});
|
||||
this.build_results(keywords);
|
||||
setTimeout(function() { me.input.select(); }, 500);
|
||||
},
|
||||
|
||||
reset: function() {
|
||||
this.sidelist.empty();
|
||||
this.sidebar.empty();
|
||||
this.results_area.empty();
|
||||
this.results_area.append($('<div class="search-intro-placeholder"><span>' +
|
||||
'<i class="mega-octicon octicon-telescope"></i><p>'+__("Search for anything")+'</p></span></div>'));
|
||||
},
|
||||
|
||||
bind_keyboard_events: function() {
|
||||
var me = this;
|
||||
this.search_modal.on('keydown', function(e) {
|
||||
if(me.sidebar.find('.list-link').length > 1) {
|
||||
var list_types = me.get_all_list_types();
|
||||
var current_type_index = list_types.indexOf(me.current_type);
|
||||
// DOWN and UP keys navigate sidebar
|
||||
if(e.which === 40) {
|
||||
if(current_type_index < list_types.length - 1) {
|
||||
next_type = list_types[current_type_index + 1];
|
||||
me.sidebar.find('*[data-category="'+ next_type +'"]').trigger('click');
|
||||
}
|
||||
} else if(e.which === 38) {
|
||||
if(current_type_index > 0) {
|
||||
last_type = list_types[current_type_index - 1];
|
||||
me.sidebar.find('*[data-category="'+ last_type +'"]').trigger('click');
|
||||
}
|
||||
} else if (e.which === 9) {
|
||||
// Tab key rolls back after the last result
|
||||
if(me.results_area.find('a').last().is(":focus")) {
|
||||
e.preventDefault();
|
||||
me.results_area.find('.module-section-link').first().focus();
|
||||
}
|
||||
} else if(e.which === 8) {
|
||||
// Backspace key focuses input
|
||||
if(!me.input.is(":focus")) {
|
||||
me.input.focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
this.search_modal.on('keypress', function(e) {
|
||||
if(!me.input.is(":focus")) {
|
||||
me.input.focus();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
build_results: function(keywords) {
|
||||
var me = this;
|
||||
this.summary = $('<div class="module-body summary"></div>');
|
||||
this.sidelist = $('<ul class="module-sidebar-nav overlay-sidebar nav nav-pills nav-stacked search-sidelist"></ul>');
|
||||
this.full_lists = {};
|
||||
this.current = 0;
|
||||
this.search_objects[me.current].build_results_object(me, keywords);
|
||||
},
|
||||
|
||||
render_results: function(results_obj, keywords){
|
||||
render_results: function(results_obj, keywords) {
|
||||
var me = this;
|
||||
if(this.current === 0) { this.reset() }
|
||||
results_obj.sidelist.forEach(function(list_item) {
|
||||
|
|
@ -67,47 +119,42 @@ frappe.search.UnifiedSearch = Class.extend({
|
|||
me.summary.append(section);
|
||||
});
|
||||
this.full_lists = Object.assign(this.full_lists, results_obj.lists);
|
||||
this.full_lists["All Results"] = this.summary;
|
||||
this.render_next_search(keywords);
|
||||
},
|
||||
|
||||
bind_events: function() {
|
||||
var me = this;
|
||||
this.results_area.on('scroll', function() {
|
||||
if(me.results_area.find('.all-results-link').length !== 0) {
|
||||
return;
|
||||
}
|
||||
var r = me.results_area.find('.module-section')[1];
|
||||
me.results_area.find('.module-section').each(function() {
|
||||
if(($(this).position().top < 120) && ($(this).position().top + $(this).height() > 120)) {
|
||||
var types = $(this).attr('data-type').split(',');
|
||||
me.sidelist.find('.list-link').removeClass('active');
|
||||
types.forEach(function(type) {
|
||||
me.sidelist.find('*[data-category="'+ type +'"]').addClass('active');
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
this.sidelist.find('.list-link').on('click', function() {
|
||||
me.set_sidelist_link_action($(this));
|
||||
this.sidebar.find('.list-link').on('click', function() {
|
||||
me.set_sidebar_link_action($(this));
|
||||
});
|
||||
this.results_area.find('.section-more').on('click', function() {
|
||||
var type = $(this).attr('data-category');
|
||||
me.sidelist.find('*[data-category="'+ type +'"]').trigger('click');
|
||||
me.sidebar.find('*[data-category="'+ type +'"]').trigger('click');
|
||||
return false;
|
||||
});
|
||||
this.results_area.find('.Help-result a').on('click', frappe.help.show_results);
|
||||
},
|
||||
|
||||
set_sidelist_link_action: function(link) {
|
||||
this.sidelist.find(".list-link").removeClass("active");
|
||||
this.sidelist.find(".list-link i").addClass("hide");
|
||||
set_sidebar_link_action: function(link) {
|
||||
var me = this;
|
||||
this.sidebar.find(".list-link").removeClass("active");
|
||||
link.addClass("active");
|
||||
link.find("i").removeClass("hide");
|
||||
var type = link.attr('data-category');
|
||||
this.results_area.empty().html(this.full_lists[type]);
|
||||
me.results_area.find('.module-section-link').first().focus();
|
||||
|
||||
this.results_area.find('.section-more').on('click', function() {
|
||||
var type = $(this).attr('data-category');
|
||||
me.sidebar.find('*[data-category="'+ type +'"]').trigger('click');
|
||||
return false;
|
||||
});
|
||||
|
||||
this.current_type = type;
|
||||
|
||||
this.set_back_link();
|
||||
this.set_list_more_link(type);
|
||||
this.results_area.find('.Help-result a').on('click', frappe.help.show_results);
|
||||
},
|
||||
|
||||
set_back_link: function() {
|
||||
|
|
@ -120,9 +167,8 @@ frappe.search.UnifiedSearch = Class.extend({
|
|||
|
||||
show_summary: function() {
|
||||
this.current_type = '';
|
||||
this.sidelist.find(".list-link i").addClass("hide");
|
||||
this.sidelist.find(".list-link").removeClass("active");
|
||||
this.sidelist.find(".list-link").first().addClass("active");
|
||||
this.sidebar.find(".list-link").removeClass("active");
|
||||
this.sidebar.find(".list-link").first().addClass("active");
|
||||
this.results_area.empty().html(this.summary);
|
||||
this.bind_events();
|
||||
},
|
||||
|
|
@ -141,7 +187,9 @@ frappe.search.UnifiedSearch = Class.extend({
|
|||
var me = this;
|
||||
var more_results = more_data[0];
|
||||
var more = more_data[1];
|
||||
this.results_area.find('.module-section-link').last().addClass('.current-last');
|
||||
this.results_area.find('.list-more').before(more_results);
|
||||
setTimeout(function() { me.results_area.find('.more-results').last().find('.module-section-link').first().focus(); }, 200);
|
||||
if(!more) {
|
||||
this.results_area.find('.list-more').hide();
|
||||
var no_of_results = this.results_area.find('.result').length;
|
||||
|
|
@ -166,34 +214,38 @@ frappe.search.UnifiedSearch = Class.extend({
|
|||
// More searches to go
|
||||
this.search_objects[this.current].build_results_object(this, keywords);
|
||||
} else {
|
||||
// If there's only one link in sidelist, there's no summary (show its full list)
|
||||
if(this.sidelist.find('.list-link').length === 1) {
|
||||
this.sidebar.append(this.sidelist);
|
||||
// If there's only one link in sidebar, there's no summary (show its full list)
|
||||
if(this.sidebar.find('.list-link').length === 1) {
|
||||
this.bind_events();
|
||||
this.sidelist.find('.list-link').trigger('click');
|
||||
this.sidebar.find('.list-link').trigger('click');
|
||||
this.results_area.find('.all-results-link').hide();
|
||||
|
||||
} else if (this.sidelist.find('.list-link').length === 0) {
|
||||
} else if (this.sidebar.find('.list-link').length === 0) {
|
||||
this.results_area.html('<p class="results-status text-muted" style="text-align: center;">'+
|
||||
'No results found for: '+ "'"+ keywords +"'" +'</p>');
|
||||
} else {
|
||||
this.sidebar.find('.search-sidelist').prepend('<li class="module-sidebar-item list-link"' +
|
||||
'data-category="All Results"><a><span>'+__("All Results")+'</span><i class="octicon octicon-chevron-right pull-right"' +
|
||||
'></a></li>');
|
||||
var list_types = this.get_all_list_types();
|
||||
if(list_types.indexOf(this.current_type) >= 0) {
|
||||
this.bind_events();
|
||||
this.sidelist.find('*[data-category="'+ this.current_type +'"]').trigger('click');
|
||||
} else {
|
||||
this.show_summary();
|
||||
if(list_types.indexOf(this.current_type) === -1) {
|
||||
this.current_type = "All Results";
|
||||
}
|
||||
this.bind_events();
|
||||
this.sidebar.find('*[data-category="'+ this.current_type +'"]').trigger('click');
|
||||
this.bind_events();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
get_all_list_types: function() {
|
||||
var types = [];
|
||||
this.sidelist.find('.list-link').each(function() {
|
||||
this.sidebar.find('.list-link').each(function() {
|
||||
types.push($(this).attr('data-category'));
|
||||
});
|
||||
return types;
|
||||
}
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
|
|
@ -244,8 +296,9 @@ frappe.search.GlobalSearch = Class.extend({
|
|||
},
|
||||
|
||||
make_sidelist_item: function(type) {
|
||||
var sidelist_item = '<li class="strong module-sidebar-item list-link" data-search="{0}"' +
|
||||
'data-category="{1}"><a><span>{1}</span><i class="fa fa-chevron-right pull-right hide"></a></li>';
|
||||
var sidelist_item = '<li class="module-sidebar-item list-link" data-search="{0}"' +
|
||||
'data-category="{1}"><a><span>{1}</span><i class="octicon octicon-chevron-right pull-right"' +
|
||||
'></a></li>';
|
||||
return $(__(sidelist_item, [this.search_type, type]));
|
||||
},
|
||||
|
||||
|
|
@ -303,7 +356,7 @@ frappe.search.GlobalSearch = Class.extend({
|
|||
|
||||
make_result_item: function(type, result) {
|
||||
var link_html = '<div class="result '+ type +'-result">' +
|
||||
'<a href="{0}" class="module-section-link small">{1}</a>' +
|
||||
'<b><a href="{0}" class="module-section-link small">{1}</a></b>' +
|
||||
'<p class="small">{2}</p>' +
|
||||
'</div>';
|
||||
var formatted_result = this.format_result(result);
|
||||
|
|
@ -324,7 +377,7 @@ frappe.search.GlobalSearch = Class.extend({
|
|||
if(part.toLowerCase().indexOf(keywords) !== -1) {
|
||||
var colon_index = part.indexOf(':');
|
||||
part = '<span class="field-name text-muted">' +
|
||||
part.slice(0, colon_index + 1) + '</span>' +
|
||||
me.bold_keywords(part.slice(0, colon_index + 1), keywords) + '</span>' +
|
||||
me.bold_keywords(part.slice(colon_index + 1), keywords);
|
||||
content += part + ', ';
|
||||
}
|
||||
|
|
@ -349,8 +402,8 @@ frappe.search.GlobalSearch = Class.extend({
|
|||
results_col.append(me.make_result_item(type, result));
|
||||
});
|
||||
if(results.length > this.section_length) {
|
||||
results_col.append('<button class="btn btn-default btn-xs text-muted section-more" data-category="'
|
||||
+ type + '" style="margin-top:10px">More...</button>');
|
||||
results_col.append('<a href="#" class="section-more small" data-category="'
|
||||
+ type + '" style="margin-top:10px">'+__("More...")+'</a>');
|
||||
|
||||
}
|
||||
return results_section;
|
||||
|
|
@ -394,8 +447,8 @@ frappe.search.GlobalSearch = Class.extend({
|
|||
results_col.append(me.make_result_item(type, result));
|
||||
});
|
||||
if(more) {
|
||||
results_col.append('<button class="btn btn-default btn-xs text-muted list-more" data-search="'+
|
||||
this.search_type +'" data-category="'+ type + '" style="margin-top:10px"> More...</button>');
|
||||
results_col.append('<a href="#" class="list-more small" data-search="'+ this.search_type +
|
||||
'" data-category="'+ type + '" style="margin-top:10px">'+__("More...")+'</a>');
|
||||
}
|
||||
return results_list;
|
||||
},
|
||||
|
|
@ -484,7 +537,7 @@ frappe.search.GlobalSearch = Class.extend({
|
|||
value: __("{0}: {1}", [__(data.doctype), data.name]),
|
||||
route: ["Form", data.doctype, data.name],
|
||||
match: data.doctype,
|
||||
index: 41,
|
||||
index: 40,
|
||||
default: "Global",
|
||||
description: me.get_finds(data.content, keywords).slice(0,86) + '...'
|
||||
}
|
||||
|
|
@ -503,15 +556,9 @@ frappe.search.NavSearch = frappe.search.GlobalSearch.extend({
|
|||
set_types: function() {
|
||||
var me = this;
|
||||
this.section_length = 4;
|
||||
this.awesome_bar = new frappe.search.AwesomeBar();
|
||||
this.nav_results = {
|
||||
"Search in ...": me.awesome_bar.make_search_in_list(me.keywords),
|
||||
"Lists": me.awesome_bar.get_doctypes(me.keywords),
|
||||
"Reports": me.awesome_bar.get_reports(me.keywords),
|
||||
"Pages": me.awesome_bar.get_pages(me.keywords),
|
||||
"Modules": me.awesome_bar.get_modules(me.keywords)
|
||||
}
|
||||
var types = ["Search in ...", "Lists", "Reports", "Pages", "Modules"];
|
||||
|
||||
this.set_nav_results(me.keywords);
|
||||
var types = ["Lists", "Reports", "Pages", "Modules"];
|
||||
types.forEach(function(type) {
|
||||
if(me.nav_results[type].length > 0) {
|
||||
me.types.push(type);
|
||||
|
|
@ -526,6 +573,20 @@ frappe.search.NavSearch = frappe.search.GlobalSearch.extend({
|
|||
}
|
||||
},
|
||||
|
||||
set_nav_results: function(keywords) {
|
||||
var me = this;
|
||||
this.awesome_bar = new frappe.search.AwesomeBar();
|
||||
var compare = function(a, b) {
|
||||
return a.index - b.index;
|
||||
}
|
||||
this.nav_results = {
|
||||
"Lists": me.awesome_bar.get_doctypes(keywords).sort(compare),
|
||||
"Reports": me.awesome_bar.get_reports(keywords).sort(compare),
|
||||
"Pages": me.awesome_bar.get_pages(keywords).sort(compare),
|
||||
"Modules": me.awesome_bar.get_modules(keywords).sort(compare)
|
||||
}
|
||||
},
|
||||
|
||||
get_results: function() {
|
||||
var me = this;
|
||||
this.types.forEach(function(type) {
|
||||
|
|
@ -563,7 +624,16 @@ frappe.search.NavSearch = frappe.search.GlobalSearch.extend({
|
|||
this.make_more_list(type, results, more)
|
||||
},
|
||||
|
||||
make_path: function(route) {
|
||||
path = '#';
|
||||
route.forEach(function(r) {
|
||||
path += r + '/';
|
||||
});
|
||||
return path.slice(0, -1);
|
||||
},
|
||||
|
||||
make_result_item: function(type, result) {
|
||||
var me = this;
|
||||
if(!result.subtypes) {
|
||||
var link_html = '<div class="result '+ type +'-result single-link">' +
|
||||
'<a href="{0}" class="module-section-link small">{1}</a>' +
|
||||
|
|
@ -571,30 +641,20 @@ frappe.search.NavSearch = frappe.search.GlobalSearch.extend({
|
|||
return this.make_result_link(type, result, link_html);
|
||||
|
||||
} else {
|
||||
var result_div = $('<div class="result '+ type +'-result single-link"></div>');
|
||||
var button_html = '<button class="btn btn-default btn-xs text-muted result-subtype"'+
|
||||
'>{0}</button>'
|
||||
var result_div = $('<div class="result '+ type +'-result single-link result-with-subtype"></div>');
|
||||
result.subtypes.forEach(function(s) {
|
||||
if(["Gantt", "Report", "Calendar"].indexOf(s.type) !== -1) {
|
||||
var button = $(__(button_html, [s.type]));
|
||||
button.on('click', function() {
|
||||
if(s.route_options) {
|
||||
frappe.route_options = s.route_options;
|
||||
}
|
||||
frappe.set_route(s.route);
|
||||
return false;
|
||||
});
|
||||
var button_html = '<button class="btn btn-default btn-xs result-subtype"'+
|
||||
'><a class="text-muted" href="{0}">{1}</a></button>';
|
||||
var button = $(__(button_html, [me.make_path(s.route), s.type]));
|
||||
result_div.append(button);
|
||||
} else {
|
||||
title_link_html = '<a href="{0}" class="module-section-link small">{1}</a>';
|
||||
var link = $(__(title_link_html, ['#', result.title + ' ' + s.type]));
|
||||
link.on('click', function() {
|
||||
if(s.route_options) {
|
||||
frappe.route_options = s.route_options;
|
||||
}
|
||||
frappe.set_route(s.route);
|
||||
return false;
|
||||
});
|
||||
title_link_html = '<a href="{0}" class="module-section-link small result-main">{1}</a>';
|
||||
if(s.type === "List") {
|
||||
var link = $(__(title_link_html, [me.make_path(s.route), result.title]));
|
||||
} else {
|
||||
var link = $(__(title_link_html, [me.make_path(s.route), result.title + ' ' + s.type]));
|
||||
}
|
||||
result_div.append(link);
|
||||
}
|
||||
})
|
||||
|
|
@ -605,8 +665,9 @@ frappe.search.NavSearch = frappe.search.GlobalSearch.extend({
|
|||
},
|
||||
|
||||
make_result_link: function(type, result, link_html) {
|
||||
var me = this;
|
||||
if(!result.onclick) {
|
||||
var link = $(__(link_html, ['#', result.label]));
|
||||
var link = $(__(link_html, [me.make_path(result.route), result.label]));
|
||||
link.on('click', function() {
|
||||
if(result.route_options) {
|
||||
frappe.route_options = result.route_options;
|
||||
|
|
@ -668,8 +729,8 @@ frappe.search.NavSearch = frappe.search.GlobalSearch.extend({
|
|||
results_column.append(me.make_result_item(type, result));
|
||||
});
|
||||
if(results.length > this.section_length) {
|
||||
results_column.append('<button class="btn btn-default btn-xs text-muted section-more" data-category="'
|
||||
+ type + '" style="margin-top:10px">More...</button>');
|
||||
results_column.append('<a href="#" class="section-more small" data-category="'
|
||||
+ type + '" style="margin-top:10px">'+__("More...")+'</a>');
|
||||
}
|
||||
return results_column;
|
||||
}
|
||||
|
|
@ -681,6 +742,7 @@ frappe.search.HelpSearch = frappe.search.GlobalSearch.extend({
|
|||
},
|
||||
|
||||
set_types: function() {
|
||||
this.section_length = 4;
|
||||
this.types = [this.search_type];
|
||||
this.sidelist = this.make_sidelist();
|
||||
this.get_result_set(this.types[0]);
|
||||
|
|
@ -688,9 +750,9 @@ frappe.search.HelpSearch = frappe.search.GlobalSearch.extend({
|
|||
|
||||
make_sidelist: function() {
|
||||
var sidelist = [];
|
||||
var sidelist_item = '<li class="strong module-sidebar-item list-link help-link" '+
|
||||
var sidelist_item = '<li class="module-sidebar-item list-link help-link" '+
|
||||
'data-search="'+ this.search_type + '" data-category="'+ this.search_type + '"><a><span>'+
|
||||
this.search_type +'</span><i class="fa fa-chevron-right pull-right hide"></a></li>';
|
||||
this.search_type +'</span><i class="octicon octicon-chevron-right pull-right"></a></li>';
|
||||
sidelist.push(sidelist_item);
|
||||
return sidelist;
|
||||
},
|
||||
|
|
@ -719,14 +781,42 @@ frappe.search.HelpSearch = frappe.search.GlobalSearch.extend({
|
|||
this.lists[type] = this.make_full_list(type, results, more);
|
||||
},
|
||||
|
||||
make_section: function(type, results) {
|
||||
var me = this;
|
||||
var results_section = $('<div class="row module-section" data-type="'+type+'">'+
|
||||
'<div class="col-sm-12 module-section-column">' +
|
||||
'<div class="h4 section-head">'+type+'</div>' +
|
||||
'<div class="section-body"></div>'+
|
||||
'</div></div>');
|
||||
var results_col = results_section.find('.module-section-column');
|
||||
results.slice(0, this.section_length).forEach(function(result) {
|
||||
results_col.append(me.make_condensed_result_item(type, result));
|
||||
});
|
||||
if(results.length > this.section_length) {
|
||||
results_col.append('<a href="#" class="section-more small" data-category="'
|
||||
+ type + '" style="margin-top:10px">'+__("More...")+'</a>');
|
||||
|
||||
}
|
||||
return results_section;
|
||||
},
|
||||
|
||||
make_condensed_result_item: function(type, result) {
|
||||
var me = this;
|
||||
var link_html = '<div class="result '+ type +'-result">' +
|
||||
'<b><a href="#" data-path="{0}" class="module-section-link small">{1}</a></b>' +
|
||||
'<p class="small"></p>' +
|
||||
'</div>';
|
||||
var link = $(__(link_html, [result[2], result[0]]));
|
||||
return link;
|
||||
},
|
||||
|
||||
make_result_item: function(type, result) {
|
||||
var me = this;
|
||||
var link_html = '<div class="result '+ type +'-result">' +
|
||||
'<a href="#" data-path="{0}" class="module-section-link small">{1}</a>' +
|
||||
'<b><a href="#" data-path="{0}" class="module-section-link small">{1}</a></b>' +
|
||||
'<p class="small">{2}</p>' +
|
||||
'</div>';
|
||||
var link = $(__(link_html, [result[2], result[0], result[1]]));
|
||||
link.find('a').on('click', frappe.help.show_results);
|
||||
return link;
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<div class="input-group has-feedback search-header" style="margin:5px -5px;">
|
||||
<span class="input-group-addon">
|
||||
<i class="glyphicon glyphicon-search"></i>
|
||||
<i class="octicon octicon-search"></i>
|
||||
</span>
|
||||
<input type="text" class="form-control search-input" placeholder="Search for...">
|
||||
<input type="text" class="form-control search-input" placeholder="Search for ...">
|
||||
<span class="input-group-addon"><a type="button" class="close" data-dismiss="modal" aria-hidden="true">×</a></span>
|
||||
</div>
|
||||
|
|
@ -16,9 +16,8 @@ frappe.ui.toolbar.Toolbar = Class.extend({
|
|||
this.awesome_bar.setup("#navbar-search");
|
||||
this.awesome_bar.setup("#modal-search");
|
||||
|
||||
this.search = new frappe.search.UnifiedSearch();
|
||||
this.help = new frappe.search.HelpSearch();
|
||||
this.search.setup();
|
||||
this.search = this.awesome_bar.search;
|
||||
this.help = this.awesome_bar.help;
|
||||
|
||||
$(document).on("notification-update", function() {
|
||||
frappe.ui.notifications.update_notifications();
|
||||
|
|
|
|||
|
|
@ -563,21 +563,59 @@ textarea.form-control {
|
|||
}
|
||||
|
||||
.layout-side-section {
|
||||
.module-sidebar-nav {
|
||||
margin-top: 0px;
|
||||
}
|
||||
.help-link {
|
||||
padding-top: 20px;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.nav > li > a {
|
||||
padding-left: 20px;
|
||||
.nav {
|
||||
li a {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding-left: 20px;
|
||||
|
||||
i {
|
||||
visibility: hidden;
|
||||
}
|
||||
}
|
||||
|
||||
.active i {
|
||||
visibility: visible;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.results-area {
|
||||
a {
|
||||
color: #5E64FF;
|
||||
.search-intro-placeholder {
|
||||
color: #d4d9dd;
|
||||
height: inherit;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
span {
|
||||
text-align: center;
|
||||
|
||||
i {
|
||||
font-size: 120px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
p {
|
||||
font-size: 20px;
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// a {
|
||||
// color: #5E64FF;
|
||||
// }
|
||||
|
||||
.single-link a {
|
||||
color: #36414c;
|
||||
}
|
||||
|
|
@ -597,15 +635,19 @@ textarea.form-control {
|
|||
|
||||
.full-list {
|
||||
.result {
|
||||
border-bottom: 1px solid #d1d8dd;
|
||||
margin-top: 10px;
|
||||
margin-top: 15px;
|
||||
|
||||
.result-subtype{
|
||||
.result-subtype {
|
||||
float: right;
|
||||
margin-left: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
.result-with-subtype {
|
||||
border-bottom: 1px solid #d1d8dd;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.section-head {
|
||||
margin-bottom: 25px;
|
||||
}
|
||||
|
|
@ -646,6 +688,12 @@ textarea.form-control {
|
|||
margin: 30px 0px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 600px) {
|
||||
.results-area .back-link {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.result {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue