project_kanban.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. openerp.custom_project = function(instance) {
  2. var QWeb = instance.web.qweb;
  3. instance.web_calendar.CalendarView = instance.web_calendar.CalendarView.extend({
  4. remove_event: function(id) {
  5. var self = this;
  6. function do_it() {
  7. return $.when(self.dataset.unlink([Number(id)])).then(function() {
  8. self.$calendar.fullCalendar('removeEvents', id);
  9. });
  10. }
  11. if (this.options.confirm_on_delete) {
  12. if (confirm(_t("Está seguro que desea eliminar esta actividad?"))) {
  13. return do_it();
  14. }
  15. } else
  16. return do_it();
  17. },
  18. event_data_transform: function(event) {
  19. var res = this._super.apply(this, arguments);
  20. //This would go off when there is no color set for hex_value. You could control this too.
  21. if (res && res.hasOwnProperty('className')) {
  22. //If you would uncomment the next line it would use the default colour that is set for the user. (default behaviour from Odoo calendars)
  23. // res.className = res.className.substring(0, res.className.indexOf(' calendar_color_'));
  24. // res.backgroundColor = '#DBDBDB';
  25. if (res.title.indexOf('false') > -1) {
  26. res.title = res.title.substring(0, res.title.indexOf(','));
  27. }
  28. }
  29. if (event.hex_value && res.title) {
  30. res.backgroundColor = event.hex_value;
  31. res.title = res.title.substring(0, res.title.indexOf(', ' + event.hex_value));
  32. }
  33. return res;
  34. }
  35. });
  36. instance.web_kanban.KanbanRecord = instance.web_kanban.KanbanRecord.extend({
  37. on_card_clicked: function() {
  38. if (this.view.dataset.model === 'project.task') {
  39. var self = this;
  40. var id = self.values.id.value;
  41. this.do_action({
  42. name: 'Tareas',
  43. type: 'ir.actions.act_window',
  44. res_model: 'project.task',
  45. view_mode: 'form',
  46. view_type: 'form',
  47. target: 'new',
  48. views: [
  49. [1576, 'form']
  50. ],
  51. res_id: id,
  52. flags: {
  53. 'form': {
  54. 'action_buttons': 'True'
  55. }
  56. }
  57. });
  58. } else {
  59. this._super.apply(this, arguments);
  60. }
  61. },
  62. });
  63. instance.web_kanban.KanbanGroup.include({
  64. hide_menu: function() {
  65. this.$el.find(".oe_dropdown_toggle ul.oe_dropdown_menu li").find('a:contains("Editar")').parent().hide();
  66. this.$el.find(".oe_dropdown_toggle ul.oe_dropdown_menu li").find('a:contains("Suprimir")').parent().hide();
  67. },
  68. start: function() {
  69. var self = this;
  70. self._super.apply(self, arguments);
  71. if (self.dataset.model == 'project.task') {
  72. this.hide_menu();
  73. }
  74. if( self.dataset.model == 'project.project'){
  75. self.$el.find('.oe_kanban_column_cards').css('margin-left', '6% !important');
  76. }
  77. }
  78. });
  79. instance.web_kanban.KanbanView.include({
  80. // set_background: function() {
  81. // this.$el.find('.oe_kanban_groups_records').css('background', 'url("/custom_project/static/src/image/fondo7.jpeg")');
  82. // this.$el.find('.oe_kanban_groups_records').css('background-repeat', 'round');
  83. // },
  84. //
  85. // start: function() {
  86. // var self = this;
  87. //
  88. // self._super.apply(self, arguments);
  89. // if (self.dataset.model == 'project.project') {
  90. //
  91. // this.set_background();
  92. // }
  93. // },
  94. postprocess_m2m_tags: function() {
  95. var self = this;
  96. if (!this.many2manys.length) {
  97. return;
  98. }
  99. var relations = {};
  100. this.groups.forEach(function(group) {
  101. group.records.forEach(function(record) {
  102. self.many2manys.forEach(function(name) {
  103. var field = record.record[name];
  104. var $el = record.$('.oe_form_field.oe_tags[name=' + name + ']').empty();
  105. if (!relations[field.relation]) {
  106. relations[field.relation] = {
  107. ids: [],
  108. elements: {},
  109. context: self.m2m_context[name]
  110. };
  111. }
  112. var rel = relations[field.relation];
  113. field.raw_value.forEach(function(id) {
  114. rel.ids.push(id);
  115. if (!rel.elements[id]) {
  116. rel.elements[id] = [];
  117. }
  118. rel.elements[id].push($el[0]);
  119. });
  120. });
  121. });
  122. });
  123. _.each(relations, function(rel, rel_name) {
  124. var dataset = new instance.web.DataSetSearch(self, rel_name, self.dataset.get_context(rel.context));
  125. var defer = $.Deferred();
  126. var f = new openerp.Model('project.category');
  127. var fields = ['id', 'name', 'hex_value'];
  128. f.query(fields).filter().all().then(function(results) {
  129. _.each(results, function(item) {
  130. $(rel.elements[item.id]).append('<span class="oe_tag" style="background:' + item.hex_value + '">' + _.str.escapeHTML(item.name) + '</span>');
  131. });
  132. });
  133. });
  134. }
  135. });
  136. }