diff --git a/apps/spreadsheeteditor/main/app/view/FormulaWizard.js b/apps/spreadsheeteditor/main/app/view/FormulaWizard.js index 9f9020c68..f549d9016 100644 --- a/apps/spreadsheeteditor/main/app/view/FormulaWizard.js +++ b/apps/spreadsheeteditor/main/app/view/FormulaWizard.js @@ -61,15 +61,15 @@ define([ this.template = [ '
', '', - '
', - '
', + '
', + '
', '', '
', '
', '
', '
', '', - '', + '', '', '', '', @@ -84,6 +84,9 @@ define([ this.api = this.options.api; this._noApply = false; this.args = []; + this.repeatedArg = undefined; + this.minArgCount = 1; + this.maxArgCount = 1; Common.UI.Window.prototype.initialize.call(this, this.options); }, @@ -91,27 +94,14 @@ define([ render: function() { Common.UI.Window.prototype.render.call(this); - this.txtArg1 = new Common.UI.InputFieldBtn({ - el : $('#formula-wizard-txt-arg1'), - style : 'width: 100%;', - allowBlank : true, - validateOnChange: false - }); - - this.txtArg2 = new Common.UI.InputFieldBtn({ - el : $('#formula-wizard-txt-arg2'), - style : 'width: 100%;', - allowBlank : true, - validateOnChange: false - }); - var $window = this.getChild(); $window.find('.dlg-btn').on('click', _.bind(this.onBtnClick, this)); $window.find('input').on('keypress', _.bind(this.onKeyPress, this)); this.panelArgs = $window.find('#formula-wizard-panel-args'); - this.tableArgs = $window.find('#formula-wizard-tbl-args').parent(); + this.tableArgs = $window.find('#formula-wizard-tbl-args'); this.panelDesc = $window.find('#formula-wizard-panel-desc'); + this.lblArgDesc = $window.find('#formula-wizard-arg-desc'); this._preventCloseCellEditor = false; @@ -153,12 +143,12 @@ define([ }) } var height = this.panelDesc.outerHeight(); - height = this.$window.find('.box').height() - height - 23;// #formula-wizard-name height + height = this.$window.find('.box').height() - height - 33;// #formula-wizard-name height this.panelArgs.height(height); height = parseInt((height-8)/30) * 30; - this.tableArgs.height(height); + this.tableArgs.parent().height(height); this.scrollerY = new Common.UI.Scroller({ - el: this.tableArgs, + el: this.tableArgs.parent(), minScrollbarLength : 20, alwaysVisibleY: true }); @@ -166,68 +156,101 @@ define([ if (this.props) { // fill arguments var props = this.props; + this.minArgCount = props.asc_getArgumentMin(); + this.maxArgCount = props.asc_getArgumentMax(); + var result = props.asc_getFormulaResult(); $('#formula-wizard-value').html('' + this.textValue + ': ' + ((result!==undefined && result!==null)? result : '')); - var tbl = this.$window.find('#formula-wizard-tbl-args'); - var argtpl = '
' + - '
' + - '
'; - var argmin = props.asc_getArgumentMin(), - argmax = props.asc_getArgumentMax(), - argres = props.asc_getArgumentsResult(), + var argres = props.asc_getArgumentsResult(), argtype = props.asc_getArgumentsType(), - argval = props.asc_getArgumentsValue(), - argcount = 0, - lasttype; - for (var i=0; i' + this.args[argcount].argName + ''); - else - this.args[argcount].lblName.html(this.args[argcount].argName); - this.args[argcount].lblValue.text(' = '+ (argres && (argres.length>argcount) && argres[argcount]!==null ? argres[argcount] : this.args[argcount].argTypeName)); - argcount++; + if (argtype) { + for (var i=0; i
' + + '
', + div = $(Common.Utils.String.format(argtpl, argcount)); + this.tableArgs.append(div); + + var txt = new Common.UI.InputFieldBtn({ + el: div.find('#formula-wizard-txt-arg'+argcount), + index: argcount, + validateOnChange: true, + validateOnBlur: false + }).on('changed:after', function(input, newValue, oldValue, e) { + if (newValue == oldValue) return; + }).on('changing', function(input, newValue, oldValue, e) { + if (newValue == oldValue) return; + var index = input.options.index, + arg = me.args[index], + res = me.api.asc_insertFormulaArgument(newValue, index, arg.argType); + arg.lblValue.text(' = '+ (res!==null && res !==undefined ? res : arg.argTypeName)); + }); + txt.setValue((argval!==undefined && argval!==null) ? argval : ''); + txt._input.on('focus', _.bind(this.onSelectArgument, this, txt)); + txt.on('button:click', _.bind(this.onSelectData, this)); + + me.args.push({ + index: argcount, + lblName: div.find('#formula-wizard-lbl-name-arg'+argcount), + lblValue: div.find('#formula-wizard-lbl-val-arg'+argcount), + argInput: txt, + argName: 'Argument ' + (argcount+1), + argDesc: 'some argument description', + argType: argtype, + argTypeName: me.getArgType(argtype) + }); + if (argcount' + me.args[argcount].argName + ''); + else + me.args[argcount].lblName.html(me.args[argcount].argName); + me.args[argcount].lblValue.text(' = '+ ( argres!==null && argres!==undefined ? argres : me.args[argcount].argTypeName)); }, getArgType: function(type) { @@ -252,6 +275,44 @@ define([ return str; }, + onSelectArgument: function(input) { + var index = input.options.index, + arg = this.args[index]; + arg.argDesc ? this.lblArgDesc.html('' + arg.argName + ': ' + arg.argDesc) : this.lblArgDesc.addClass('hidden'); + if (!this._noApply && index==this.args.length-1 && this.repeatedArg && index+this.repeatedArg.length