TaskManager.php.task.js 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931
  1. // @required var BASE_URL
  2. // @required var TASK
  3. // @required var USER
  4. // @required var TYPE
  5. // @required var ProblemsTableId
  6. // @required var ProjectsTableId
  7. var activeCount = 0;
  8. var allCount = 0;
  9. var acceptedCount = 0;
  10. var picker;
  11. var position = 0;
  12. var wordLen = 0;
  13. var projectId;
  14. var author;
  15. var state = [];
  16. var loaded;
  17. renderForm();
  18. /*$(document).on('click', '#save', function() {
  19. $("#save").prop('disabled', true);
  20. save();
  21. });*/
  22. function setSort() {
  23. var req = `
  24. <Transaction
  25. xmlns="http://www.opengis.net/wfs"
  26. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  27. version="1.0.0"
  28. service="WFS"
  29. xmlns:p5_default_db="` + BASE_WFS_URL + `/default_db/"
  30. xmlns:gml="http://www.opengis.net/gml">
  31. `;
  32. var i = 0;
  33. var idx = [];
  34. $("#sortable").find(".singleTask").each(function() {
  35. i++;
  36. req += `
  37. <Insert xmlns="http://www.opengis.net/wfs">
  38. <PROBLEMS xmlns="` + BASE_WFS_URL + `/default_db/">
  39. <ID xmlns="` + BASE_WFS_URL + `/default_db/">` + $(this).data("id") + `</ID>
  40. <SORT_PRIO xmlns="` + BASE_WFS_URL + `/default_db/">` + i + `</SORT_PRIO>
  41. </PROBLEMS>
  42. </Insert>
  43. `;
  44. idx.push($(this).data("id"));
  45. });
  46. req += `</Transaction>`;
  47. var link = BASE_URL + 'wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&';
  48. //console.log(req);
  49. $.ajax({
  50. url: link,
  51. data: req,
  52. type: 'POST',
  53. contentType: "text/xml",
  54. dataType: "xml",
  55. success: function(data) {
  56. //console.log(data);
  57. //console.log("sorted");
  58. if($(data).find("ServiceException").text() == ""){
  59. $.notify("Sortowanie zsynchronizowane", "success");
  60. }else{
  61. $.notify($(data).find("ServiceException").text(), "danger");
  62. $.notify("Błąd. Skontaktuj się z administratorem", "error");
  63. }
  64. }
  65. });
  66. var temp = [];
  67. $.each(idx, function(i, e){
  68. var index = getIndexById(e);
  69. temp.push(state[index]);
  70. });
  71. $.each(state, function(i, e){
  72. if(e['percent'] == "100%")
  73. temp.push(e);
  74. });
  75. state = [];
  76. state = temp;
  77. render();
  78. }
  79. function createLink(name, id) {
  80. if (TYPE == "PROBLEM") return 'index.php?_route=ViewTableAjax&namespace=default_db/' + "PROBLEMS" + '#EDIT/' + id
  81. if (TYPE == "PROJECT") return 'index.php?_route=ViewTableAjax&namespace=default_db/' + "IN7_MK_BAZA_DYSTRYBUCJI" + '#EDIT/' + id
  82. return '#'
  83. }
  84. function getDetails(value) {
  85. var date = false;
  86. var worker = false;
  87. $.each(value.split(" "), function(i, e) {
  88. if (e.substr(0, 1) == "@") {
  89. var query = e.substr(1);
  90. if (query != "" && isNaN(query.substr(0, 1)) && !worker) {
  91. worker = query;
  92. }
  93. if (query != "" && !isNaN(query.substr(0, 1)) && !date) {
  94. date = moment(query).format('YYYY-MM-DD HH:mm:ss');
  95. }
  96. }
  97. });
  98. return {
  99. worker: worker,
  100. date: date
  101. };
  102. }
  103. //Deleted function to save changes.
  104. /*function save() {
  105. var link = BASE_URL + 'wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&';
  106. var saveQuery = `
  107. <Transaction
  108. xmlns="http://www.opengis.net/wfs"
  109. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  110. version="1.0.0"
  111. service="WFS"
  112. xmlns:p5_default_db="` + BASE_URL + `wfs/default_db/PROBLEMS"
  113. xsi:schemaLocation="` + BASE_URL + `wfs/default_db/PROBLEMS ` + BASE_URL + `dev-pl/se-feature-api/wfs.php/xml/wfs/default_db/PROBLEMS/?SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=p5_default_db:PROBLEMS&amp;SRSNAME=EPSG:4326&amp;"
  114. xmlns:gml="http://www.opengis.net/gml">
  115. <Insert xmlns="http://www.opengis.net/wfs">
  116. <PROBLEMS xmlns="` + BASE_URL + `wfs/default_db/PROBLEMS">
  117. <ID xmlns="` + BASE_URL + `wfs/default_db/CRM_PROCES">` + TASK + `</ID>
  118. `;
  119. $("#left").find("input").each(function() {
  120. saveQuery += '<' + $(this).attr("name") + ' xmlns="' + BASE_URL + 'wfs/default_db/PROBLEMS">' + $(this).val() + '</' + $(this).attr("name") + '>\n';
  121. });
  122. $("#left").find("select").each(function() {
  123. saveQuery += '<' + $(this).attr("name") + ' xmlns="' + BASE_URL + 'wfs/default_db/PROBLEMS">' + $(this).find("option:selected").text() + '</' + $(this).attr("name") + '>\n';
  124. });
  125. saveQuery += `
  126. </PROBLEMS>
  127. </Insert>
  128. </Transaction>
  129. `;
  130. //console.log(saveQuery);
  131. $.ajax({
  132. url: link,
  133. data: saveQuery,
  134. type: 'POST',
  135. contentType: "text/xml",
  136. dataType: "text",
  137. success: function(data) {
  138. //console.log(data);
  139. $.notify("Zapisano!", "success");
  140. $("#save").prop('disabled', false);
  141. renderForm();
  142. },
  143. error: function(xhr, ajaxOptions, thrownError) {
  144. $.notify("Brak połączenia z bazą danych", "error");
  145. }
  146. });
  147. }*/
  148. function updateProgress() {
  149. var proc;
  150. var procAcc;
  151. allCount = state.length;
  152. activeCount = 0;
  153. acceptedCount = 0;
  154. $.each(state, function(i, e){
  155. if (e["percent"] != "100%") {
  156. activeCount++;
  157. }
  158. if (e["status"] == "OFF_HARD") {
  159. acceptedCount++;
  160. }
  161. });
  162. if (allCount != 0) {
  163. proc = Math.round((allCount - activeCount) / allCount * 100 / 10) * 10;
  164. procAcc = Math.round((acceptedCount) / allCount * 100 / 10) * 10;
  165. } else {
  166. proc = 0;
  167. procAcc = 0;
  168. }
  169. $("#completed").css('width', proc - procAcc + "%").attr('aria-valuenow', proc - procAcc).text(proc + '%');
  170. $("#accepted").css('width', procAcc + "%").attr('aria-valuenow', procAcc).text(procAcc + '%');
  171. if (proc == 0) {
  172. $("#completed").text("");
  173. }
  174. if (procAcc == 0) {
  175. $("#accepted").text("");
  176. }
  177. if(proc == procAcc){
  178. $("#completed").text("");
  179. }
  180. }
  181. function getCaretPosition(ctrl) {
  182. var start, end;
  183. if (ctrl.setSelectionRange) {
  184. start = ctrl.selectionStart;
  185. end = ctrl.selectionEnd;
  186. } else if (document.selection && document.selection.createRange) {
  187. var range = document.selection.createRange();
  188. start = 0 - range.duplicate().moveStart('character', -100000);
  189. end = start + range.text.length;
  190. }
  191. return {
  192. start: start,
  193. end: end
  194. }
  195. }
  196. $(document).on('dblclick', '#sortable li', function(e) {
  197. var link = BASE_URL + 'wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&';
  198. var index = getIndexById($(this).data("id"));
  199. var req = `
  200. <Transaction
  201. xmlns="http://www.opengis.net/wfs"
  202. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  203. version="1.0.0"
  204. service="WFS"
  205. xmlns:p5_default_db="` + BASE_URL + `wfs/default_db/PROBLEMS"
  206. xsi:schemaLocation="` + BASE_URL + `wfs/default_db/PROBLEMS` + BASE_URL + `dev-pl/se-feature-api/wfs.php/xml/wfs/default_db/PROBLEMS/?SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=p5_default_db:PROBLEMS&amp;SRSNAME=EPSG:4326&amp;"
  207. xmlns:gml="http://www.opengis.net/gml">
  208. `;
  209. req += `
  210. <Insert xmlns="http://www.opengis.net/wfs">
  211. <PROBLEMS xmlns="` + BASE_URL + `wfs/default_db/PROBLEMS">
  212. <ID xmlns="` + BASE_URL + `wfs/default_db/PROBLEMS">` + $(this).data("id") + `</ID>`;
  213. if (state[index]["status"] == "NORMAL") {
  214. state[index]["status"] = "WAITING";
  215. req += '<A_STATUS xmlns="' + BASE_URL + 'wfs/default_db/PROBLEMS">WAITING</A_STATUS>';
  216. } else if (state[index]["status"] == "WAITING") {
  217. state[index]["status"] = "NORMAL";
  218. req += '<A_STATUS xmlns="' + BASE_URL + 'wfs/default_db/PROBLEMS">NORMAL</A_STATUS>';
  219. }
  220. req += `</PROBLEMS>
  221. </Insert>
  222. </Transaction>`;
  223. render();
  224. $.ajax({
  225. url: link,
  226. data: req,
  227. type: 'POST',
  228. contentType: "text/xml",
  229. dataType: "text",
  230. success: function(data) {}
  231. });
  232. });
  233. function autoCom() {
  234. var hide = true;
  235. $(".eInput").autocomplete({
  236. source: function(request, response) {
  237. $.ajax({
  238. url: BASE_URL + 'wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=p5_default_db:ADMIN_USERS&SRSNAME=EPSG:3003&Filter=<ogc:Filter><ogc:PropertyIsLike wildCard="*" singleChar="^" escapeChar="!"><ogc:PropertyName>ADM_ACCOUNT</ogc:PropertyName><ogc:Literal>*' + request.term + '*</ogc:Literal></ogc:PropertyIsLike></ogc:Filter>&maxFeatures=10',
  239. dataType: "xml",
  240. success: function(xmlResponse) {
  241. var data = $("featureMember", xmlResponse).map(function() {
  242. if ($("ID", this).text() != 0)
  243. return {
  244. value: $("ADM_ACCOUNT", this).text(),
  245. id: $("ID", this).text()
  246. };
  247. });
  248. response(data);
  249. }
  250. });
  251. },
  252. search: function() {
  253. if (hide) return false;
  254. },
  255. select: function(event, ui) {
  256. var text = this.value;
  257. this.value = text.substring(0, position) + " @" +
  258. ui.item.value + " " + text.substring(position + wordLen + 2);
  259. return false;
  260. },
  261. focus: function() {
  262. return false;
  263. },
  264. minLength: 0
  265. }).bind("keyup", function() {
  266. hide = true;
  267. $(this).autocomplete("close");
  268. var caret = getCaretPosition(this);
  269. var val = this.value;
  270. val += " ";
  271. var result = /\S+$/.exec(val.slice(0, val.indexOf(' ', caret.end)));
  272. var lastWord = result ? result[0] : null;
  273. if (lastWord != null && lastWord.substring(0, 1) == "@") {
  274. wordLen = lastWord.length;
  275. var query = lastWord.substr(1);
  276. if (isNaN(query.substring(0, 1)) && query != "") {
  277. hide = false;
  278. if (val.substr(0, caret.end).lastIndexOf(" ") > 0) {
  279. position = val.substr(0, caret.end).lastIndexOf(" ");
  280. } else {
  281. position = 0;
  282. }
  283. }
  284. if (!isNaN(query.substring(0, 1)) && query != "") {
  285. if (val.substr(0, caret.end).lastIndexOf(" ") > 0) {
  286. position = val.substr(0, caret.end).lastIndexOf(" ");
  287. } else {
  288. position = 0;
  289. }
  290. $(picker).data("DateTimePicker").show();
  291. }
  292. }
  293. $(this).autocomplete("search", query);
  294. });
  295. }
  296. $(document).on('keydown', '.hours', function(e) {
  297. var textarea = this;
  298. if (e.which == 13) {
  299. $(textarea).prop("disabled", true);
  300. var req = `
  301. <Transaction
  302. xmlns="http://www.opengis.net/wfs"
  303. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  304. version="1.0.0"
  305. service="WFS"
  306. xmlns:p5_default_db="` + BASE_WFS_URL + `/default_db/"
  307. xsi:schemaLocation="` + BASE_WFS_URL + `/default_db/` + BASE_URL + `dev-pl/se-feature-api/wfs.php/xml/wfs/default_db/PROBLEMS/?SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=p5_default_db:PROBLEMS&amp;SRSNAME=EPSG:4326&amp;"
  308. xmlns:gml="http://www.opengis.net/gml">
  309. `;
  310. req += `
  311. <Insert xmlns="http://www.opengis.net/wfs">
  312. <PROBLEMS xmlns="` + BASE_WFS_URL + `/default_db">
  313. <ID xmlns="` + BASE_WFS_URL + `/default_db">` + $(this).parents("li").data('id') + `</ID>
  314. <L_APPOITMENT_PERIOD xmlns="` + BASE_WFS_URL + `/default_db">` + $(textarea).val()+ `</L_APPOITMENT_PERIOD>
  315. </PROBLEMS>
  316. </Insert>`;
  317. req += '</Transaction>';
  318. var id = getIndexById($(this).parents("li").data('id'));
  319. var period = $(this).val();
  320. var link = BASE_URL + 'wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&';
  321. //console.log(req);
  322. $.ajax({
  323. url: link,
  324. data: req,
  325. type: 'POST',
  326. contentType: "text/xml",
  327. dataType: "xml",
  328. success: function(data) {
  329. //console.log(data);
  330. $.notify("Zapisano!", "success");
  331. state[id]["period"] = period;
  332. render();
  333. }
  334. });
  335. }
  336. });
  337. $(document).on('keydown', '.editable', function(e) {
  338. var textarea = this;
  339. if (e.keyCode == 13) {
  340. $(textarea).prop("disabled", true);
  341. var details = getDetails($(this).val());
  342. var req = `
  343. <Transaction
  344. xmlns="http://www.opengis.net/wfs"
  345. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  346. version="1.0.0"
  347. service="WFS"
  348. xmlns:p5_default_db="` + BASE_WFS_URL + `/default_db/"
  349. xmlns:gml="http://www.opengis.net/gml">
  350. `;
  351. req += `
  352. <Insert xmlns="http://www.opengis.net/wfs">
  353. <PROBLEMS xmlns="` + BASE_WFS_URL + `/default_db/">
  354. <ID xmlns="` + BASE_WFS_URL + `/default_db/">` + $(this).parents("li").data('id') + `</ID>`;
  355. if (details.worker != false)
  356. req += '<L_APPOITMENT_USER xmlns="' + BASE_WFS_URL + '/default_db/">' + details.worker + '</L_APPOITMENT_USER>';
  357. else
  358. req += '<L_APPOITMENT_USER xmlns="' + BASE_WFS_URL + '/default_db/">' + USER + '</L_APPOITMENT_USER>';
  359. if (details.date != false)
  360. req += '<A_PROBLEM_DATE xmlns="' + BASE_WFS_URL + '/default_db/">' + details.date + '</A_PROBLEM_DATE>';
  361. else
  362. req += '<A_PROBLEM_DATE xmlns="' + BASE_WFS_URL + '/default_db/">' + moment().format('YYYY-MM-DD HH:mm:ss') + '</A_PROBLEM_DATE>';
  363. req += `<A_PROBLEM_DESC xmlns="` + BASE_WFS_URL + `/default_db/">` + $(this).val() + `</A_PROBLEM_DESC>
  364. <CUSTOMER_ADMIN_USER xmlns="` + BASE_WFS_URL + `/default_db/">BRAK</CUSTOMER_ADMIN_USER>
  365. </PROBLEMS>
  366. </Insert>`;
  367. req += '</Transaction>';
  368. var id = getIndexById($(this).parents("li").data('id'));
  369. var desc = $(this).val();
  370. var link = BASE_URL + 'wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&';
  371. $.ajax({
  372. url: link,
  373. data: req,
  374. type: 'POST',
  375. contentType: "text/xml",
  376. dataType: "xml",
  377. success: function(data) {
  378. state[id]["desc"] = desc;
  379. if (details.worker != false) {
  380. state[id]["worker"] = details.worker
  381. } else {
  382. state[id]["worker"] = USER;
  383. }
  384. render();
  385. $.notify("Zapisano!", "success");
  386. }
  387. });
  388. return false;
  389. }
  390. });
  391. $(document).on('keydown', '.eInput', function(e) {
  392. if (e.keyCode == 13) {
  393. if ($(this).val() != "") {
  394. var details = getDetails($(this).val());
  395. var req = `
  396. <Transaction
  397. xmlns="http://www.opengis.net/wfs"
  398. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  399. version="1.0.0"
  400. service="WFS"
  401. xmlns:p5_default_db="` + BASE_WFS_URL + `/default_db/"
  402. xmlns:gml="http://www.opengis.net/gml">
  403. `;
  404. req += `
  405. <Insert xmlns="http://www.opengis.net/wfs">
  406. <PROBLEMS xmlns="` + BASE_WFS_URL + `/default_db/">`;
  407. if (TYPE == "PROBLEM") {
  408. req += `<PARENT_ID xmlns="` + BASE_WFS_URL + `/default_db/">` + TASK + `</PARENT_ID>`;
  409. }
  410. if (TYPE == "PROJECT") {
  411. req += `<PARENT_ID xmlns="` + BASE_WFS_URL + `/default_db/">0</PARENT_ID>`;
  412. }
  413. if (details.worker != false) {
  414. req += '<L_APPOITMENT_USER xmlns="' + BASE_WFS_URL + '/default_db/">' + details.worker + '</L_APPOITMENT_USER>';
  415. } else {
  416. req += '<L_APPOITMENT_USER xmlns="' + BASE_WFS_URL + '/default_db/">' + USER + '</L_APPOITMENT_USER>';
  417. }
  418. if (details.date != false) {
  419. req += '<A_PROBLEM_DATE xmlns="' + BASE_WFS_URL + '/default_db/">' + details.date + '</A_PROBLEM_DATE>';
  420. } else {
  421. req += '<A_PROBLEM_DATE xmlns="' + BASE_WFS_URL + '/default_db/">' + moment().format('YYYY-MM-DD HH:mm:ss') + '</A_PROBLEM_DATE>';
  422. }
  423. req += `<ID_PROJECT xmlns="` + BASE_WFS_URL + `/default_db">` + ProjectId + `</ID_PROJECT>`;
  424. req += `<L_APPOITMENT_PERIOD xmlns="` + BASE_WFS_URL + `/default_db">0</L_APPOITMENT_PERIOD>`;
  425. req += `<A_PROBLEM_DESC xmlns="` + BASE_WFS_URL + `/default_db">` + $(this).val() + `</A_PROBLEM_DESC>
  426. <CUSTOMER_ADMIN_USER xmlns="` + BASE_WFS_URL + `/default_db">BRAK</CUSTOMER_ADMIN_USER>
  427. </PROBLEMS>
  428. </Insert>`;
  429. req += '</Transaction>';
  430. var link = BASE_URL + 'wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&';
  431. var info = this;
  432. //console.log(req);
  433. $.ajax({
  434. url: link,
  435. data: req,
  436. type: 'POST',
  437. contentType: "text/xml",
  438. dataType: "xml",
  439. success: function(data) {
  440. //console.log(data);
  441. if($(data).find("ServiceException").text() != ""){
  442. $.notify("Błąd API: Prawdopodobnie nie masz uprawnień. Skontaktuj się z administratorem.", "error");
  443. $.notify($(data).find("ServiceException").text(), "danger");
  444. }else{
  445. var temp = {};
  446. temp["id"] = $(data).find("FeatureId").attr("fid").substr($(data).find("FeatureId").attr("fid").indexOf('.') + 1);
  447. temp["desc"] = $(info).val();
  448. temp["percent"] = "0%";
  449. temp["period"] = "0";
  450. temp["childs"] = false;
  451. temp["status"] = "WAITING";
  452. temp["worker"] = (details.worker != false ? details.worker : USER);
  453. temp["owner"] = USER;
  454. state.push(temp);
  455. $(".eInput").val("");
  456. //console.log(temp);
  457. //console.log("x", state);
  458. updateProgress();
  459. render();
  460. setSort();
  461. }
  462. }
  463. });
  464. }
  465. return false;
  466. }
  467. });
  468. $(document).on('click', '.delTask', function() {
  469. var id = $(this).closest(".singleTask").data("id");
  470. var index = getIndexById(id);
  471. if ($(this).parents(".singleTask").find(".aCheck").data("state") == "1") {
  472. $.notify("Nie możesz zmieniać stanu zatwierdzonych zadań", "danger");
  473. return true;
  474. }
  475. if(state[index]['childs'] != false){
  476. $.notify("Zmieniać status można tylko wtedy, jeżeli zadanie nie ma podzadań.", "danger");
  477. return;
  478. }
  479. if ($(this).parents(".singleTask").data("step") == 2) {
  480. allCount--;
  481. } else {
  482. allCount--;
  483. activeCount--;
  484. }
  485. var req = `
  486. <Transaction
  487. xmlns="http://www.opengis.net/wfs"
  488. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  489. version="1.0.0"
  490. service="WFS"
  491. xmlns:p5_default_db="` + BASE_WFS_URL + `/default_db/"
  492. xmlns:gml="http://www.opengis.net/gml">
  493. `;
  494. req += `
  495. <Insert xmlns="http://www.opengis.net/wfs">
  496. <PROBLEMS xmlns="` + BASE_WFS_URL + `/default_db/">`;
  497. req += `<ID xmlns="` + BASE_WFS_URL + `/default_db/">` + id + `</ID>`;
  498. req += `<A_STATUS xmlns="` + BASE_WFS_URL + `/default_db/">DELETED</A_STATUS>
  499. </PROBLEMS>
  500. </Insert>`;
  501. req += '</Transaction>';
  502. var link = BASE_URL + 'wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&';
  503. $.ajax({
  504. url: link,
  505. data: req,
  506. type: 'POST',
  507. contentType: "text/xml",
  508. dataType: "xml",
  509. success: function(data) {
  510. }
  511. });
  512. state.splice(index, 1);
  513. render();
  514. });
  515. $(document).on('click', '#showMore', function() {
  516. if ($("#doneList").is(":visible")) {
  517. $("#doneList").slideUp("fast");
  518. $(this).html("Pokaż wykonane zadania <span class='glyphicon glyphicon-chevron-down'></span>");
  519. } else {
  520. $("#doneList").slideDown("fast");
  521. $(this).html("Ukryj wykonane zadania <span class='glyphicon glyphicon-chevron-up'></span>");
  522. }
  523. });
  524. $(document).on('click', '.aCheck', function() {
  525. var node = this;
  526. var id = getIndexById($(node).parents("li").data("id"));
  527. if (state[id]["owner"] != USER) {
  528. $.notify("Tylko zleceniodawca może zatwierdzać postęp prac.", "danger");
  529. return true;
  530. }
  531. var link = BASE_URL + 'wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&';
  532. var req = `
  533. <Transaction
  534. xmlns="http://www.opengis.net/wfs"
  535. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  536. version="1.0.0"
  537. service="WFS"
  538. xmlns:p5_default_db="` + BASE_WFS_URL + `/default_db"
  539. xmlns:gml="http://www.opengis.net/gml">
  540. `;
  541. req += `
  542. <Insert xmlns="http://www.opengis.net/wfs">
  543. <PROBLEMS xmlns="` + BASE_WFS_URL + `/default_db">
  544. <ID xmlns="` + BASE_WFS_URL + `/default_db">` + $(node).parents("li").data("id") + `</ID>`;
  545. if (state[id]['status'] != "OFF_HARD") {
  546. req += '<A_STATUS xmlns="' + BASE_WFS_URL + '/default_db">OFF_HARD</A_STATUS>';
  547. state[id]['status'] = "OFF_HARD";
  548. } else {
  549. req += '<A_STATUS xmlns="' + BASE_WFS_URL + '/default_db">WAITING</A_STATUS>';
  550. state[id]['status'] = "WAITING";
  551. }
  552. req += `</PROBLEMS>
  553. </Insert>
  554. </Transaction>`;
  555. //console.log(req);
  556. $.ajax({
  557. url: link,
  558. data: req,
  559. type: 'POST',
  560. contentType: "text/xml",
  561. dataType: "text",
  562. success: function(data) {
  563. //console.log(data);
  564. setSort();
  565. updateProgress();
  566. render();
  567. }
  568. });
  569. });
  570. function getIndexById(id){
  571. for (var i = 0; i < state.length; i++) {
  572. if (state[i]['id'] == id) {
  573. return i;
  574. }
  575. }
  576. return false;
  577. }
  578. $(document).on('click', '.check', function() {
  579. var node = this;
  580. var id = $(node).parents("li").data("id");
  581. var index = getIndexById(id);
  582. if (state[index]['status'] == "OFF_HARD") {
  583. $.notify("Nie możesz zmieniać stanu zatwierdzonych zadań", "danger");
  584. return true;
  585. }
  586. if(state[index]['childs'] != false){
  587. $.notify("Zmieniać status można tylko wtedy, jeżeli zadanie nie ma podzadań.", "danger");
  588. return;
  589. }
  590. var link = BASE_URL + 'wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&';
  591. var req = `
  592. <Transaction
  593. xmlns="http://www.opengis.net/wfs"
  594. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  595. version="1.0.0"
  596. service="WFS"
  597. xmlns:p5_default_db="` + BASE_WFS_URL + `/default_db"
  598. xmlns:gml="http://www.opengis.net/gml">
  599. `;
  600. req += `
  601. <Insert xmlns="http://www.opengis.net/wfs">
  602. <PROBLEMS xmlns="` + BASE_URL + `/default_db">
  603. <ID xmlns="` + BASE_WFS_URL + `/default_db">` + $(node).parents("li").data("id") + `</ID>`;
  604. if (state[index]['percent'] != "100%") {
  605. req += '<A_PROBLEM_COMPLETE_PERCENT xmlns="' + BASE_WFS_URL + '/default_db/PROBLEMS">100%</A_PROBLEM_COMPLETE_PERCENT>';
  606. state[index]['percent'] = "100%";
  607. } else {
  608. req += '<A_PROBLEM_COMPLETE_PERCENT xmlns="' + BASE_WFS_URL + '/default_db/PROBLEMS">0%</A_PROBLEM_COMPLETE_PERCENT>';
  609. state[index]['percent'] = "0%";
  610. }
  611. req += `</PROBLEMS>
  612. </Insert>
  613. </Transaction>`;
  614. $.ajax({
  615. url: link,
  616. data: req,
  617. type: 'POST',
  618. contentType: "text/xml",
  619. dataType: "text",
  620. success: function(data) {
  621. setSort();
  622. }
  623. });
  624. updateProgress();
  625. render();
  626. });
  627. function stripHTML(dirtyString) {
  628. var container = document.createElement('div');
  629. var text = document.createTextNode(dirtyString);
  630. container.appendChild(text);
  631. return container.innerHTML; // innerHTML will be a xss safe string
  632. }
  633. function renderForm() {
  634. $("#left").empty();
  635. var link, link2;
  636. if (TYPE == "PROBLEM") {
  637. link = BASE_URL + "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&TYPENAME=p5_default_db:PROBLEMS&REQUEST=DescribeFeatureTypeAdvanced";
  638. link2 = BASE_URL + "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=p5_default_db:PROBLEMS&SRSNAME=EPSG:3003&Filter=<ogc:Filter><ogc:PropertyIsEqualTo><ogc:PropertyName>ID</ogc:PropertyName><ogc:Literal>" + TASK + "</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter>";
  639. }
  640. if (TYPE == "PROJECT") {
  641. link = BASE_URL + "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&TYPENAME=p5_default_db:IN7_MK_BAZA_DYSTRYBUCJI&REQUEST=DescribeFeatureTypeAdvanced";
  642. link2 = BASE_URL + "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=p5_default_db:IN7_MK_BAZA_DYSTRYBUCJI&SRSNAME=EPSG:3003&Filter=<ogc:Filter><ogc:PropertyIsEqualTo><ogc:PropertyName>ID</ogc:PropertyName><ogc:Literal>" + TASK + "</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter>";
  643. }
  644. var field = '';
  645. $.get(link, function(fields) {
  646. $.get(link2, function(data) {
  647. author = $(data).find("A_RECORD_CREATE_AUTHOR").text();
  648. if (TYPE == "PROBLEM") {
  649. ProjectId = $(data).find("ID_PROJECT").text();
  650. }
  651. if (TYPE == "PROJECT") {
  652. ProjectId = TASK;
  653. }
  654. if (TYPE == "PROBLEM") {
  655. var breadcrumb = `
  656. <ol class="breadcrumb">
  657. ` + ($(data).find("ID_PROJECT").text() != 0 ? "<li><a href='" + BASE_URL + "index.php?_route=UrlAction_TaskManager&ID_PROJECT=" + $(data).find("ID_PROJECT").text() + "'> Projekt " + $(data).find("ID_PROJECT").text() + "</a></li>" : "") + `
  658. ` + ($(data).find("PARENT_ID").text() != 0 ? "<li><a href='" + BASE_URL + "index.php?_route=UrlAction_TaskManager&ID_PROBLEM=" + $(data).find("PARENT_ID").text() + "'> Zadanie " + $(data).find("PARENT_ID").text() + "</a></li>" : "") + `
  659. <li class="active">Zadanie ` + $(data).find("ID").text() + ` </li>
  660. </ol>`;
  661. }
  662. if (TYPE == "PROJECT") {
  663. var breadcrumb = `
  664. <ol class="breadcrumb">
  665. <li class=active> Projekt ` + TASK + `</li>
  666. </ol>`;
  667. }
  668. $("#left").append(breadcrumb);
  669. field += '';
  670. $(fields).find("sequence").find("element").each(function() {
  671. var show = true;
  672. if ($(this).attr('name') == "ID") {
  673. show = false;
  674. }
  675. if (show) {
  676. field += '<div class="form-group">';
  677. field += '<label class="col-xs-12 col-sm-12 col-md-12 control-label" for="' + $(this).attr('name') + '">';
  678. if ($(this).attr('p5:label')) {
  679. field += $(this).attr('p5:label');
  680. } else {
  681. field += $(this).attr('name');
  682. }
  683. field += ' <i class="glyphicon glyphicon-info-sign frm-help" data-toggle="popover" data-trigger="hover" title="" data-content="' + stripHTML($(this).attr('p5:description')) + '" data-original-title="' + $(this).attr('name') + '">';
  684. field += '</i>';
  685. field += '</label>';
  686. field += '<div class="col-xs-12 col-sm-12 col-md-12">';
  687. var value = $(data).find($(this).attr('name')).text();
  688. if ($(this).attr('p5:allow_write') == "true") {
  689. if ($(this).attr('type') == "gml:LineStringPropertyType") {
  690. field += '...';
  691. } else if ($(this).attr('type') == "xsd:string" || $(this).attr('type') == "xsd:integer" || true) {// || true due to changes of saving system.
  692. field += '<input readOnly name="' + $(this).attr('name') + '" type="text" value="' + $(data).find($(this).attr('name')).text() + '" maxlength="255" class="form-control">';
  693. } else if ($(this).attr('type') == "xsd:dateTime") {
  694. field += '<div class="input-group"><input name="' + $(this).attr('name') + '" readOnly type="text" value="' + value + '" maxlength="255" class="se_type-datetime form-control" data-format="yyyy-MM-dd hh:mm"><span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></div>';
  695. } else {
  696. field += '<select name="' + $(this).attr('name') + '" class="form-control"><option></option>';
  697. $(fields).find("simpleType[name='" + $(this).attr('type').replace("p5_default_db:", "") + "']").find("enumeration").each(function() {
  698. if (value == $(this).attr("value")) {
  699. field += '<option selected=SELECTED >' + $(this).attr("value") + '</option>';
  700. } else {
  701. field += '<option >' + $(this).attr("value") + '</option>';
  702. }
  703. });
  704. field += "</select>";
  705. }
  706. } else {
  707. field += $(data).find($(this).attr('name')).text();
  708. }
  709. field += '</div>';
  710. field += '<div class=clearfix></div></div>';
  711. }
  712. });
  713. field += '<div class="form-group">';
  714. field += '<div class="col-xs-offset-0 col-xs-12 col-sm-offset-3 col-sm-9 col-md-offset-2 col-md-10">';
  715. field += '</div></div>';
  716. field += '<a class="btn btn-primary" href="' + createLink("PROBLEMS", TASK) + '">Edytuj</a>';
  717. $("#left").append(field);
  718. $("#left").append("<div class=clearfix></div>");
  719. createLink("PROBLEMS", TASK, $("#save").parents("a"));
  720. //renderTaskManager();
  721. getData();
  722. });
  723. });
  724. }
  725. $(document).ajaxStop(function() {
  726. if (loaded) return;
  727. loaded = true;
  728. renderTaskManager();
  729. });
  730. function getData() {
  731. if (TYPE == "PROBLEM") {
  732. link = BASE_URL + 'wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=p5_default_db:PROBLEMS&SRSNAME=EPSG:3003&Filter=<ogc:Filter><ogc:And><ogc:PropertyIsEqualTo><ogc:PropertyName>PARENT_ID</ogc:PropertyName><ogc:Literal>' + TASK + '</ogc:Literal></ogc:PropertyIsEqualTo><ogc:Not><ogc:PropertyIsEqualTo><ogc:PropertyName>A_STATUS</ogc:PropertyName><ogc:Literal>Deleted</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Not></ogc:And></ogc:Filter>&sortBy=ID+D';//SORT_PRIO+A';
  733. }
  734. if (TYPE == "PROJECT") {
  735. link = BASE_URL + 'wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=p5_default_db:PROBLEMS&SRSNAME=EPSG:3003&Filter=<ogc:Filter><ogc:And><ogc:PropertyIsEqualTo><ogc:PropertyName>ID_PROJECT</ogc:PropertyName><ogc:Literal>' + TASK + '</ogc:Literal></ogc:PropertyIsEqualTo><ogc:PropertyIsEqualTo><ogc:PropertyName>PARENT_ID</ogc:PropertyName><ogc:Literal>0</ogc:Literal></ogc:PropertyIsEqualTo><ogc:Not><ogc:PropertyIsEqualTo><ogc:PropertyName>A_STATUS</ogc:PropertyName><ogc:Literal>DELETED</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Not></ogc:And></ogc:Filter>&sortBy=ID+D';//SORT_PRIO+A
  736. }
  737. $.get(link, function(data) {
  738. loaded = false;
  739. //console.log(data);
  740. var count = $(data).find("featureMember").length;
  741. $(data).find("featureMember").each(function(e) {
  742. if ($(this).find("ID").text() == 0) {
  743. return;
  744. }
  745. var temp = {};
  746. temp["id"] = $(this).find("ID").text();
  747. temp["desc"] = $(this).find("A_PROBLEM_DESC").text();
  748. temp["percent"] = $(this).find("A_PROBLEM_COMPLETE_PERCENT").text();
  749. if(temp["percent"] === ""){
  750. //console.log(temp);
  751. $.notify("Błąd krytyczny. Brak uprawnień do komórki: `A_PROBLEM_COMPLETE_PERCENT` w tabeli `PROBLEMS`", "error");
  752. loaded = true;
  753. return false;
  754. }
  755. temp["status"] = $(this).find("A_STATUS").text();
  756. temp["worker"] = $(this).find("L_APPOITMENT_USER").text();
  757. temp["period"] = $(this).find("L_APPOITMENT_PERIOD").text();
  758. temp["owner"] = $(this).find("A_RECORD_CREATE_AUTHOR").text();
  759. temp["childs"] = false;
  760. var linkChilds = BASE_URL + "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=p5_default_db:PROBLEMS&SRSNAME=EPSG:3003&Filter=<ogc:Filter><ogc:PropertyIsEqualTo><ogc:PropertyName>PARENT_ID</ogc:PropertyName><ogc:Literal>" + temp["id"] + "</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter>";
  761. $.get(linkChilds, function(data) {
  762. //console.log(data);
  763. if ($(data).find("ID").text() != '') {
  764. temp["childs"] = true;
  765. }
  766. state.push(temp);
  767. });
  768. });
  769. });
  770. }
  771. function render() {
  772. var resultActive = "";
  773. var resultDone = "";
  774. //console.log(state);
  775. $.each(state, function(i, e) {
  776. var result = "";
  777. var css = "";
  778. if (e["percent"] != "100%") {
  779. if (e['status'] == "NORMAL") {
  780. css = "background: linear-gradient(to right, #73fb73 0%, #73fb73 " + e["percent"] + ", #bdefbd " + e["percent"] + ", #bdefbd 100%);";
  781. } else if (e['status'] == "WAITING") {
  782. css = "background: linear-gradient(to right, rgba(0,0,0,0.1) 0%, rgba(0,0,0,0.1) " + e["percent"] + ", transparent " + e["percent"] + ", transparent 100%);";
  783. }
  784. }
  785. result += "<li class=singleTask data-id=" + e["id"] + " style='"+css+"'>";
  786. result += "<span class='glyphicon glyphicon-option-vertical ico'></span>";
  787. if (e["percent"] == "100%") {
  788. result += "<span class=check style='background-color:#333333'></span>";
  789. if (e['status'] != "OFF_HARD") {
  790. result += "<span class=aCheck></span>";
  791. } else {
  792. result += "<span class=aCheck style=background-color:#2ecc71;></span>";
  793. }
  794. } else {
  795. result += "<span class=check></span>";
  796. }
  797. result += "<input type=text "+(e["childs"] ? "DISABLED" : "")+" class='form-control hours' value='"+e["period"]+"' style=width:40px;float:left;padding:0px;height:25px;>"
  798. result += "<textarea " + (USER != e["owner"] || e['status'] == "OFF_HARD" ? "DISABLED" : "") + ' class="editable" style="font-size:small">' + e['desc'] + "</textarea>";
  799. result += `<div class="dropdown" style=display:inline;>
  800. <span class="glyphicon glyphicon glyphicon-menu-hamburger" style="vertical-align: top;" data-toggle="dropdown"></span>
  801. <ul class="dropdown-menu dropdown-menu-right">
  802. <li><a href=` + BASE_URL + `index.php?_route=UrlAction_TaskManager&ID_PROBLEM=` + e['id'] + `>Szczegóły</a></li>
  803. <li><p style="cursor:pointer;padding:3px 20px;" class=delTask>Usuń</p></li>
  804. </ul>
  805. </div>`;
  806. result += ((e['owner'] != USER) ? " <span class='glyphicon glyphicon-user user' title='Zlecone przez inną osobę'></span>" : "") + "</li>";
  807. if (e['percent'] == "100%") {
  808. resultDone += result;
  809. } else {
  810. resultActive += result;
  811. }
  812. });
  813. resultActive += "<div class=clearfix></div>";
  814. resultDone += "<div class=clearfix></div>";
  815. $("#sortable").html(resultActive);
  816. $("#doneList").html(resultDone);
  817. $('.editable').autosize();
  818. }
  819. function loadStats(){
  820. var link;
  821. if (TYPE == "PROBLEM") {
  822. link = BASE_URL + "index.php?_route=UrlAction_TaskManager&_task=getStatsAjax&TYPE=PROBLEM&ID="+TASK;
  823. } else {
  824. link = BASE_URL + "index.php?_route=UrlAction_TaskManager&_task=getStatsAjax&TYPE=PROBLEM&ID="+TASK;
  825. }
  826. $.get(link, function(data) {
  827. data = data[0];
  828. var result = "<td>L. wykonanych podzadań: "+data["CHILDS_DONE_COUNT"]+"/"+data["CHILDS_COUNT"]+"</td><td></td>";
  829. $("#line1", ".stats").html(result);
  830. });
  831. }
  832. function renderTaskManager() {
  833. $("#right").append("<div class=taskList ></div>");
  834. if (false) {// TODO
  835. $("#right").append("<h2>Statystyki</h2><div class=stats></div>");
  836. $(".stats").append("<div class=table-responsive><table class=table><tr id=line1></tr><tr id=line2></tr></table></div>");
  837. loadStats();
  838. }
  839. $(".taskList").append("<div class=progress></div>");
  840. $(".progress").append("<div id=accepted class='progress-bar progress-bar-success progress-bar-striped' role=progressbar style=width:9%>0%</div>");
  841. $(".progress").append("<div id=completed class='progress-bar progress-bar-info progress-bar-striped' role=progressbar style=width:9%>0%</div>");
  842. $(".taskList").append("<ul id='sortable'></ul>");
  843. // $("#sortable").append("<li><span class='glyphicon glyphicon-option-vertical ico'></span><span class=check data-step=0></span> <div class=editable contentEditable='true'>Zaprojektować podstawowy layout skryptu</div></li>");
  844. // $("#sortable").append("<li><span class='glyphicon glyphicon-option-vertical ico'></span><span class=check data-step=0></span> <div class=editable contentEditable='true'>Stworzyć tasklistę, dodać przesuwaunie i flagowanie</div></li>");
  845. // $("#sortable").append("<li><span class='glyphicon glyphicon-option-vertical ico'></span><span class=check data-step=0></span> <div class=editable contentEditable='true'>Dodać po lewej stronie formularz</div></li>");
  846. // $("#sortable").append("<li><span class='glyphicon glyphicon-option-vertical ico'></span><span class=check data-step=0></span> <div class=editable contentEditable='true'>Połączyć z API</div></li>");
  847. $(".taskList").append('<div id="add" style="font-size:small">' +
  848. '<span class="glyphicon glyphicon-plus addIco" style="padding-top:3px"></span> ' +
  849. '<textarea class="eInput" style="font-size:small" id="datepicker" placeholder="Dodaj zadanie"></textarea>' +
  850. '<div class="clearfix"></div>' + '</div>');
  851. picker = $("<input/>", {
  852. type: 'text',
  853. style: 'width:0px;height:0px;outline:none;overflow:0;border:0;margin:0px;padding:0px;',
  854. id: "date",
  855. }).datetimepicker({
  856. defaultDate: false,
  857. useCurrent: false,
  858. widgetPositioning: {
  859. horizontal: 'auto',
  860. vertical: 'bottom'
  861. }
  862. })
  863. $('.taskList').append(picker);
  864. $(".taskList").append("<div id=showMore >Pokaż wykonane zadania <span class='glyphicon glyphicon-chevron-down'></span></div>");
  865. $(".taskList").append("<ul id='doneList'></ul>");
  866. var link;
  867. $("#doneList").hide();
  868. updateProgress();
  869. $(picker).on("dp.change", function(e) {
  870. var date = e.date;
  871. date = date.format('YYYY-MM-DD');
  872. var text = $(".eInput").val();
  873. var result = text.substring(0, position) + " @" + date + " " + text.substring(position + wordLen + 2);
  874. $(".eInput").val(result);
  875. $(picker).data("DateTimePicker").hide();
  876. });
  877. $(function() {
  878. $("#sortable").sortable({
  879. stop: function(event, ui) {
  880. setSort();
  881. },
  882. handle: ".ico"
  883. });
  884. autoCom();
  885. $('.eInput').autosize();
  886. });
  887. render();
  888. }