You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
2.7 KiB

  1. /******************************************************************************
  2. *
  3. * OpenERP, Open Source Management Solution
  4. * Copyright (c) 2010-2014 Elico Corp. All Rights Reserved.
  5. * Augustin Cisterne-Kaas <augustin.cisterne-kaas@elico-corp.com>
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License as
  9. * published by the Free Software Foundation, either version 3 of the
  10. * License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. ******************************************************************************/
  21. openerp.web_polymorphic = function (instance) {
  22. instance.web.form.FieldPolymorphic = instance.web.form.FieldMany2One.extend( {
  23. template: "FieldMany2One",
  24. events: {
  25. 'focus input': function(e) {
  26. this.field.relation = this.field_manager.get_field_value(this.polymorphic);
  27. },
  28. 'click input': function(e) {
  29. this.field.relation = this.field_manager.get_field_value(this.polymorphic);
  30. }
  31. },
  32. init: function(field_manager, node) {
  33. this._super(field_manager, node);
  34. this.polymorphic = this.node.attrs.polymorphic;
  35. },
  36. render_editable: function() {
  37. var self = this;
  38. this.$drop_down = this.$el.find(".oe_m2o_drop_down_button");
  39. this.$drop_down.click(function() {
  40. self.polymorphic = self.node.attrs.polymorphic;
  41. self.field.relation = self.field_manager.get_field_value(self.polymorphic);
  42. });
  43. this._super();
  44. this.set_polymorphic_event();
  45. this.set({
  46. readonly: true
  47. });
  48. },
  49. set_polymorphic_event: function() {
  50. self = this;
  51. this.field_manager.fields[this.polymorphic].$el.on(
  52. 'change', function(){
  53. field_value = self.field_manager.get_field_value(self.polymorphic);
  54. if(field_value !== false)
  55. self.set("effective_readonly", false);
  56. else
  57. self.set("effective_readonly", true);
  58. }
  59. );
  60. }
  61. });
  62. instance.web.form.widgets.add('polymorphic', 'instance.web.form.FieldPolymorphic')
  63. };