Browse Source

Merge branch 'saurabh6790-module_flow' into develop

version-14
Anand Doshi 9 years ago
parent
commit
a6ddb00254
12 changed files with 193 additions and 12 deletions
  1. +17
    -7
      frappe/desk/form/linked_with.py
  2. +2
    -1
      frappe/model/document.py
  3. +2
    -0
      frappe/public/build.json
  4. +36
    -0
      frappe/public/css/form.css
  5. +4
    -0
      frappe/public/css/indicator.css
  6. +52
    -0
      frappe/public/js/frappe/form/document_flow.js
  7. +2
    -2
      frappe/public/js/frappe/form/linked_with.js
  8. +12
    -0
      frappe/public/js/frappe/form/templates/form_document_flow.html
  9. +11
    -2
      frappe/public/js/frappe/ui/page.js
  10. +5
    -0
      frappe/public/js/legacy/form.js
  11. +45
    -0
      frappe/public/less/form.less
  12. +5
    -0
      frappe/public/less/indicator.less

+ 17
- 7
frappe/desk/form/linked_with.py View File

@@ -9,24 +9,36 @@ import frappe.desk.form.meta
import frappe.desk.form.load import frappe.desk.form.load


@frappe.whitelist() @frappe.whitelist()
def get_linked_docs(doctype, name, linkinfo=None):
def get_linked_docs(doctype, name, linkinfo=None, for_doctype=None):
key = "linked_with:{doctype}:{name}".format(doctype=doctype, name=name) key = "linked_with:{doctype}:{name}".format(doctype=doctype, name=name)


if isinstance(linkinfo, basestring):
# additional fields are added in linkinfo
linkinfo = json.loads(linkinfo)

if for_doctype:
key = "{key}:{for_doctype}".format(key=key, for_doctype=for_doctype)

results = frappe.cache().get_value(key, user=True) results = frappe.cache().get_value(key, user=True)

if results: if results:
return results return results


meta = frappe.desk.form.meta.get_meta(doctype) meta = frappe.desk.form.meta.get_meta(doctype)
results = {} results = {}


if isinstance(linkinfo, basestring):
# additional fields are added in linkinfo
linkinfo = json.loads(linkinfo)

if not linkinfo: if not linkinfo:
return results return results


if for_doctype:
if for_doctype in linkinfo:
# only get linked with for this particular doctype
linkinfo = { for_doctype: linkinfo.get(for_doctype) }
else:
return results

me = frappe.db.get_value(doctype, name, ["parenttype", "parent"], as_dict=True) me = frappe.db.get_value(doctype, name, ["parenttype", "parent"], as_dict=True)

for dt, link in linkinfo.items(): for dt, link in linkinfo.items():
link["doctype"] = dt link["doctype"] = dt
link_meta_bundle = frappe.desk.form.load.get_meta_bundle(dt) link_meta_bundle = frappe.desk.form.load.get_meta_bundle(dt)
@@ -61,11 +73,9 @@ def get_linked_docs(doctype, name, linkinfo=None):


else: else:
filters = [[dt, link.get("fieldname"), '=', name]] filters = [[dt, link.get("fieldname"), '=', name]]

# dynamic link # dynamic link
if link.get("doctype_fieldname"): if link.get("doctype_fieldname"):
filters.append([dt, link.get("doctype_fieldname"), "=", doctype]) filters.append([dt, link.get("doctype_fieldname"), "=", doctype])

ret = frappe.get_list(doctype=dt, fields=fields, filters=filters) ret = frappe.get_list(doctype=dt, fields=fields, filters=filters)


except frappe.PermissionError: except frappe.PermissionError:


+ 2
- 1
frappe/model/document.py View File

@@ -693,8 +693,9 @@ class Document(BaseDocument):
# clear linked doctypes list # clear linked doctypes list
cache.hdel("linked_doctypes", doctype) cache.hdel("linked_doctypes", doctype)


# delete linked with cache for all users
# for all users, delete linked with cache and per doctype linked with cache
cache.delete_value("user:*:linked_with:{doctype}:{name}".format(doctype=doctype, name=name)) cache.delete_value("user:*:linked_with:{doctype}:{name}".format(doctype=doctype, name=name))
cache.delete_value("user:*:linked_with:{doctype}:{name}:*".format(doctype=doctype, name=name))


_clear_cache(self) _clear_cache(self)
for d in self.get_all_children(): for d in self.get_all_children():


+ 2
- 0
frappe/public/build.json View File

