[ui] [listviews] commonified indicators
This commit is contained in:
parent
02f789c81d
commit
b3254acf1b
8 changed files with 80 additions and 28 deletions
|
|
@ -69,7 +69,7 @@ def get_meta_bundle(doctype):
|
|||
bundle = [frappe.desk.form.meta.get_meta(doctype)]
|
||||
for df in bundle[0].fields:
|
||||
if df.fieldtype=="Table":
|
||||
bundle.append(frappe.desk.form.meta.get_meta(df.options))
|
||||
bundle.append(frappe.desk.form.meta.get_meta(df.options, not frappe.conf.developer_mode))
|
||||
return bundle
|
||||
|
||||
def get_docinfo(doc):
|
||||
|
|
|
|||
|
|
@ -89,6 +89,7 @@
|
|||
"public/js/frappe/model/create_new.js",
|
||||
"public/js/frappe/model/perm.js",
|
||||
"public/js/frappe/model/workflow.js",
|
||||
"public/js/frappe/model/indicator.js",
|
||||
|
||||
"public/js/frappe/misc/user.js",
|
||||
"public/js/frappe/misc/pretty_date.js",
|
||||
|
|
|
|||
|
|
@ -44,15 +44,9 @@ frappe.ui.form.Toolbar = Class.extend({
|
|||
return this.page.add_dropdown(label);
|
||||
},
|
||||
set_indicator: function() {
|
||||
if(this.frm.meta.is_submittable && !this.frm.doc.__islocal) {
|
||||
switch(this.frm.doc.docstatus) {
|
||||
case 0:
|
||||
return this.page.set_indicator(__("Draft"), "red");
|
||||
case 1:
|
||||
return this.page.set_indicator(__("Submitted"), "blue");
|
||||
case 2:
|
||||
return this.page.set_indicator(__("Cancelled"), "grey");
|
||||
}
|
||||
var indicator = frappe.get_indicator(this.frm.doc);
|
||||
if(indicator) {
|
||||
this.page.set_indicator(indicator[0], indicator[1]);
|
||||
} else {
|
||||
this.page.clear_indicator();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,18 +2,20 @@
|
|||
{% var total_cols=0; for (var i=0, l=columns.length; i < l; i++ ) {
|
||||
var col = columns[i], value=data[col.fieldname]; total_cols += parseInt(col.colspan); %}
|
||||
{% if (total_cols <= 12) { %}
|
||||
<div class="col-sm-{%= col.colspan %}
|
||||
{% if(col.type==="Subject") { %}col-xs-12{% } else { %}hidden-xs{% } %}
|
||||
list-item-col text-ellipsis" title="{%= col.title + ": " + value %}">
|
||||
<div class="col-sm-{%= col.colspan %} text-ellipsis
|
||||
{% if(col.type==="Subject") { %}col-xs-12{% } else { %}hidden-xs{% } %}"
|
||||
{% if(col.title) { %}title="{%= col.title + ": " + value %}"{% } %}>
|
||||
{% if (col.type==="Subject") { %}
|
||||
{%= subject %}
|
||||
{% } else if (col.type==="Indicator") { %}
|
||||
{%= me.get_indicator(data) %}
|
||||
{% } else if (col.fieldtype==="Image") { %}
|
||||
<img src="{%= value %}" style="max-height: 30px; max-width: 100%;">
|
||||
{% } else if(col.fieldtype==="Select") { %}
|
||||
<span class="filterable indicator {%= frappe.utils.guess_colour(value) %}"
|
||||
data-filter="{%= col.fieldname %},=,{%= value %}">{%= value %}</span>
|
||||
{% } else if(col.fieldtype==="Link") { %}
|
||||
<a class="filterable grey"
|
||||
<a class="filterable h6 text-muted grey"
|
||||
data-filter="{%= col.fieldname %},=,{%= value %}">{%= value %}</a>
|
||||
{% } else { %}
|
||||
{%= frappe.format(value, col) %}
|
||||
|
|
|
|||
|
|
@ -99,11 +99,20 @@ frappe.views.ListView = Class.extend({
|
|||
},
|
||||
set_columns: function() {
|
||||
this.columns = [];
|
||||
this.total_colspans = 4;
|
||||
this.columns.push({
|
||||
colspan: 4,
|
||||
type: "Subject"
|
||||
colspan: this.settings.colwidths && this.settings.colwidths.subject || 6,
|
||||
type: "Subject",
|
||||
});
|
||||
this.total_colspans = this.columns[0].colspan;
|
||||
|
||||
// indicator
|
||||
if(frappe.model.is_submittable(this.doctype) || this.settings.get_indicator) {
|
||||
this.columns.push({
|
||||
colspan: this.settings.colwidths && this.settings.colwidths.indicator || 3,
|
||||
type: "Indicator",
|
||||
});
|
||||
this.total_colspans += this.columns[1].colspan;
|
||||
}
|
||||
|
||||
var me = this;
|
||||
if(this.workflow_state_fieldname) {
|
||||
|
|
@ -126,17 +135,21 @@ frappe.views.ListView = Class.extend({
|
|||
if(in_list(overridden, d.fieldname) || d.fieldname === me.title_field) {
|
||||
return;
|
||||
}
|
||||
me.add_column(d);
|
||||
if(me.total_colspans < 12) {
|
||||
me.add_column(d);
|
||||
}
|
||||
});
|
||||
|
||||
// additional columns
|
||||
if(this.settings.add_columns) {
|
||||
$.each(this.settings.add_columns, function(i, d) {
|
||||
if(typeof d==="string") {
|
||||
me.add_column(frappe.meta.get_docfield(me.doctype, d));
|
||||
} else {
|
||||
me.columns.push(d);
|
||||
me.total_colspans += parseInt(d.colspan);
|
||||
if(me.total_colspans < 12) {
|
||||
if(typeof d==="string") {
|
||||
me.add_column(frappe.meta.get_docfield(me.doctype, d));
|
||||
} else {
|
||||
me.columns.push(d);
|
||||
me.total_colspans += parseInt(d.colspan);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -196,6 +209,7 @@ frappe.views.ListView = Class.extend({
|
|||
data: data,
|
||||
columns: this.columns,
|
||||
subject: this.get_avatar_and_id(data, true),
|
||||
me: this
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -240,6 +254,12 @@ frappe.views.ListView = Class.extend({
|
|||
return frappe.render_template("list_item_subject", data);
|
||||
},
|
||||
|
||||
get_indicator: function(doc) {
|
||||
var indicator = frappe.get_indicator(doc, this.doctype);
|
||||
return '<span class="indicator '+indicator[1]+' filterable" data-filter="'
|
||||
+indicator[2]+'">'+indicator[0]+'<span>';
|
||||
},
|
||||
|
||||
prepare_data: function(data) {
|
||||
if(data.modified)
|
||||
this.prepare_when(data, data.modified);
|
||||
|
|
|
|||
34
frappe/public/js/frappe/model/indicator.js
Normal file
34
frappe/public/js/frappe/model/indicator.js
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright (c) 2015, Web Notes Technologies Pvt. Ltd. and Contributors
|
||||
|
||||
frappe.get_indicator = function(doc, doctype) {
|
||||
if(doc.__unsaved) {
|
||||
return [__("Not Saved"), "orange"];
|
||||
}
|
||||
|
||||
if(!doctype) doctype = doc.doctype;
|
||||
|
||||
var _get_indicator = frappe.listview_settings[doctype]
|
||||
&& frappe.listview_settings[doctype].get_indicator,
|
||||
is_submittable = frappe.model.is_submittable(doctype);
|
||||
|
||||
if(is_submittable && doc.docstatus==0) {
|
||||
return [__("Draft"), "red", "docstatus,=,0"];
|
||||
}
|
||||
|
||||
if(is_submittable && doc.docstatus==2) {
|
||||
return [__("Cancelled"), "red", "docstatus,=,2"];
|
||||
}
|
||||
|
||||
if(_get_indicator) {
|
||||
var indicator = _get_indicator(doc);
|
||||
if(indicator) return indicator;
|
||||
}
|
||||
|
||||
if(is_submittable && doc.docstatus==1) {
|
||||
return [__("Submitted"), "blue", "docstatus,=,1"];
|
||||
}
|
||||
|
||||
if(doc.status) {
|
||||
return [__(doc.status), frappe.utils.guess_colour(doc.status)];
|
||||
}
|
||||
}
|
||||
|
|
@ -95,10 +95,10 @@ frappe.views.Container = Class.extend({
|
|||
|
||||
if(module_info) {
|
||||
divider();
|
||||
if(icon) {
|
||||
icon = '<span class="'+icon+' text-muted"></span> '
|
||||
}
|
||||
$('<li><a href="#Module/'+ breadcrumbs.module +'">'+ icon + __(label) +'</a></li>').appendTo($breadcrumbs);
|
||||
// if(icon) {
|
||||
// icon = '<span class="'+icon+' text-muted"></span> '
|
||||
// }
|
||||
$('<li><a href="#Module/'+ breadcrumbs.module +'">' + __(label) +'</a></li>').appendTo($breadcrumbs);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
{% if (doc.hidden) { %}
|
||||
<span class="text-muted"><i class="icon-eye-close"></i>{% } %}
|
||||
{% if(doc.fieldtype==="Link") { %}<i class="icon-link"></i>{% } %}
|
||||
{% if(doc.in_list_view) { %} <i class="icon-list"></i>{% } %}
|
||||
{% if(doc.fieldtype==="Table") { %}<i class="icon-th"></i>{% } %}
|
||||
{%= doc.label %}
|
||||
{% if (doc.hidden) { %}</span>{% } %}
|
||||
|
|
@ -19,7 +20,7 @@
|
|||
</p>
|
||||
{% if (doc.description) { %}<p class="text-muted small">{%= doc.description %}</p>{% } %}
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
<div class="col-sm-3">
|
||||
{%= doc.fieldtype %}
|
||||
<br><span class="small">{%= doc.fieldname %}</span>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue