Total Complexity | 8 |
Complexity/F | 1.33 |
Lines of Code | 71 |
Function Count | 6 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | export default { |
||
2 | data: function () { |
||
3 | return { |
||
4 | /** |
||
5 | * When true, project is visible. |
||
6 | * |
||
7 | * @type {Boolean} |
||
8 | */ |
||
9 | visible: this.project.visible |
||
10 | } |
||
11 | }, |
||
12 | |||
13 | methods: { |
||
14 | /** |
||
15 | * Toggle the visibility property. |
||
16 | */ |
||
17 | toggleVisiblity () { |
||
18 | this.visible = !this.visible; |
||
19 | }, |
||
20 | |||
21 | /** |
||
22 | * Send ajax request to server to change visibility. |
||
23 | * |
||
24 | * @param {Boolean} visible Desired project visibility. |
||
25 | */ |
||
26 | changeVisibility (visible) { |
||
27 | this.toggleVisiblity(); |
||
28 | |||
29 | let updateAction = this.getAction(); |
||
30 | |||
31 | this.ajax.patch(updateAction, { |
||
32 | visible: this.visible, |
||
33 | }) |
||
34 | .then(function () { |
||
35 | let title = 'Project Hidden'; |
||
36 | let message = this.project.name + ' is not publicly viewable'; |
||
37 | |||
38 | if (this.visible) { |
||
39 | title = 'Project Visible'; |
||
40 | message = this.project.name + ' is now publicly viewable'; |
||
41 | } |
||
42 | |||
43 | this.flash({ |
||
44 | title: title, |
||
45 | message: message, |
||
46 | type: 'success' |
||
47 | }); |
||
48 | }) |
||
49 | .catch(function () { |
||
50 | this.flash({ |
||
51 | title: 'Error', |
||
52 | message: 'Could not change project visibility', |
||
53 | type: 'error' |
||
54 | }); |
||
55 | }); |
||
56 | }, |
||
57 | |||
58 | /** |
||
59 | * Return the default update action if no update action is present. |
||
60 | * |
||
61 | * @return {String} |
||
62 | */ |
||
63 | getAction () { |
||
64 | if (typeof this.updateAction === 'undefined') { |
||
65 | return '/manager/'+this.project.slug+'/update' |
||
66 | } |
||
67 | |||
68 | return this.updateAction; |
||
69 | } |
||
70 | } |
||
71 | }; |