@@ -161,12 +161,14 @@
"public/js/frappe/form/templates/set_sharing.html", "public/js/frappe/form/templates/set_sharing.html",
"public/js/frappe/form/templates/form_sidebar.html", "public/js/frappe/form/templates/form_sidebar.html",
"public/js/frappe/form/templates/form_dashboard.html", "public/js/frappe/form/templates/form_dashboard.html",
"public/js/frappe/form/templates/form_document_flow.html",
"public/js/frappe/form/templates/form_links.html", "public/js/frappe/form/templates/form_links.html",
"public/js/frappe/views/formview.js", "public/js/frappe/views/formview.js",
"public/js/legacy/form.js", "public/js/legacy/form.js",
"public/js/legacy/clientscriptAPI.js", "public/js/legacy/clientscriptAPI.js",
"public/js/frappe/form/toolbar.js", "public/js/frappe/form/toolbar.js",
"public/js/frappe/form/dashboard.js", "public/js/frappe/form/dashboard.js",
"public/js/frappe/form/document_flow.js",
"public/js/frappe/form/save.js", "public/js/frappe/form/save.js",
"public/js/frappe/form/script_manager.js", "public/js/frappe/form/script_manager.js",
"public/js/frappe/form/grid.js", "public/js/frappe/form/grid.js",


+ 36
- 0
frappe/public/css/form.css View File

@@ -30,6 +30,42 @@
.form-message { .form-message {
padding: 15px; padding: 15px;
} }
.document-flow-wrapper {
padding: 40px 15px 30px;
font-size: 12px;
border-bottom: 1px solid #EBEFF2;
}
.document-flow-wrapper .document-flow {
display: inline-block;
position: relative;
left: 50%;
transform: translateX(-50%);
}
.document-flow-wrapper .document-flow .document-flow-link-wrapper:not(:last-child) {
border-top: 1px solid #b8c2cc;
padding-right: 60px;
display: inline-block;
margin-right: -4px;
}
.document-flow-wrapper .document-flow .document-flow-link {
margin-top: -10px;
display: inline-block;
}
.document-flow-wrapper .document-flow .document-flow-link:not(.disabled):hover .document-flow-link-label,
.document-flow-wrapper .document-flow .document-flow-link:not(.disabled):focus .document-flow-link-label,
.document-flow-wrapper .document-flow .document-flow-link:not(.disabled):active .document-flow-link-label {
text-decoration: underline;
}
.document-flow-wrapper .document-flow .document-flow-link-label {
display: inline-block;
margin-left: -50%;
margin-top: 5px;
}
@media (max-width: 767px) {
.document-flow-wrapper {
display: none;
}
}
.form-dashboard { .form-dashboard {
border-bottom: 1px solid #EBEFF2; border-bottom: 1px solid #EBEFF2;
} }


+ 4
- 0
frappe/public/css/indicator.css View File

