|
1 | | -(function() { |
2 | | - var board_id, css, |
3 | | - _this = this; |
4 | | - |
5 | | - board_id = window.board.model.id; |
6 | | - |
7 | | - css = " .contextMenu li.change_column >a { background-image: url('/images/icons/silk/note_go.png'); } .change_column_opts li a { background-image: url('/images/icons/silk/note.png'); } "; |
8 | | - |
9 | | - if (window.board.model.users.get(KanbanTool.Board.current_user_id).can('move_tasks', window.board.model)) { |
10 | | - $('<style>').html(css).appendTo('head'); |
11 | | - $.ajax({ |
12 | | - type: 'GET', |
13 | | - url: '/boards/' + parseInt(board_id + 20) + '/schema.json', |
14 | | - async: false, |
15 | | - dataType: 'json', |
16 | | - success: function(schema) { |
17 | | - var columns, max_width; |
18 | | - max_width = 120; |
19 | | - columns = '<ul class="level2 change_column_opts">'; |
20 | | - $(schema.workflow_stages).each(function(i, e) { |
21 | | - var width; |
22 | | - columns += '<li><a href="#extension:change_column:' + e.id + '">' + e.full_name + '</a></li>'; |
23 | | - width = e.full_name.length * 6 + 30; |
24 | | - if (width > max_width) { |
25 | | - return max_width = width; |
26 | | - } |
27 | | - }); |
28 | | - columns += '</ul>'; |
29 | | - $('#task_context_menu .change_board').after('<li class="change_column has_submenu"><a onclick="return false;" href="#">Change column</a>' + columns + '</li>'); |
30 | | - return $('.change_column_opts').css({ |
31 | | - 'width': max_width |
32 | | - }); |
33 | | - } |
34 | | - }); |
35 | | - $(window).bind('extensionContextMenuAction', function(event, action, el, pos) { |
36 | | - var current_ws_id, task_id, ws_id; |
37 | | - if (/extension:change_column:([0-9])/.test(action)) { |
38 | | - ws_id = action.replace(/extension:change_column:/, ''); |
39 | | - current_ws_id = $(el).parent()[0].id.split('_')[1]; |
40 | | - task_id = $(el)[0].id.split('_')[1]; |
41 | | - if (ws_id !== current_ws_id) { |
42 | | - return $.ajax({ |
43 | | - type: 'POST', |
44 | | - url: '/boards/' + parseInt(board_id + 20) + '/tasks/' + task_id + '/change_board', |
45 | | - dataType: 'script', |
46 | | - async: false, |
47 | | - data: { |
48 | | - b_id: parseInt(board_id + 20), |
49 | | - ws_id: ws_id, |
50 | | - sl_id: $(el).parent()[0].id.split('_')[2], |
51 | | - copy: false |
52 | | - } |
53 | | - }); |
54 | | - } |
55 | | - } |
56 | | - }); |
| 1 | +window.KT.Elements.Task.contextMenu.push({ |
| 2 | + name: 'Change column', |
| 3 | + permissions: 'update_tasks', |
| 4 | + type: 'submenu', |
| 5 | + options: (function(e) { |
| 6 | + var i, len, opts, ref, stage; |
| 7 | + opts = []; |
| 8 | + ref = e.delegateTarget.props.task.board().workflowStages().leafs(); |
| 9 | + for (i = 0, len = ref.length; i < len; i++) { |
| 10 | + stage = ref[i]; |
| 11 | + opts.push({ |
| 12 | + id: stage.id, |
| 13 | + html: _.escape(stage.get('name')), |
| 14 | + action: (function() { |
| 15 | + var ids; |
| 16 | + ids = $('kt-task.kt-selected').map(function() { |
| 17 | + return this.props.taskId; |
| 18 | + }); |
| 19 | + return KT.tasks.groupUpdate(ids, { |
| 20 | + 'workflow_stage_id': this.id, |
| 21 | + 'position': null |
| 22 | + }); |
| 23 | + }) |
| 24 | + }); |
57 | 25 | } |
58 | | - |
59 | | -}).call(this); |
| 26 | + return opts; |
| 27 | + }) |
| 28 | +}); |
0 commit comments