|
| 1 | +var $ = require("jquery"); |
| 2 | +require("jquery-migrate"); |
| 3 | +// var moment = require("moment"); |
| 4 | +require("jqueryui"); |
| 5 | +//require("jqueryui/jquery-ui.css"); |
| 6 | +import Tabulator from 'tabulator-tables'; |
| 7 | +require('tabulator-tables/dist/css/tabulator.css'); |
| 8 | + |
| 9 | +import 'select2/dist/js/select2.full.js' |
| 10 | +require('select2/dist/css/select2.css'); |
| 11 | + |
| 12 | +require('../../css/style.css'); |
| 13 | +(function() { |
| 14 | + $.ajaxSetup({ |
| 15 | + headers: { 'RequestToken': OC.requestToken } |
| 16 | + }); |
| 17 | + |
| 18 | + $( function() { |
| 19 | + var newGoalProjectId; |
| 20 | + $(document).ready(function() { |
| 21 | + $("#dialog-confirm").dialog({ |
| 22 | + autoOpen: false, |
| 23 | + modal: true |
| 24 | + }); |
| 25 | + }); |
| 26 | + |
| 27 | + |
| 28 | + $("#project-select").select2({ |
| 29 | + width: '200px', |
| 30 | + escapeMarkup : function(markup) { return markup; }, |
| 31 | + placeholder: "Select project", |
| 32 | + allowClear: true, |
| 33 | + templateResult: function formatState (project) { |
| 34 | + var color = '#ffffff'; |
| 35 | + if (project.color) { |
| 36 | + color = project.color; |
| 37 | + } |
| 38 | + var $state = $( |
| 39 | + '<span class="select-project"><span class="select-project-color" style="background-color:'+color+';" ></span>' + project.text + '</span>' |
| 40 | + ); |
| 41 | + return $state; |
| 42 | + }, |
| 43 | + ajax: { |
| 44 | + tags: true, |
| 45 | + url: OC.generateUrl('/apps/timetracker/ajax/projects'), |
| 46 | + |
| 47 | + dataType: 'json', |
| 48 | + delay: 250, |
| 49 | + |
| 50 | + processResults: function (data, page) { //json parse |
| 51 | + return { |
| 52 | + results: $.map(data.Projects,function(val, i){ |
| 53 | + return { id: val.id, text:val.name, color: val.color}; |
| 54 | + }), |
| 55 | + pagination: { |
| 56 | + more: false, |
| 57 | + } |
| 58 | + }; |
| 59 | + }, |
| 60 | + cache: false, |
| 61 | + |
| 62 | + }, |
| 63 | + }); |
| 64 | + $('#project-select').on("select2:select select2:unselect", function(e) { |
| 65 | + newGoalProjectId = ($(e.target).val() != null)? $(e.target).val() : ""; |
| 66 | + }); |
| 67 | + |
| 68 | + |
| 69 | + $("#new-goal-submit").click(function () { |
| 70 | + if ($("#new-goal-hours").val().trim() == '') |
| 71 | + return false; |
| 72 | + var baseUrl = OC.generateUrl('/apps/timetracker/ajax/add-goal'); |
| 73 | + var jqxhr = $.post( baseUrl, { |
| 74 | + projectId : newGoalProjectId, |
| 75 | + hours: $("#new-goal-hours").val(), |
| 76 | + interval: $("#new-goal-interval").val(), |
| 77 | + }, function() { |
| 78 | + |
| 79 | + getGoals(); |
| 80 | + }) |
| 81 | + .done(function(data, status, jqXHR) { |
| 82 | + var response = data; |
| 83 | + if ('Error' in response){ |
| 84 | + alert(response.Error); |
| 85 | + } |
| 86 | + }) |
| 87 | + .fail(function() { |
| 88 | + alert( "error" ); |
| 89 | + }) |
| 90 | + return false; |
| 91 | + }); |
| 92 | + |
| 93 | + getGoals(); |
| 94 | + function getGoals(){ |
| 95 | + var baseUrl = OC.generateUrl('/apps/timetracker/ajax/goals'); |
| 96 | + |
| 97 | + var editIcon = function(cell, formatterParams){ //plain text value |
| 98 | + return "<i class='fa fa-edit'></i>"; |
| 99 | + }; |
| 100 | + |
| 101 | + |
| 102 | + var columns = [ |
| 103 | + {title:"#", field:"", formatter:"rownum", width: 40, align: "center"}, |
| 104 | + {title:"Project", field:"projectName", widthGrow:1}, //column will be allocated 1/5 of the remaining space |
| 105 | + {title:"Target Hours", field:"hours", widthGrow:1}, //column will be allocated 1/5 of the remaining space |
| 106 | + {title:"Interval", field:"interval", widthGrow:1}, //column will be allocated 1/5 of the remaining space |
| 107 | + {title:"Started At", field:"createdAt", widthGrow:1, mutator: function(value, data, type, params, component){ |
| 108 | + return new Date(data.createdAt*1000).toDateString();} |
| 109 | + }, //column will be allocated 1/5 of the remaining space |
| 110 | + {title:"Hours spent current interval", field:"workedHoursCurrentPeriod", widthGrow:1}, //column will be allocated 1/5 of the remaining space |
| 111 | + {title:"Past Debt in Hours", field:"debtHours", widthGrow:1}, //column will be allocated 1/5 of the remaining space |
| 112 | + {title:"Remaining Hours", field:"remainingHours", widthGrow:1}, //column will be allocated 1/5 of the remaining space |
| 113 | + {title:"Total Remaining Hours", field:"totalRemainingHours", widthGrow:1}, //column will be allocated 1/5 of the remaining space |
| 114 | + {formatter:"buttonCross", width:40, align:"center", cellClick:function(e, cell) { |
| 115 | + $("#dialog-confirm").dialog({ |
| 116 | + buttons : { |
| 117 | + "Confirm" : {click: function() { |
| 118 | + var baseUrl = OC.generateUrl('/apps/timetracker/ajax/delete-goal/'+cell.getRow().getData().id); |
| 119 | + var jqxhr = $.post( baseUrl, function() { |
| 120 | + getGoals(); |
| 121 | + $("#dialog-confirm").dialog("close"); |
| 122 | + }) |
| 123 | + .done(function(data, status, jqXHR) { |
| 124 | + var response = data; |
| 125 | + if ('Error' in response){ |
| 126 | + alert(response.Error); |
| 127 | + } |
| 128 | + }) |
| 129 | + .fail(function() { |
| 130 | + alert( "error" ); |
| 131 | + }) |
| 132 | + return false; |
| 133 | + }, |
| 134 | + text: 'Confirm', |
| 135 | + class:'primary' |
| 136 | + }, |
| 137 | + "Cancel" : function() { |
| 138 | + $(this).dialog("close"); |
| 139 | + } |
| 140 | + } |
| 141 | + }); |
| 142 | + $("#dialog-confirm").dialog('open'); |
| 143 | + |
| 144 | + //cell.getRow().delete(); |
| 145 | + }}, |
| 146 | + |
| 147 | + ]; |
| 148 | + |
| 149 | + var table = new Tabulator("#goals", { |
| 150 | + ajaxURL:baseUrl, |
| 151 | + layout:"fitColumns", |
| 152 | + columns:columns, |
| 153 | + rowClick:function(e, row){ |
| 154 | + return false; |
| 155 | + }, |
| 156 | + ajaxResponse:function(url, params, response){ |
| 157 | + |
| 158 | + return response.Goals; //return the tableData property of a response json object |
| 159 | + }, |
| 160 | + }); |
| 161 | + } |
| 162 | + } ); |
| 163 | +}()); |
0 commit comments