Merge pull request #1284 from rmehta/gantt-calendar-fixes
[enhancement] fixes to style and commonified conditions for calendar and style
This commit is contained in:
commit
66f93373e2
4 changed files with 66 additions and 17 deletions
|
|
@ -9,6 +9,7 @@ import json
|
|||
|
||||
@frappe.whitelist()
|
||||
def update_event(args, field_map):
|
||||
"""Updates Event (called via calendar) based on passed `field_map`"""
|
||||
args = frappe._dict(json.loads(args))
|
||||
field_map = frappe._dict(json.loads(field_map))
|
||||
w = frappe.get_doc(args.doctype, args.name)
|
||||
|
|
@ -16,3 +17,18 @@ def update_event(args, field_map):
|
|||
w.set(field_map.end, args.get(field_map.end))
|
||||
w.save()
|
||||
|
||||
def get_event_conditions(doctype, filters=None):
|
||||
"""Returns SQL conditions with user permissions and filters for event queries"""
|
||||
from frappe.desk.reportview import build_match_conditions
|
||||
if not frappe.has_permission(doctype):
|
||||
frappe.throw(_("Not Permitted"), frappe.PermissionError)
|
||||
|
||||
conditions = build_match_conditions(doctype)
|
||||
conditions = conditions and (" and " + conditions) or ""
|
||||
if filters:
|
||||
filters = json.loads(filters)
|
||||
for key in filters:
|
||||
if filters[key]:
|
||||
conditions += " and " + key + ' = "' + filters[key].replace('"', '\"') + '"'
|
||||
|
||||
return conditions
|
||||
|
|
|
|||
|
|
@ -121,7 +121,8 @@ $.extend(frappe.meta, {
|
|||
if(fn==="owner") {
|
||||
return "Owner";
|
||||
} else {
|
||||
return this.get_docfield(dt, fn, dn).label || fn;
|
||||
var df = this.get_docfield(dt, fn, dn);
|
||||
return (df ? df.label : "") || fn;
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -124,6 +124,9 @@ frappe.views.Calendar = frappe.views.CalendarBase.extend({
|
|||
"important": {
|
||||
"color": "#FFDCDC"
|
||||
},
|
||||
"danger": {
|
||||
"color": "#FFDCDC"
|
||||
},
|
||||
"warning": {
|
||||
"color": "#FFE6BF",
|
||||
},
|
||||
|
|
@ -135,6 +138,9 @@ frappe.views.Calendar = frappe.views.CalendarBase.extend({
|
|||
},
|
||||
"inverse": {
|
||||
"color": "#D9F6FF"
|
||||
},
|
||||
"": {
|
||||
"color": "#F0F4F7"
|
||||
}
|
||||
},
|
||||
get_system_datetime: function(date) {
|
||||
|
|
@ -249,14 +255,12 @@ frappe.views.Calendar = frappe.views.CalendarBase.extend({
|
|||
|
||||
me.fix_end_date_for_event_render(d);
|
||||
|
||||
if(d.status) {
|
||||
if(me.style_map) {
|
||||
$.extend(d, me.styles[me.style_map[d.status]] || {});
|
||||
} else {
|
||||
$.extend(d, me.styles[frappe.utils.guess_style(d.status, "standard")]);
|
||||
}
|
||||
if(me.get_css_class) {
|
||||
$.extend(d, me.styles[me.get_css_class(d)] || {});
|
||||
} else if(me.style_map) {
|
||||
$.extend(d, me.styles[me.style_map[d.status]] || {});
|
||||
} else {
|
||||
$.extend(d, me.styles["standard"]);
|
||||
$.extend(d, me.styles[frappe.utils.guess_style(d.status, "standard")]);
|
||||
}
|
||||
d["textColor"] = "#36414C";
|
||||
})
|
||||
|
|
|
|||
|
|
@ -10,17 +10,19 @@ frappe.views.GanttFactory = frappe.views.Factory.extend({
|
|||
frappe.require('assets/frappe/js/lib/jQuery.Gantt/css/style.css');
|
||||
frappe.require('assets/frappe/js/lib/jQuery.Gantt/js/jquery.fn.gantt.js');
|
||||
|
||||
frappe.model.with_doctype(route[1], function() {
|
||||
this.doctype = route[1];
|
||||
|
||||
frappe.model.with_doctype(this.doctype, function() {
|
||||
var page = me.make_page();
|
||||
$(page).on("show", function() {
|
||||
page.ganttview.set_filters_from_route_options();
|
||||
});
|
||||
|
||||
var options = {
|
||||
doctype: route[1],
|
||||
doctype: me.doctype,
|
||||
parent: page
|
||||
};
|
||||
$.extend(options, frappe.views.calendar[route[1]] || {});
|
||||
$.extend(options, frappe.views.calendar[me.doctype] || {});
|
||||
|
||||
page.ganttview = new frappe.views.Gantt(options);
|
||||
});
|
||||
|
|
@ -47,10 +49,14 @@ frappe.views.Gantt = frappe.views.CalendarBase.extend({
|
|||
function() { me.refresh(); }, "icon-refresh")
|
||||
|
||||
this.page.add_field({fieldtype:"Date", label:"From",
|
||||
fieldname:"start", "default": frappe.datetime.month_start(), input_css: {"z-index": 3}});
|
||||
fieldname:"start", "default": frappe.datetime.month_start(),
|
||||
change: function() { me.refresh(); },
|
||||
input_css: {"z-index": 3}});
|
||||
|
||||
this.page.add_field({fieldtype:"Date", label:"To",
|
||||
fieldname:"end", "default": frappe.datetime.month_end(), input_css: {"z-index": 3}});
|
||||
fieldname:"end", "default": frappe.datetime.month_end(),
|
||||
change: function() { me.refresh(); },
|
||||
input_css: {"z-index": 3}});
|
||||
|
||||
this.add_filters();
|
||||
this.wrapper = $("<div style='position:relative;z-index:1;'></div>").appendTo(this.page.main);
|
||||
|
|
@ -98,6 +104,21 @@ frappe.views.Gantt = frappe.views.CalendarBase.extend({
|
|||
// projects
|
||||
$.each(r.message, function(i,v) {
|
||||
|
||||
v["title"] = v[me.field_map["title"]];
|
||||
|
||||
// description
|
||||
v.desc = v.title
|
||||
+ (v.name ? ("<br>" + v.name) : "");
|
||||
|
||||
$.each(v, function(key, value) {
|
||||
if(!in_list(["name", "title", me.field_map["title"], "desc"], key) && value) {
|
||||
var label = frappe.meta.get_label(me.doctype, key);
|
||||
if(label) {
|
||||
v.desc += "<br>" + label + ": " + value;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// standardize values
|
||||
$.each(me.field_map, function(target, source) {
|
||||
v[target] = v[source];
|
||||
|
|
@ -108,13 +129,22 @@ frappe.views.Gantt = frappe.views.CalendarBase.extend({
|
|||
v.end.setHours(v.end.getHours() + 1);
|
||||
}
|
||||
|
||||
// class
|
||||
if(me.style_map) {
|
||||
v.cssClass = me.style_map[v.status]
|
||||
} else if(me.get_css_class) {
|
||||
v.cssClass = me.get_css_class(v);
|
||||
} else {
|
||||
v.cssClass = frappe.utils.guess_style(v.status, "standard")
|
||||
}
|
||||
|
||||
if(v.start && v.end) {
|
||||
source.push({
|
||||
name: v.title,
|
||||
desc: v.status,
|
||||
values: [{
|
||||
name: v.title,
|
||||
desc: v.title + "<br>" + (v.status || ""),
|
||||
desc: v.desc,
|
||||
from: '/Date('+moment(v.start).format("X")+'000)/',
|
||||
to: '/Date('+moment(v.end).format("X")+'000)/',
|
||||
customClass: {
|
||||
|
|
@ -123,9 +153,7 @@ frappe.views.Gantt = frappe.views.CalendarBase.extend({
|
|||
'info':'ganttBlue',
|
||||
'success':'ganttGreen',
|
||||
'':'ganttGray'
|
||||
}[me.style_map ?
|
||||
me.style_map[v.status] :
|
||||
frappe.utils.guess_style(v.status, "standard")],
|
||||
}[v.cssClass],
|
||||
dataObj: v
|
||||
}]
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue