2013-11-20 07:29:58 +00:00
|
|
|
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
|
2013-08-05 09:29:54 +00:00
|
|
|
// License: GNU General Public License v3. See license.txt
|
2012-02-23 07:05:32 +00:00
|
|
|
|
2012-04-17 07:10:37 +00:00
|
|
|
pscript['onload_Sales Browser'] = function(wrapper){
|
2013-05-23 10:33:49 +00:00
|
|
|
wn.ui.make_app_page({
|
|
|
|
parent: wrapper,
|
|
|
|
})
|
|
|
|
|
2013-04-19 07:31:32 +00:00
|
|
|
wrapper.appframe.add_module_icon("Selling")
|
2012-11-13 11:14:27 +00:00
|
|
|
|
2013-11-13 11:25:38 +00:00
|
|
|
wrapper.appframe.set_title_right('Refresh', function() {
|
2012-04-17 07:10:37 +00:00
|
|
|
wrapper.make_tree();
|
2013-11-13 11:25:38 +00:00
|
|
|
});
|
2012-04-17 07:10:37 +00:00
|
|
|
|
2013-05-23 10:33:49 +00:00
|
|
|
|
|
|
|
$(wrapper)
|
|
|
|
.find(".layout-side-section")
|
2013-09-26 21:24:15 +00:00
|
|
|
.html('<div class="text-muted">'+
|
|
|
|
wn._('Click on a link to get options to expand get options ') +
|
|
|
|
wn._('Add') + ' / ' + wn._('Edit') + ' / '+ wn._('Delete') + '.</div>')
|
2013-05-23 10:33:49 +00:00
|
|
|
|
2012-04-17 07:10:37 +00:00
|
|
|
wrapper.make_tree = function() {
|
|
|
|
var ctype = wn.get_route()[1] || 'Territory';
|
2013-07-29 14:00:39 +00:00
|
|
|
return wn.call({
|
2013-12-12 13:42:19 +00:00
|
|
|
method: 'erpnext.selling.page.sales_browser.sales_browser.get_children',
|
2012-12-12 10:56:39 +00:00
|
|
|
args: {ctype: ctype},
|
|
|
|
callback: function(r) {
|
|
|
|
var root = r.message[0]["value"];
|
2013-05-23 10:33:49 +00:00
|
|
|
erpnext.sales_chart = new erpnext.SalesChart(ctype, root,
|
|
|
|
$(wrapper)
|
|
|
|
.find(".layout-main-section")
|
|
|
|
.css({
|
|
|
|
"min-height": "300px",
|
|
|
|
"padding-bottom": "25px"
|
|
|
|
}));
|
2012-12-12 10:56:39 +00:00
|
|
|
}
|
|
|
|
});
|
2012-04-17 07:10:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wrapper.make_tree();
|
|
|
|
}
|
|
|
|
|
|
|
|
pscript['onshow_Sales Browser'] = function(wrapper){
|
|
|
|
// set route
|
|
|
|
var ctype = wn.get_route()[1] || 'Territory';
|
2012-07-12 04:24:43 +00:00
|
|
|
|
2012-11-13 11:14:27 +00:00
|
|
|
wrapper.appframe.set_title(ctype+' Tree')
|
2012-04-17 07:10:37 +00:00
|
|
|
|
|
|
|
if(erpnext.sales_chart && erpnext.sales_chart.ctype != ctype) {
|
|
|
|
wrapper.make_tree();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
erpnext.SalesChart = Class.extend({
|
2013-05-23 10:33:49 +00:00
|
|
|
init: function(ctype, root, parent) {
|
|
|
|
$(parent).empty();
|
2012-04-17 07:10:37 +00:00
|
|
|
var me = this;
|
|
|
|
me.ctype = ctype;
|
|
|
|
this.tree = new wn.ui.Tree({
|
2013-05-23 10:33:49 +00:00
|
|
|
parent: $(parent),
|
2012-12-12 10:56:39 +00:00
|
|
|
label: root,
|
2012-04-17 07:10:37 +00:00
|
|
|
args: {ctype: ctype},
|
2013-12-12 13:42:19 +00:00
|
|
|
method: 'erpnext.selling.page.sales_browser.sales_browser.get_children',
|
2012-04-17 07:10:37 +00:00
|
|
|
click: function(link) {
|
|
|
|
if(me.cur_toolbar)
|
|
|
|
$(me.cur_toolbar).toggle(false);
|
|
|
|
|
|
|
|
if(!link.toolbar)
|
|
|
|
me.make_link_toolbar(link);
|
|
|
|
|
|
|
|
if(link.toolbar) {
|
|
|
|
me.cur_toolbar = link.toolbar;
|
|
|
|
$(me.cur_toolbar).toggle(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.tree.rootnode.$a
|
2012-12-12 10:56:39 +00:00
|
|
|
.data('node-data', {value: root, expandable:1})
|
2012-04-17 07:10:37 +00:00
|
|
|
.click();
|
|
|
|
},
|
|
|
|
make_link_toolbar: function(link) {
|
|
|
|
var data = $(link).data('node-data');
|
|
|
|
if(!data) return;
|
|
|
|
|
|
|
|
link.toolbar = $('<span class="tree-node-toolbar"></span>').insertAfter(link);
|
|
|
|
|
|
|
|
// edit
|
2012-08-24 06:45:44 +00:00
|
|
|
var node_links = [];
|
|
|
|
|
2012-12-06 06:39:52 +00:00
|
|
|
if (wn.model.can_read(this.ctype)) {
|
2013-09-26 21:24:15 +00:00
|
|
|
node_links.push('<a onclick="erpnext.sales_chart.open();">'+wn._('Edit')+'</a>');
|
2012-08-24 06:45:44 +00:00
|
|
|
}
|
2012-04-17 07:10:37 +00:00
|
|
|
|
|
|
|
if(data.expandable) {
|
2012-08-24 06:45:44 +00:00
|
|
|
if (wn.boot.profile.can_create.indexOf(this.ctype) !== -1 ||
|
|
|
|
wn.boot.profile.in_create.indexOf(this.ctype) !== -1) {
|
2013-09-26 21:24:15 +00:00
|
|
|
node_links.push('<a onclick="erpnext.sales_chart.new_node();">' + wn._('Add Child') + '</a>');
|
2012-08-24 06:45:44 +00:00
|
|
|
}
|
2012-04-17 07:10:37 +00:00
|
|
|
}
|
2012-12-06 06:39:52 +00:00
|
|
|
|
|
|
|
if (wn.model.can_write(this.ctype)) {
|
2013-09-26 21:24:15 +00:00
|
|
|
node_links.push('<a onclick="erpnext.sales_chart.rename()">' + wn._('Rename') + '</a>');
|
2012-12-06 06:39:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (wn.model.can_delete(this.ctype)) {
|
2013-09-26 21:24:15 +00:00
|
|
|
node_links.push('<a onclick="erpnext.sales_chart.delete()">' + wn._('Delete') + '</a>');
|
2012-12-06 06:39:52 +00:00
|
|
|
};
|
2012-08-24 06:45:44 +00:00
|
|
|
|
|
|
|
link.toolbar.append(node_links.join(" | "));
|
2012-04-17 07:10:37 +00:00
|
|
|
},
|
|
|
|
new_node: function() {
|
|
|
|
var me = this;
|
2013-07-22 11:45:01 +00:00
|
|
|
|
|
|
|
var fields = [
|
|
|
|
{fieldtype:'Data', fieldname: 'name_field',
|
|
|
|
label:'New ' + me.ctype + ' Name', reqd:true},
|
|
|
|
{fieldtype:'Select', fieldname:'is_group', label:'Group Node', options:'No\nYes',
|
2013-09-26 21:24:15 +00:00
|
|
|
description: wn._("Further nodes can be only created under 'Group' type nodes")},
|
2013-07-22 11:45:01 +00:00
|
|
|
{fieldtype:'Button', fieldname:'create_new', label:'Create New' }
|
|
|
|
]
|
|
|
|
|
|
|
|
if(me.ctype == "Sales Person") {
|
|
|
|
fields.splice(-1, 0, {fieldtype:'Link', fieldname:'employee', label:'Employee',
|
2013-09-26 21:24:15 +00:00
|
|
|
options:'Employee', description: wn._("Please enter Employee Id of this sales parson")});
|
2013-07-22 11:45:01 +00:00
|
|
|
}
|
|
|
|
|
2012-04-17 07:10:37 +00:00
|
|
|
// the dialog
|
|
|
|
var d = new wn.ui.Dialog({
|
2013-09-26 21:24:15 +00:00
|
|
|
title: wn._('New ') + wn._(me.ctype),
|
2013-07-22 11:45:01 +00:00
|
|
|
fields: fields
|
2012-04-17 07:10:37 +00:00
|
|
|
})
|
|
|
|
|
2012-12-06 06:39:52 +00:00
|
|
|
d.set_value("is_group", "No");
|
2012-04-17 07:10:37 +00:00
|
|
|
// create
|
|
|
|
$(d.fields_dict.create_new.input).click(function() {
|
|
|
|
var btn = this;
|
|
|
|
$(btn).set_working();
|
|
|
|
var v = d.get_values();
|
|
|
|
if(!v) return;
|
|
|
|
|
|
|
|
var node = me.selected_node();
|
|
|
|
|
|
|
|
v.parent = node.data('label');
|
|
|
|
v.ctype = me.ctype;
|
|
|
|
|
2013-07-29 14:00:39 +00:00
|
|
|
return wn.call({
|
2013-12-12 13:42:19 +00:00
|
|
|
method: 'erpnext.selling.page.sales_browser.sales_browser.add_node',
|
2012-04-17 07:10:37 +00:00
|
|
|
args: v,
|
|
|
|
callback: function() {
|
|
|
|
$(btn).done_working();
|
|
|
|
d.hide();
|
|
|
|
node.trigger('reload');
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
d.show();
|
|
|
|
},
|
|
|
|
selected_node: function() {
|
|
|
|
return this.tree.$w.find('.tree-link.selected');
|
2012-12-06 06:39:52 +00:00
|
|
|
},
|
|
|
|
open: function() {
|
|
|
|
var node = this.selected_node();
|
|
|
|
wn.set_route("Form", this.ctype, node.data("label"));
|
|
|
|
},
|
|
|
|
rename: function() {
|
|
|
|
var node = this.selected_node();
|
|
|
|
wn.model.rename_doc(this.ctype, node.data('label'), function(new_name) {
|
|
|
|
node.data('label', new_name).find(".tree-label").html(new_name);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
delete: function() {
|
|
|
|
var node = this.selected_node();
|
|
|
|
wn.model.delete_doc(this.ctype, node.data('label'), function() {
|
|
|
|
node.parent().remove();
|
|
|
|
});
|
|
|
|
},
|
2012-05-07 12:30:57 +00:00
|
|
|
});
|