关于一些界面元素
-
[quote author=janden link=topic=5789.msg14367#msg14367 date=1362479849]
想问一下,如附图中的下拉选项框,在openerp中是怎么调用出来的呢?
[/quote]
这个截图应该是在会计莫款的“会计凭证明细”里。
Tree view的定义很简单,但是view的类型是“tree_account_move_line_quickadd”。
很显然是在js里扩展了(参看 tree_account_move_line_quickadd.js )。
我就灌个水,都贴过来:<br /><br />openerp.account.quickadd = function (instance) {<br /> var _t = instance.web._t,<br /> _lt = instance.web._lt;<br /> var QWeb = instance.web.qweb;<br /> <br /> instance.web.account = instance.web.account || {};<br /><br /> instance.web.views.add('tree_account_move_line_quickadd', 'instance.web.account.QuickAddListView');<br /> instance.web.account.QuickAddListView = instance.web.ListView.extend({<br /> init: function() {<br /> this._super.apply(this, arguments);<br /> this.journals = [];<br /> this.periods = [];<br /> this.current_journal = null;<br /> this.current_period = null;<br /> this.default_period = null;<br /> this.default_journal = null;<br /> this.current_journal_type = null;<br /> this.current_journal_currency = null;<br /> this.current_journal_analytic = null;<br /> },<br /> start:function(){<br /> var tmp = this._super.apply(this, arguments);<br /> var self = this;<br /> this.$el.parent().prepend(QWeb.render("AccountMoveLineQuickAdd", {widget: this}));<br /> <br /> this.$el.parent().find('.oe_account_select_journal').change(function() {<br /> self.current_journal = this.value === '' ? null : parseInt(this.value);<br /> self.do_search(self.last_domain, self.last_context, self.last_group_by);<br /> });<br /> this.$el.parent().find('.oe_account_select_period').change(function() {<br /> self.current_period = this.value === '' ? null : parseInt(this.value);<br /> self.do_search(self.last_domain, self.last_context, self.last_group_by);<br /> });<br /> this.on('edit:after', this, function () {<br /> self.$el.parent().find('.oe_account_select_journal').attr('disabled', 'disabled');<br /> self.$el.parent().find('.oe_account_select_period').attr('disabled', 'disabled');<br /> });<br /> this.on('save:after cancel:after', this, function () {<br /> self.$el.parent().find('.oe_account_select_journal').removeAttr('disabled');<br /> self.$el.parent().find('.oe_account_select_period').removeAttr('disabled');<br /> });<br /> var mod = new instance.web.Model("account.move.line", self.dataset.context, self.dataset.domain);<br /> mod.call("default_get", [['journal_id','period_id'],self.dataset.context]).then(function(result) {<br /> self.current_period = result['period_id'];<br /> self.current_journal = result['journal_id'];<br /> });<br /> return tmp;<br /> },<br /> do_search: function(domain, context, group_by) {<br /> var self = this;<br /> this.last_domain = domain;<br /> this.last_context = context;<br /> this.last_group_by = group_by;<br /> this.old_search = _.bind(this._super, this);<br /> var mod = new instance.web.Model("account.move.line", context, domain);<br /> return $.when(mod.call("list_journals", []).then(function(result) {<br /> self.journals = result;<br /> }),mod.call("list_periods", []).then(function(result) {<br /> self.periods = result;<br /> })).then(function () {<br /> var o;<br /> self.$el.parent().find('.oe_account_select_journal').children().remove().end();<br /> self.$el.parent().find('.oe_account_select_journal').append(new Option('', ''));<br /> for (var i = 0;i < self.journals.length;i++){<br /> o = new Option(self.journals[i][1], self.journals[i][0]);<br /> if (self.journals[i][0] === self.current_journal){<br /> self.current_journal_type = self.journals[i][2];<br /> self.current_journal_currency = self.journals[i][3];<br /> self.current_journal_analytic = self.journals[i][4];<br /> $(o).attr('selected',true);<br /> }<br /> self.$el.parent().find('.oe_account_select_journal').append(o);<br /> }<br /> self.$el.parent().find('.oe_account_select_period').children().remove().end();<br /> self.$el.parent().find('.oe_account_select_period').append(new Option('', ''));<br /> for (var i = 0;i < self.periods.length;i++){<br /> o = new Option(self.periods[i][1], self.periods[i][0]);<br /> self.$el.parent().find('.oe_account_select_period').append(o);<br /> } <br /> self.$el.parent().find('.oe_account_select_period').val(self.current_period).attr('selected',true);<br /> return self.search_by_journal_period();<br /> });<br /> },<br /> search_by_journal_period: function() {<br /> var self = this;<br /> var domain = [];<br /> if (self.current_journal !== null) domain.push(["journal_id", "=", self.current_journal]);<br /> if (self.current_period !== null) domain.push(["period_id", "=", self.current_period]);<br /> self.last_context["journal_id"] = self.current_journal === null ? false : self.current_journal;<br /> if (self.current_period === null) delete self.last_context["period_id"];<br /> else self.last_context["period_id"] = self.current_period;<br /> self.last_context["journal_type"] = self.current_journal_type;<br /> self.last_context["currency"] = self.current_journal_currency;<br /> self.last_context["analytic_journal_id"] = self.current_journal_analytic;<br /> return self.old_search(new instance.web.CompoundDomain(self.last_domain, domain), self.last_context, self.last_group_by);<br /> },<br /> });<br />};<br /><br /><br />
模版:<br /><?xml version="1.0" encoding="UTF-8"?><br /><br /><templates id="template" xml:space="preserve"><br /> <br /> <t t-name="AccountMoveLineQuickAdd"><br /> <div class="oe_account_quickadd ui-toolbar" style="margin-bottom:0px;"><br /> <div class="oe_form_dropdown_section"><br /> <h4>Period :</h4> <br /> <select class="oe_account_select_period"><br /> <br /> </select><br /> </div><br /> <div class="oe_form_dropdown_section"><br /> <h4>Journal :</h4> <br /> <select class="oe_account_select_journal" ><br /> <br /> </select><br /> </div><br /> </div><br /> </t><br /><br /></templates><br /><br />
别忘记,还有css的定义。