Ver a proveniência

[form] [workflow] fixed ui, added default workflow_status if missing

version-14
Rushabh Mehta há 12 anos
ascendente
cometimento
e19d69ffde
5 ficheiros alterados com 60 adições e 36 eliminações
  1. +15
    -0
      core/doctype/workflow/workflow.py
  2. +8
    -1
      public/js/legacy/widgets/form/fields.js
  3. +26
    -31
      public/js/wn/form/states.js
  4. +10
    -3
      public/js/wn/form/toolbar.js
  5. +1
    -1
      public/js/wn/ui/listing.js

+ 15
- 0
core/doctype/workflow/workflow.py Ver ficheiro

@@ -29,6 +29,10 @@ class DocType:
def validate(self): def validate(self):
self.set_active() self.set_active()
self.create_custom_field_for_workflow_state() self.create_custom_field_for_workflow_state()
self.update_default_workflow_status()
def on_update(self):
webnotes.clear_cache(doctype=self.doc.document_type)
def create_custom_field_for_workflow_state(self): def create_custom_field_for_workflow_state(self):
webnotes.clear_cache(doctype=self.doc.document_type) webnotes.clear_cache(doctype=self.doc.document_type)
@@ -52,6 +56,17 @@ class DocType:
webnotes.msgprint("Created Custom Field '%s' in '%s'" % (self.doc.workflow_state_field, webnotes.msgprint("Created Custom Field '%s' in '%s'" % (self.doc.workflow_state_field,
self.doc.document_type)) self.doc.document_type))


def update_default_workflow_status(self):
docstatus_map = {}
states = self.doclist.get({"doctype": "Workflow Document State"})
states.sort(lambda x, y: x.idx - y.idx)
for d in self.doclist.get({"doctype": "Workflow Document State"}):
if not d.doc_status in docstatus_map:
webnotes.conn.sql("""update `tab%s` set `%s` = %s where \
ifnull(`%s`, '')='' and docstatus=%s""" % (self.doc.document_type, self.doc.workflow_state_field,
'%s', self.doc.workflow_state_field, "%s"), (d.state, d.doc_status))
docstatus_map[d.doc_status] = d.state
def set_active(self): def set_active(self):
if int(self.doc.is_active or 0): if int(self.doc.is_active or 0):
# clear all other # clear all other


+ 8
- 1
public/js/legacy/widgets/form/fields.js Ver ficheiro

@@ -75,7 +75,14 @@ Field.prototype.set_label = function(label) {
} }


Field.prototype.set_description = function(txt) { Field.prototype.set_description = function(txt) {
this.$wrapper.find(":input").attr("title", txt).tooltip();
if(txt) {
if(!this.$wrapper.find(".help-box").length) {
$('<p class="help-box small"></p>').appendTo(this.input_area);
}
this.$wrapper.find(".help-box").html(txt);
} else {
this.$wrapper.find(".help-box").empty().toggle(false);
}
} }


Field.prototype.get_status = function(explain) { Field.prototype.get_status = function(explain) {


+ 26
- 31
public/js/wn/form/states.js Ver ficheiro

@@ -31,9 +31,6 @@ wn.ui.form.States = Class.extend({


this.update_fields = wn.workflow.get_update_fields(this.frm.doctype); this.update_fields = wn.workflow.get_update_fields(this.frm.doctype);


this.make();
this.bind_action();

var me = this; var me = this;
$(this.frm.wrapper).bind("render_complete", function() { $(this.frm.wrapper).bind("render_complete", function() {
me.refresh(); me.refresh();
@@ -41,23 +38,22 @@ wn.ui.form.States = Class.extend({
}, },
make: function() { make: function() {
this.$wrapper = $('<div class="states" style="margin-bottom: 11px; height: 26px;">\
<div class="btn-group">\
<button class="btn dropdown-toggle" data-toggle="dropdown">\
<i class="icon-small"></i> <span class="state-text"></span> <span class="caret"></span>\
</button>\
<ul class="dropdown-menu">\
</ul>\
</div>\
<button class="btn btn-help">?</button>\
</div>').appendTo(this.frm.body_header);
this.$wrapper.toggle(false);
var parent = this.frm.appframe.$w.find(".title-button-area");
this.workflow_button = $('<button class="btn dropdown-toggle">\
<i class="icon-small"></i> <span class="state-text"></span>\
<span class="caret"></span></button>')
.appendTo(parent).dropdown();
this.dropdown = $('<ul class="dropdown-menu">').insertAfter(this.workflow_button);
this.help_btn = $('<button class="btn"><i class="icon-question-sign"></i></button').
insertBefore(this.workflow_button);
this.setup_help(); this.setup_help();
this.bind_action();
}, },


setup_help: function() { setup_help: function() {
var me = this; var me = this;
this.$wrapper.find(".btn-help").click(function() {
this.help_btn.click(function() {
wn.workflow.setup(me.frm.doctype); wn.workflow.setup(me.frm.doctype);
var state = me.get_state(); var state = me.get_state();
var d = new wn.ui.Dialog({ var d = new wn.ui.Dialog({
@@ -84,44 +80,44 @@ wn.ui.form.States = Class.extend({
refresh: function() { refresh: function() {
// hide if its not yet saved // hide if its not yet saved
this.$wrapper.toggle(false);
if(this.frm.doc.__islocal) { if(this.frm.doc.__islocal) {
this.set_default_state(); this.set_default_state();
return;
} }

this.make();
// state text // state text
var state = this.get_state(); var state = this.get_state();
if(state) { if(state) {
// show current state on the button // show current state on the button
this.$wrapper.find(".state-text").text(state);
this.workflow_button.find(".state-text").text(state);
var state_doc = wn.model.get("Workflow State", {name:state})[0]; var state_doc = wn.model.get("Workflow State", {name:state})[0];


// set the icon // set the icon
this.$wrapper.find('.icon-small').removeClass()
.addClass("icon-small icon-white")
this.workflow_button.find('i').removeClass()
.addClass("icon-white")
.addClass("icon-" + state_doc.icon); .addClass("icon-" + state_doc.icon);


// set the style // set the style
var btn = this.$wrapper.find(".btn:first");
btn.removeClass().addClass("btn dropdown-toggle")
this.workflow_button.removeClass().addClass("btn dropdown-toggle")


if(state_doc && state_doc.style) if(state_doc && state_doc.style)
btn.addClass("btn-" + state_doc.style.toLowerCase());
this.workflow_button.addClass("btn-" + state_doc.style.toLowerCase());
// show actions from that state // show actions from that state
this.show_actions(state); this.show_actions(state);
this.$wrapper.toggle(true);
if(this.frm.doc.__islocal) { if(this.frm.doc.__islocal) {
this.$wrapper.find('.btn:first').attr('disabled', true);
this.workflow_button.attr('disabled', true);
} }
} }
}, },
show_actions: function(state) { show_actions: function(state) {
var $ul = this.$wrapper.find("ul");
var $ul = this.dropdown;
$ul.empty(); $ul.empty();


$.each(wn.workflow.get_transitions(this.frm.doctype, state), function(i, d) { $.each(wn.workflow.get_transitions(this.frm.doctype, state), function(i, d) {
@@ -135,7 +131,7 @@ wn.ui.form.States = Class.extend({
}); });


// disable the button if user cannot change state // disable the button if user cannot change state
this.$wrapper.find('.btn:first')
this.workflow_button
.attr('disabled', $ul.find("li").length ? false : true); .attr('disabled', $ul.find("li").length ? false : true);
}, },


@@ -155,9 +151,8 @@ wn.ui.form.States = Class.extend({
bind_action: function() { bind_action: function() {
var me = this; var me = this;
$(this.$wrapper).on("click", "[data-action]", function() {
this.dropdown.on("click", "[data-action]", function() {
var action = $(this).attr("data-action"); var action = $(this).attr("data-action");
// capture current state // capture current state
var doc_before_action = copy_dict(me.frm.doc); var doc_before_action = copy_dict(me.frm.doc);


@@ -166,7 +161,7 @@ wn.ui.form.States = Class.extend({
me.frm.doc[me.state_fieldname], action); me.frm.doc[me.state_fieldname], action);
me.frm.doc[me.state_fieldname] = next_state; me.frm.doc[me.state_fieldname] = next_state;
var new_state = wn.workflow.get_document_state(me.frm.doctype, next_state); var new_state = wn.workflow.get_document_state(me.frm.doctype, next_state);
var new_docstatus = new_state.doc_status;
var new_docstatus = cint(new_state.doc_status);


// update field and value // update field and value
if(new_state.update_field) { if(new_state.update_field) {
@@ -192,11 +187,11 @@ wn.ui.form.States = Class.extend({
msgprint(wn._("Document Status transition from ") + me.frm.doc.docstatus + " " msgprint(wn._("Document Status transition from ") + me.frm.doc.docstatus + " "
+ wn._("to") + + wn._("to") +
new_docstatus + " " + wn._("is not allowed.")); new_docstatus + " " + wn._("is not allowed."));
return;
return false;
} }
// hide dropdown // hide dropdown
$(this).parents(".dropdown-menu").prev().dropdown('toggle');
$(this).parents(".dropdown-menu:first").prev().dropdown('toggle');
return false; return false;
}) })


+ 10
- 3
public/js/wn/form/toolbar.js Ver ficheiro

@@ -115,15 +115,17 @@ wn.ui.form.Toolbar = Class.extend({
this.appframe.$w.find(".title-button-area").empty(); this.appframe.$w.find(".title-button-area").empty();
var docstatus = cint(this.frm.doc.docstatus); var docstatus = cint(this.frm.doc.docstatus);
var p = this.frm.perm[0]; var p = this.frm.perm[0];
var has_workflow = wn.model.get("Workflow", {document_type: me.frm.doctype}).length;


if(!wn.model.get("Workflow", {document_type: me.frm.doctype}).length) {
if(has_workflow && this.frm.doc.__islocal) {
this.make_save_button();
} else if(!has_workflow) {
if(docstatus==0 && p[SUBMIT] && (!me.frm.doc.__islocal)) { if(docstatus==0 && p[SUBMIT] && (!me.frm.doc.__islocal)) {
this.appframe.add_button('Submit', function() { this.appframe.add_button('Submit', function() {
me.frm.savesubmit(this);}, 'icon-lock', true).addClass("btn-primary"); me.frm.savesubmit(this);}, 'icon-lock', true).addClass("btn-primary");
} }
else if(docstatus==0) { else if(docstatus==0) {
this.appframe.add_button('Save', function() {
me.frm.save('Save', null, this);}, 'icon-save', true).addClass("btn-primary");
this.make_save_button();
} }
else if(docstatus==1 && p[CANCEL]) { else if(docstatus==1 && p[CANCEL]) {
this.appframe.add_dropdown_button("File", 'Cancel', function() { this.appframe.add_dropdown_button("File", 'Cancel', function() {
@@ -135,6 +137,11 @@ wn.ui.form.Toolbar = Class.extend({
} }
} }
}, },
make_save_button: function() {
var me = this;
this.appframe.add_button('Save', function() {
me.frm.save('Save', null, this);}, 'icon-save', true).addClass("btn-primary");
},
add_update_button_on_dirty: function() { add_update_button_on_dirty: function() {
var me = this; var me = this;
$(this.frm.wrapper).on("dirty", function() { $(this.frm.wrapper).on("dirty", function() {


+ 1
- 1
public/js/wn/ui/listing.js Ver ficheiro

@@ -104,7 +104,7 @@ wn.ui.Listing = Class.extend({
class="img-load"/></div>\ class="img-load"/></div>\
</div><div style="clear:both"></div>\ </div><div style="clear:both"></div>\
\ \
<div class="no-result help hide">\
<div class="no-result" style="display: none;">\
%(no_result_message)s\ %(no_result_message)s\
</div>\ </div>\
\ \


Carregando…
Cancelar
Guardar