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.

81 lines
3.1 KiB

6 years ago
  1. /**********************************************************************************
  2. *
  3. * Copyright (C) 2018 MuK IT GmbH
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as
  7. * published by the Free Software Foundation, either version 3 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. **********************************************************************************/
  19. odoo.define('muk_web_security.form_controller', function (require) {
  20. "use strict";
  21. var ajax = require('web.ajax');
  22. var core = require('web.core');
  23. var utils = require('web.utils');
  24. var FormController = require('web.FormController');
  25. var QWeb = core.qweb;
  26. var _t = core._t;
  27. FormController.include({
  28. _update: function() {
  29. var self = this;
  30. var data = this.model.get(this.handle).data;
  31. this.activeActions.edit = data.permission_write === undefined ?
  32. this.activeActions.edit : !!data.permission_write;
  33. this.activeActions.create = data.permission_create === undefined ?
  34. this.activeActions.create : !!data.permission_create;
  35. this.activeActions.delete = data.permission_unlink === undefined ?
  36. this.activeActions.delete : !!data.permission_unlink;
  37. this.activeActions.duplicate = data.permission_create === undefined ?
  38. this.activeActions.duplicate : !!data.permission_create;
  39. if(this.activeActions.edit && data.locked !== undefined && !data.editor &&
  40. data.locked && data.locked instanceof Object) {
  41. this.activeActions.locked = true;
  42. } else {
  43. this.activeActions.locked = false;
  44. }
  45. return $.when(this._super.apply(this, arguments));
  46. },
  47. _updateButtons: function () {
  48. this._super.apply(this, arguments);
  49. if(this.$buttons) {
  50. var $create = this.$buttons.find('.o_form_button_create');
  51. var $edit = this.$buttons.find('.o_form_button_edit');
  52. $create.toggle(this.activeActions.create);
  53. $edit.toggle(this.activeActions.edit);
  54. if(!!this.activeActions.locked) {
  55. $edit.prop("disabled", true);
  56. $edit.text(_t("Locked!"));
  57. } else {
  58. $edit.prop("disabled", false);
  59. $edit.text(_t("Edit"));
  60. }
  61. }
  62. },
  63. _updateSidebar: function () {
  64. this._super.apply(this, arguments);
  65. if(this.sidebar) {
  66. var $delete = this.sidebar.$el.find(
  67. 'li > a[data-section="other"]:contains("' + _t('Delete') + '")');
  68. var $duplicate = this.sidebar.$el.find(
  69. 'li > a[data-section="other"]:contains("' + _t('Duplicate') + '")');
  70. $delete.toggle(this.activeActions.delete && !this.activeActions.locked);
  71. $duplicate.toggle(this.activeActions.duplicate);
  72. }
  73. },
  74. });
  75. });