diff --git a/public/css/ui/common.css b/public/css/ui/common.css index f1fc14b134..eb20294e30 100644 --- a/public/css/ui/common.css +++ b/public/css/ui/common.css @@ -430,6 +430,10 @@ textarea[data-fieldtype="Small Text"] { } } +.modal-backdrop { + opacity: 0.5; +} + /* buttons */ .btn-default { color: #ffffff; diff --git a/public/js/wn/form/control.js b/public/js/wn/form/control.js index 3d411a7c13..600899b28e 100644 --- a/public/js/wn/form/control.js +++ b/public/js/wn/form/control.js @@ -319,7 +319,7 @@ wn.ui.form.ControlInt = wn.ui.form.ControlData.extend({ this.$input .css({"text-align": "right"}) .on("focus", function() { - this.select(); + setTimeout(function() { document.activeElement.select() }, 100); return false; }) }, @@ -371,7 +371,7 @@ wn.ui.form.ControlDate = wn.ui.form.ControlData.extend({ return value ? dateutil.user_to_str(value) : value; }, format_for_input: function(value) { - return dateutil.str_to_user(value); + return value ? dateutil.str_to_user(value) : ""; }, validate: function(value, callback) { var value = wn.datetime.validate(value); @@ -461,13 +461,16 @@ wn.ui.form.ControlButton = wn.ui.form.ControlData.extend({ .prependTo(me.input_area) .css({"margin-bottom": "7px"}) .on("click", function() { - if(me.frm && me.frm.cscript) { + if(me.frm && me.frm.doc && me.frm.cscript) { if(me.frm.cscript[me.df.fieldname]) { me.frm.script_manager.trigger(me.df.fieldname, me.doctype, me.docname); } else { me.frm.runscript(me.df.options, me); } - } + } + else if(me.df.click) { + me.df.click(); + } }); this.input = this.$input.get(0); this.has_input = true; @@ -670,7 +673,8 @@ wn.ui.form.ControlLink = wn.ui.form.ControlData.extend({ me.autocomplete_open = false; }, select: function(event, ui) { - me.parse_validate_and_set_in_model(ui.item.value); + if(me.frm && me.frm.doc) + me.parse_validate_and_set_in_model(ui.item.value); } }).data('uiAutocomplete')._renderItem = function(ul, item) { return $('
') @@ -684,15 +688,17 @@ wn.ui.form.ControlLink = wn.ui.form.ControlData.extend({ this.$wrapper.find(".ui-helper-hidden-accessible").remove(); }, set_custom_query: function(args) { - if(this.get_query) { - var q = this.get_query(this.frm && this.frm.doc, this.doctype, this.docname); + if(this.get_query || this.df.get_query) { + var q = (this.get_query || this.df.get_query)(this.frm && this.frm.doc, this.doctype, this.docname); if (typeof(q)==="string") { args.query = q; } else if($.isPlainObject(q)) { if(q.filters) { $.each(q.filters, function(key, value) { - q.filters[key] = value===undefined ? null : value; + if(value!==undefined) { + q.filters[key] = value || null; + } }); } $.extend(args, q); diff --git a/public/js/wn/form/formatters.js b/public/js/wn/form/formatters.js index 7d88a4cb47..0b931b9561 100644 --- a/public/js/wn/form/formatters.js +++ b/public/js/wn/form/formatters.js @@ -43,7 +43,7 @@ wn.form.formatters = { } }, Date: function(value) { - return dateutil.str_to_user(value); + return value ? dateutil.str_to_user(value) : ""; }, Text: function(value) { if(value) { diff --git a/public/js/wn/form/grid.js b/public/js/wn/form/grid.js index 9792ce0070..bc89cc353e 100644 --- a/public/js/wn/form/grid.js +++ b/public/js/wn/form/grid.js @@ -188,6 +188,7 @@ wn.ui.form.GridRow = Class.extend({ this.wrapper.find(".data-row, .panel-heading") .click(function() { me.toggle_view(); + return false; }); this.set_button_events(); } diff --git a/public/js/wn/model/create_new.js b/public/js/wn/model/create_new.js index a23617db48..c853a607dd 100644 --- a/public/js/wn/model/create_new.js +++ b/public/js/wn/model/create_new.js @@ -145,19 +145,55 @@ $.extend(wn.model, { }, map_current_doc: function(opts) { - wn.call({ - type: "GET", - method: opts.method, - args: { - "source_name": opts.source_name, - "target_doclist": wn.model.get_doclist(cur_frm.doc.doctype, cur_frm.doc.name) - }, - callback: function(r) { - if(!r.exc) { - var doclist = wn.model.sync(r.message); - cur_frm.refresh(); - } + if(opts.get_query_filters) { + opts.get_query = function() { + return {filters: opts.get_query_filters}; } - }); + } + var _map = function() { + wn.call({ + type: "GET", + method: opts.method, + args: { + "source_name": opts.source_name, + "target_doclist": wn.model.get_doclist(cur_frm.doc.doctype, cur_frm.doc.name) + }, + callback: function(r) { + if(!r.exc) { + var doclist = wn.model.sync(r.message); + cur_frm.refresh(); + } + } + }); + } + if(opts.source_doctype) { + var d = new wn.ui.Dialog({ + title: wn._("Get From ") + wn._(opts.source_doctype), + fields: [ + { + "fieldtype": "Link", + "label": wn._(opts.source_doctype), + "fieldname": opts.source_doctype, + "options": opts.source_doctype, + "get_query": opts.get_query, + reqd:1}, + { + "fieldtype": "Button", + "label": wn._("Get"), + click: function() { + var values = d.get_values(); + if(!values) + return; + opts.source_name = values[opts.source_doctype]; + d.hide(); + _map(); + } + } + ] + }) + d.show(); + } else if(opts.source_name) { + _map(); + } } }) \ No newline at end of file diff --git a/public/js/wn/ui/dialog.js b/public/js/wn/ui/dialog.js index f8c86d577e..3b8edcbc7b 100644 --- a/public/js/wn/ui/dialog.js +++ b/public/js/wn/ui/dialog.js @@ -34,7 +34,7 @@ wn.ui.Dialog = wn.ui.FieldGroup.extend({ this.make(); }, make: function() { - this.$wrapper = $('