@@ -48,6 +48,10 @@
.indicator-right.darkgrey::after { .indicator-right.darkgrey::after {
background: #b8c2cc; background: #b8c2cc;
} }
.indicator.black::before,
.indicator-right.black::after {
background: #36414C;
}
.indicator.yellow::before, .indicator.yellow::before,
.indicator-right.yellow::after { .indicator-right.yellow::after {
background: #FEEF72; background: #FEEF72;


+ 52
- 0
frappe/public/js/frappe/form/document_flow.js View File

@@ -0,0 +1,52 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// MIT License. See license.txt

frappe.ui.form.DocumentFlow = Class.extend({
init: function(opts) {
$.extend(this, opts);
this.wrapper = $('<div class="document-flow-wrapper hidden"></div>').prependTo(this.frm.layout.wrapper);
},

refresh: function() {
this.reset();
this.render();
},

reset: function() {
this.wrapper.empty().addClass('hidden');
this.linked_with = {};
},

render: function() {
var me = this;
var module = frappe.get_meta(this.frm.doctype).module
var doctypes = frappe.document_flow[module][this.frm.doctype];
if (!doctypes) {
return;
}

$(frappe.render_template('form_document_flow', {
frm: this.frm,
doctypes: doctypes,
})).appendTo(this.wrapper.removeClass('hidden'));

this.wrapper.on('click', '.document-flow-link', function() {
var doctype = $(this).attr("data-doctype");
if (me.frm.doctype != doctype) {
me.get_linked_docs(doctype);
return false;
}
});
},

get_linked_docs: function(for_doctype) {
if(!this.linked_with[for_doctype]) {
this.linked_with[for_doctype] = new frappe.ui.form.LinkedWith({
frm: this.frm,
for_doctype: for_doctype
});
}

this.linked_with[for_doctype].show();
}
});

+ 2
- 2
frappe/public/js/frappe/form/linked_with.js View File

@@ -110,13 +110,13 @@ frappe.ui.form.LinkedWith = Class.extend({


get_linked_docs: function() { get_linked_docs: function() {
var me = this; var me = this;

return frappe.call({ return frappe.call({
method:"frappe.desk.form.linked_with.get_linked_docs", method:"frappe.desk.form.linked_with.get_linked_docs",
args: { args: {
doctype: me.frm.doctype, doctype: me.frm.doctype,
name: me.frm.docname, name: me.frm.docname,
linkinfo: me.frm.__linked_doctypes
linkinfo: me.frm.__linked_doctypes,
for_doctype: me.for_doctype
}, },
callback: function(r) { callback: function(r) {
var parent = me.dialog.fields_dict.list.$wrapper.empty(); var parent = me.dialog.fields_dict.list.$wrapper.empty();


+ 12
- 0
frappe/public/js/frappe/form/templates/form_document_flow.html View File

@@ -0,0 +1,12 @@
<div class="document-flow">
{% for dt in doctypes %}
<span class="document-flow-link-wrapper">
<a data-doctype="{{ dt }}"
class="document-flow-link {% if (dt===frm.doctype) { %} strong disabled {% } %} "
style="color: inherit;">
<span class="indicator {% if (dt===frm.doctype) { %} blue {% } else { %} darkgrey {% } %}"></span><br>
<span class="document-flow-link-label">{{ __(dt) }}</span>
</a>
</span>
{% endfor %}
</div>

+ 11
- 2
frappe/public/js/frappe/ui/page.js View File

@@ -90,7 +90,6 @@ frappe.ui.Page = Class.extend({
this.page_form = $('<div class="page-form row hide"></div>').prependTo(this.main); this.page_form = $('<div class="page-form row hide"></div>').prependTo(this.main);
this.inner_toolbar = $('<div class="form-inner-toolbar hide"></div>').prependTo(this.main); this.inner_toolbar = $('<div class="form-inner-toolbar hide"></div>').prependTo(this.main);
this.icon_group = this.page_actions.find(".page-icon-group"); this.icon_group = this.page_actions.find(".page-icon-group");

}, },


set_indicator: function(label, color) { set_indicator: function(label, color) {
@@ -409,5 +408,15 @@ frappe.ui.Page = Class.extend({
this.views[name].toggle(true); this.views[name].toggle(true);


this.wrapper.trigger('view-change'); this.wrapper.trigger('view-change');
},
});

frappe.ui.scroll = function(element, animate, additional_offset) {
var header_offset = $(".navbar").height() + $(".page-head").height();
var top = $(element).offset().top - header_offset - cint(additional_offset);
if (animate) {
$("html, body").animate({ scrollTop: top });
} else {
$(window).scrollTop(top);
} }
});
}

+ 5
- 0
frappe/public/js/legacy/form.js View File

@@ -253,6 +253,10 @@ _f.Frm.prototype.setup_std_layout = function() {
this.fields_dict = this.layout.fields_dict; this.fields_dict = this.layout.fields_dict;
this.fields = this.layout.fields_list; this.fields = this.layout.fields_list;


this.document_flow = new frappe.ui.form.DocumentFlow({
frm: this
});

this.dashboard = new frappe.ui.form.Dashboard({ this.dashboard = new frappe.ui.form.Dashboard({
frm: this, frm: this,
}); });
@@ -341,6 +345,7 @@ _f.Frm.prototype.refresh_header = function(is_a_different_doc) {
this.toolbar.refresh(); this.toolbar.refresh();
} }


this.document_flow.refresh();
this.dashboard.reset(); this.dashboard.reset();


this.clear_custom_buttons(); this.clear_custom_buttons();


+ 45
- 0
frappe/public/less/form.less View File

@@ -40,6 +40,51 @@
padding: 15px; padding: 15px;
} }


.document-flow-wrapper {
padding: 40px 15px 30px;
font-size: @text-medium;
border-bottom: 1px solid @light-border-color;

.document-flow {
display: inline-block;
position: relative;
left: 50%;
transform: translateX(-50%);

.document-flow-link-wrapper:not(:last-child) {
border-top: 1px solid @indicator-darkgrey;
padding-right: 60px;
display: inline-block;
margin-right: -4px;
}

.document-flow-link {
margin-top: -10px;
display: inline-block;
}

.document-flow-link:not(.disabled):hover,
.document-flow-link:not(.disabled):focus,
.document-flow-link:not(.disabled):active {
.document-flow-link-label {
text-decoration: underline;
}
}

.document-flow-link-label {
display: inline-block;
margin-left: -50%;
margin-top: 5px;
}
}
}

@media(max-width: @screen-xs) {
.document-flow-wrapper {
display: none;
}
}

.form-dashboard { .form-dashboard {
border-bottom: 1px solid @light-border-color; border-bottom: 1px solid @light-border-color;
} }


+ 5
- 0
frappe/public/less/indicator.less View File

@@ -55,6 +55,11 @@
background: @indicator-darkgrey; background: @indicator-darkgrey;
} }


.indicator.black::before,
.indicator-right.black::after {
background: @text-color;
}

.indicator.yellow::before, .indicator.yellow::before,
.indicator-right.yellow::after { .indicator-right.yellow::after {
background: @indicator-yellow; background: @indicator-yellow;


Loading…
Cancel
Save