167 lines
4.2 KiB
JavaScript
Raw Normal View History

// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt
2012-02-23 12:35:32 +05:30
2015-01-29 18:09:11 +05:30
frappe.pages["Sales Browser"].on_page_load = function(wrapper){
var page = frappe.ui.make_app_page({
parent: wrapper,
2015-01-01 12:49:18 +05:30
single_column: true,
});
wrapper.page.add_menu_item(__('Refresh'), function() {
2012-04-17 12:40:37 +05:30
wrapper.make_tree();
});
2012-04-17 12:40:37 +05:30
wrapper.make_tree = function() {
2014-02-14 15:47:51 +05:30
var ctype = frappe.get_route()[1] || 'Territory';
return frappe.call({
method: 'erpnext.selling.page.sales_browser.sales_browser.get_children',
args: {ctype: ctype},
callback: function(r) {
var root = r.message[0]["value"];
erpnext.sales_chart = new erpnext.SalesChart(ctype, root, page,
2015-01-19 17:34:33 +05:30
page.main.css({
"min-height": "300px",
"padding-bottom": "25px"
}));
}
});
2012-04-17 12:40:37 +05:30
}
2012-04-17 12:40:37 +05:30
wrapper.make_tree();
}
2015-01-29 18:09:11 +05:30
frappe.pages['Sales Browser'].on_page_show = function(wrapper){
2012-04-17 12:40:37 +05:30
// set route
2014-02-14 15:47:51 +05:30
var ctype = frappe.get_route()[1] || 'Territory';
2012-07-12 09:54:43 +05:30
2014-12-23 17:56:47 +05:30
wrapper.page.set_title(__('{0} Tree',[__(ctype)]));
2012-04-17 12:40:37 +05:30
if(erpnext.sales_chart && erpnext.sales_chart.ctype != ctype) {
wrapper.make_tree();
}
frappe.breadcrumbs.add(frappe.breadcrumbs.last_module || "Selling");
2012-04-17 12:40:37 +05:30
};
erpnext.SalesChart = Class.extend({
init: function(ctype, root, page, parent) {
$(parent).empty();
2012-04-17 12:40:37 +05:30
var me = this;
me.ctype = ctype;
me.page = page;
2014-02-19 12:43:16 +05:30
me.can_read = frappe.model.can_read(this.ctype);
me.can_create = frappe.boot.user.can_create.indexOf(this.ctype) !== -1 ||
frappe.boot.user.in_create.indexOf(this.ctype) !== -1;
2014-02-19 12:43:16 +05:30
me.can_write = frappe.model.can_write(this.ctype);
me.can_delete = frappe.model.can_delete(this.ctype);
me.page.set_primary_action(__("New"), function() {
me.new_node();
}, "octicon octicon-plus");
2014-02-14 15:47:51 +05:30
this.tree = new frappe.ui.Tree({
parent: $(parent),
2014-09-10 15:36:53 +08:00
label: __(root),
2012-04-17 12:40:37 +05:30
args: {ctype: ctype},
method: 'erpnext.selling.page.sales_browser.sales_browser.get_children',
2014-02-19 12:43:16 +05:30
toolbar: [
{toggle_btn: true},
{
label:__("Edit"),
condition: function(node) {
2014-02-19 12:43:16 +05:30
return !node.root && me.can_read;
},
click: function(node) {
frappe.set_route("Form", me.ctype, node.label);
}
},
{
label:__("Add Child"),
condition: function(node) { return me.can_create && node.expandable; },
click: function(node) {
me.new_node();
},
btnClass: "hidden-xs"
2014-02-19 12:43:16 +05:30
},
{
label:__("Rename"),
condition: function(node) { return !node.root && me.can_write; },
click: function(node) {
frappe.model.rename_doc(me.ctype, node.label, function(new_name) {
node.$a.html(new_name);
});
},
btnClass: "hidden-xs"
2014-02-19 12:43:16 +05:30
},
{
label:__("Delete"),
condition: function(node) { return !node.root && me.can_delete; },
click: function(node) {
frappe.model.delete_doc(me.ctype, node.label, function() {
node.parent.remove();
});
},
btnClass: "hidden-xs"
2012-04-17 12:40:37 +05:30
}
2014-02-19 12:43:16 +05:30
]
2012-04-17 12:40:37 +05:30
});
},
new_node: function() {
var me = this;
var node = me.tree.get_selected_node();
if(!(node && node.expandable)) {
frappe.msgprint(__("Select a group node first."));
return;
}
var fields = [
{fieldtype:'Data', fieldname: 'name_field',
2014-09-11 08:37:49 +08:00
label:__('New {0} Name',[__(me.ctype)]), reqd:true},
2014-09-10 15:36:53 +08:00
{fieldtype:'Select', fieldname:'is_group', label:__('Group Node'), options:'No\nYes',
2015-01-01 12:49:18 +05:30
description: __("Further nodes can be only created under 'Group' type nodes")}
]
if(me.ctype == "Sales Person") {
2014-09-10 15:36:53 +08:00
fields.splice(-1, 0, {fieldtype:'Link', fieldname:'employee', label:__('Employee'),
2015-06-29 16:04:12 +05:30
options:'Employee', description: __("Please enter Employee Id of this sales person")});
}
2012-04-17 12:40:37 +05:30
// the dialog
2014-02-14 15:47:51 +05:30
var d = new frappe.ui.Dialog({
2014-09-10 15:36:53 +08:00
title: __('New {0}',[__(me.ctype)]),
fields: fields
})
2012-12-06 12:09:52 +05:30
d.set_value("is_group", "No");
2012-04-17 12:40:37 +05:30
// create
2015-01-01 12:49:18 +05:30
d.set_primary_action(__("Create New"), function() {
2012-04-17 12:40:37 +05:30
var btn = this;
var v = d.get_values();
if(!v) return;
2014-02-19 12:43:16 +05:30
var node = me.tree.get_selected_node();
2014-02-19 12:43:16 +05:30
v.parent = node.label;
2012-04-17 12:40:37 +05:30
v.ctype = me.ctype;
2014-02-14 15:47:51 +05:30
return frappe.call({
method: 'erpnext.selling.page.sales_browser.sales_browser.add_node',
2012-04-17 12:40:37 +05:30
args: v,
2014-03-06 14:45:02 +05:30
callback: function(r) {
if(!r.exc) {
d.hide();
if(node.expanded) {
2014-03-06 14:45:02 +05:30
node.toggle_node();
}
node.reload();
2014-03-06 14:45:02 +05:30
}
}
});
2012-04-17 12:40:37 +05:30
});
2015-01-01 12:49:18 +05:30
d.show();
2012-04-17 12:40:37 +05:30
},
});