|
9 | 9 | autoOpen: false, |
10 | 10 | modal: true |
11 | 11 | }); |
12 | | - }); |
13 | | - |
| 12 | + }); |
| 13 | + |
14 | 14 | $("#new-tag-submit").click(function () { |
15 | | - if ($("#new-tag-input").val().trim() == '') |
16 | | - return false; |
| 15 | + if ($("#new-tag-input").val().trim() == '') |
| 16 | + return false; |
17 | 17 | var baseUrl = OC.generateUrl('/apps/timetracker/ajax/add-tag/'+$("#new-tag-input").val()); |
18 | 18 | var jqxhr = $.post( baseUrl, function() { |
19 | | - |
20 | 19 | getTags(); |
21 | 20 | $(dialogTagEditForm).dialog("close"); |
22 | | - }) |
23 | | - .done(function(data, status, jqXHR) { |
24 | | - var response = data; |
25 | | - if ('Error' in response){ |
| 21 | + }).done(function(data, status, jqXHR) { |
| 22 | + var response = data; |
| 23 | + if ('Error' in response){ |
26 | 24 | alert(response.Error); |
27 | | - } |
28 | | - }) |
29 | | - .fail(function() { |
30 | | - alert( "error" ); |
31 | | - }) |
32 | | - return false; |
| 25 | + } |
| 26 | + }).fail(function() { |
| 27 | + alert( "error" ); |
| 28 | + }) |
| 29 | + return false; |
33 | 30 | }); |
| 31 | + |
34 | 32 | dialogTagEditForm = $( "#dialog-tag-edit-form" ).dialog({ |
35 | 33 | autoOpen: false, |
36 | 34 | height: 400, |
37 | 35 | width: 350, |
38 | 36 | modal: true, |
39 | 37 | buttons: { |
40 | | - "Edit tag": {click: function(){ |
41 | | - editTag(dialogTagEditForm); |
42 | | - return false; |
43 | | - }, |
44 | | - text: 'Edit tag', |
45 | | - class:'primary' |
46 | | - }, |
47 | | - Cancel: function() { |
48 | | - dialogTagEditForm.dialog( "close" ); |
49 | | - } |
| 38 | + "Edit tag": { |
| 39 | + click: function(){ |
| 40 | + editTag(dialogTagEditForm); |
| 41 | + return false; |
| 42 | + }, |
| 43 | + text: 'Edit tag', |
| 44 | + class:'primary' |
| 45 | + }, |
| 46 | + Cancel: function() { |
| 47 | + dialogTagEditForm.dialog( "close" ); |
| 48 | + } |
50 | 49 | }, |
51 | 50 | close: function() { |
52 | | - form[ 0 ].reset(); |
| 51 | + form[ 0 ].reset(); |
53 | 52 | } |
54 | | - }); |
55 | | - |
56 | | - form = dialogTagEditForm.find( "form" ).on( "submit", function( event ) { |
| 53 | + }); |
| 54 | + |
| 55 | + form = dialogTagEditForm.find( "form" ).on( "submit", function( event ) { |
57 | 56 | event.preventDefault(); |
58 | 57 | editTag(dialogTagEditForm); |
59 | | - }); |
| 58 | + }); |
60 | 59 |
|
61 | | - getTags(); |
62 | | - function editTag(dialogTagEditForm){ |
| 60 | + getTags(); |
| 61 | + function editTag(dialogTagEditForm){ |
63 | 62 | target = dialogTagEditForm.target; |
64 | 63 | form = dialogTagEditForm.find( "form" ); |
65 | 64 | var baseUrl = OC.generateUrl('/apps/timetracker/ajax/edit-tag/'+target); |
|
78 | 77 | }) |
79 | 78 |
|
80 | 79 | } |
81 | | - function getTags(){ |
82 | | - var baseUrl = OC.generateUrl('/apps/timetracker/ajax/tags'); |
83 | 80 |
|
84 | | - var editIcon = function(cell, formatterParams){ //plain text value |
85 | | - return "<i class='fa fa-edit'></i>"; |
86 | | - }; |
87 | | - |
88 | | - |
89 | | - var columns = [ |
90 | | - {title:"#", field:"", formatter:"rownum", width: 40, align: "center"}, |
91 | | - {title:"Name", field:"name", widthGrow:1}, //column will be allocated 1/5 of the remaining space |
92 | | - {formatter:"buttonCross", width:40, align:"center", cellClick:function(e, cell){ |
93 | | - $("#dialog-confirm").dialog({ |
94 | | - buttons : { |
95 | | - "Confirm" : {click: function() { |
96 | | - var baseUrl = OC.generateUrl('/apps/timetracker/ajax/delete-tag/'+cell.getRow().getData().id); |
97 | | - var jqxhr = $.post( baseUrl, function() { |
98 | | - getTags(); |
99 | | - $("#dialog-confirm").dialog("close"); |
100 | | - }) |
101 | | - .done(function(data, status, jqXHR) { |
102 | | - var response = data; |
103 | | - if ('Error' in response){ |
104 | | - alert(response.Error); |
105 | | - } |
106 | | - }) |
107 | | - .fail(function() { |
108 | | - alert( "error" ); |
109 | | - }) |
110 | | - return false; |
111 | | - }, |
112 | | - text: 'Confirm', |
113 | | - class:'primary' |
114 | | - }, |
115 | | - "Cancel" : function() { |
116 | | - $(this).dialog("close"); |
117 | | - } |
118 | | - } |
119 | | - }); |
120 | | - $("#dialog-confirm").dialog('open'); |
121 | | - |
122 | | - //cell.getRow().delete(); |
123 | | - }}, |
124 | | - {formatter:editIcon, width:40, align:"center", cellClick:function(e, cell){ |
| 81 | + function getTags(){ |
| 82 | + var baseUrl = OC.generateUrl('/apps/timetracker/ajax/tags'); |
125 | 83 |
|
126 | | - dialogTagEditForm.target = cell.getRow().getData().id; |
127 | | - |
128 | | - form = dialogTagEditForm.find( "form" ) |
129 | | - form.find("#name").val(cell.getRow().getData().name); |
130 | | - dialogTagEditForm.dialog("open"); |
| 84 | + var editIcon = function(cell, formatterParams){ //plain text value |
| 85 | + return "<i class='fa fa-edit'></i>"; |
| 86 | + }; |
131 | 87 |
|
132 | | - }}, |
133 | | - ]; |
| 88 | + $.get(baseUrl, function(data){ |
| 89 | + $('#tags').html(''); |
| 90 | + var contentList = $('<div/>').addClass('app-content-list'); |
| 91 | + for (tag of data.Tags) { |
| 92 | + console.log(tag); |
| 93 | + var listItem = $('<a/>', {href:'#'}).addClass('app-content-list-item'); |
| 94 | + listItem.append($('<div/>').addClass('app-content-list-item-icon') |
| 95 | + .addClass('icon-tag-white') |
| 96 | + .css('background-color', 'rgb(100,100,100)')); |
| 97 | + listItem.append($('<div/>').addClass('app-content-list-item-line-one').text(tag.name)); |
| 98 | + listItem.append($('<div/>').addClass('icon-delete').click(function(event){ |
| 99 | + event.stopPropagation(); |
| 100 | + $("#dialog-confirm").dialog({ |
| 101 | + buttons : { |
| 102 | + "Confirm" : {click: function() { |
| 103 | + var baseUrl = OC.generateUrl('/apps/timetracker/ajax/delete-tag/'+tag.id); |
| 104 | + var jqxhr = $.post( baseUrl, function() { |
| 105 | + getTags(); |
| 106 | + $("#dialog-confirm").dialog("close"); |
| 107 | + }) |
| 108 | + .done(function(data, status, jqXHR) { |
| 109 | + var response = data; |
| 110 | + if ('Error' in response){ |
| 111 | + alert(response.Error); |
| 112 | + } |
| 113 | + }) |
| 114 | + .fail(function() { |
| 115 | + alert( "error" ); |
| 116 | + }) |
| 117 | + return false; |
| 118 | + }, |
| 119 | + text: 'Confirm', |
| 120 | + class:'primary' |
| 121 | + }, |
| 122 | + "Cancel" : function() { |
| 123 | + $(this).dialog("close"); |
| 124 | + } |
| 125 | + } |
| 126 | + }); |
| 127 | + $("#dialog-confirm").dialog('open'); |
| 128 | + })); |
| 129 | + listItem.click(function(){ |
| 130 | + dialogTagEditForm.target = tag.id; |
134 | 131 |
|
135 | | - var table = new Tabulator("#tags", { |
136 | | - ajaxURL:baseUrl, |
137 | | - layout:"fitColumns", |
138 | | - columns:columns, |
139 | | - rowClick:function(e, row){ |
140 | | - return false; |
141 | | - }, |
142 | | - ajaxResponse:function(url, params, response){ |
143 | | - |
144 | | - return response.Tags; //return the tableData property of a response json object |
145 | | - }, |
146 | | - }); |
| 132 | + form = dialogTagEditForm.find( "form" ) |
| 133 | + form.find("#name").val(tag.name); |
| 134 | + dialogTagEditForm.dialog("open"); |
| 135 | + }); |
| 136 | + contentList.append(listItem); |
| 137 | + } |
| 138 | + $('#tags').append(contentList); |
| 139 | + }); |
147 | 140 | } |
148 | | - } ); |
| 141 | + }); |
149 | 142 | }()); |
0 commit comments