From 434f2d47949191b5e5a5431dd2e7b98ae893f22a Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Wed, 19 Feb 2014 12:28:56 +0530 Subject: [PATCH] more fixes to tree --- frappe/public/css/tree.css | 1 - frappe/public/js/frappe/translate.js | 3 +- frappe/public/js/frappe/ui/tree.js | 38 ++++++++++++++++--- .../page/sitemap_browser/sitemap_browser.js | 7 +--- .../page/sitemap_browser/sitemap_browser.py | 6 ++- 5 files changed, 39 insertions(+), 16 deletions(-) diff --git a/frappe/public/css/tree.css b/frappe/public/css/tree.css index 3af785d671..3abad3db25 100644 --- a/frappe/public/css/tree.css +++ b/frappe/public/css/tree.css @@ -2,7 +2,6 @@ list-style: none; } .tree ul { - margin-top: 2px; } .tree-link { cursor: pointer; diff --git a/frappe/public/js/frappe/translate.js b/frappe/public/js/frappe/translate.js index 8dfffa6473..d40310de02 100644 --- a/frappe/public/js/frappe/translate.js +++ b/frappe/public/js/frappe/translate.js @@ -7,4 +7,5 @@ frappe._ = function(txt, replace) { if(!txt) return txt; if(typeof(txt) != "string") return txt; return frappe._messages[txt.replace(/\n/g, "")] || txt; -}; \ No newline at end of file +}; +window.__ = frappe._ \ No newline at end of file diff --git a/frappe/public/js/frappe/ui/tree.js b/frappe/public/js/frappe/ui/tree.js index 6d97e17c82..12006a8f50 100644 --- a/frappe/public/js/frappe/ui/tree.js +++ b/frappe/public/js/frappe/ui/tree.js @@ -14,7 +14,12 @@ frappe.ui.Tree = Class.extend({ parent: this.$w, label: this.label, parent_label: null, - expandable: true + expandable: true, + root: true, + data: { + value: this.label, + expandable: true + } }); this.rootnode.toggle(); }, @@ -45,7 +50,7 @@ frappe.ui.TreeNode = Class.extend({ make: function() { var me = this; this.$a = $('') - .click(function() { + .click(function(event) { me.tree.selected_node = me; if(me.tree.toolbar) { me.show_toolbar(); @@ -69,12 +74,17 @@ frappe.ui.TreeNode = Class.extend({ }, make_icon: function() { // label with icon + var me= this; var icon_html = ''; if(this.expandable) { icon_html = ''; } $(icon_html + ' ' + this.label + ""). appendTo(this.$a); + + this.$a.find('i').click(function() { + setTimeout(function() { me.toolbar.find(".btn-expand").click(); }, 100); + }); }, toggle: function(callback) { if(this.expandable && this.tree.method && !this.loaded) { @@ -97,12 +107,28 @@ frappe.ui.TreeNode = Class.extend({ var me = this; this.toolbar = $('').insertAfter(this.$a); - $.each(this.tree.toolbar, function(i, d) { - $("") - .html(d.label) + $.each(this.tree.toolbar, function(i, item) { + if(item.toggle_btn) { + item = { + condition: function() { return me.expandable; }, + get_label: function() { return me.expanded ? __("Collapse") : __("Expand") }, + click:function(node, btn) { + node.toggle(function() { + $(btn).html(node.expanded ? __("Collapse") : __("Expand")); + }); + }, + btnClass: "btn-expand" + } + } + if(item.condition) { + if(!item.condition(me)) return; + } + var link = $("") + .html(item.get_label ? item.get_label() : item.label) .appendTo(me.toolbar) - .click(function() { d.click(me, this); return false; }); + .click(function() { item.click(me, this); return false; }); + if(item.btnClass) link.addClass(item.btnClass); }) }, diff --git a/frappe/website/page/sitemap_browser/sitemap_browser.js b/frappe/website/page/sitemap_browser/sitemap_browser.js index 5eded11605..4b5491aced 100644 --- a/frappe/website/page/sitemap_browser/sitemap_browser.js +++ b/frappe/website/page/sitemap_browser/sitemap_browser.js @@ -39,12 +39,7 @@ frappe.website.SitemapBrowser = Class.extend({ method: 'frappe.website.page.sitemap_browser.sitemap_browser.get_children', toolbar: [ { - label:frappe._("Expand"), - click:function(node, btn) { - node.toggle(function() { - $(btn).html(node.expanded ? frappe._("Collapse") : frappe._("Expand")); - }); - } + toggle_btn: true, }, { label: frappe._("Update Parent"), diff --git a/frappe/website/page/sitemap_browser/sitemap_browser.py b/frappe/website/page/sitemap_browser/sitemap_browser.py index 5de66247bc..1a3a39f125 100644 --- a/frappe/website/page/sitemap_browser/sitemap_browser.py +++ b/frappe/website/page/sitemap_browser/sitemap_browser.py @@ -13,8 +13,10 @@ def get_children(parent=None): if parent=="Sitemap": parent = "" - return frappe.conn.sql("""select name as value, 1 as expandable from `tabWebsite Sitemap` where - ifnull(parent_website_sitemap, '')=%s and idx is not null order by -idx desc""", parent, as_dict=True) + return frappe.conn.sql("""select name as value, 1 as expandable, ref_doctype, docname + from `tabWebsite Sitemap` where + ifnull(parent_website_sitemap, '')=%s + and idx is not null order by -idx desc""", parent, as_dict=True) @frappe.whitelist() def move(name, up_or_down):