main.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. window.ajax_calls = [];
  2. window.issue_data = {};
  3. $.real_action = $.action;
  4. $.action = function(data,success,error,progress) {
  5. if (!Date.now) Date.now = function() { return new Date().getTime(); }
  6. ajax_calls.push({request : data,time:Date.now() });
  7. if(ajax_calls.length >10) ajax_calls.shift();
  8. $.real_action(data,success,error,progress);
  9. }
  10. //CHARGEMENT DE LA PAGE
  11. function init_plugin_issue(){
  12. window.documentLoaded = false;
  13. switch($.urlParam('page')){
  14. case 'sheet.report':
  15. if($('.issue').hasClass('readonly')){
  16. $('#assign,#reportState,#tags').attr('readonly','readonly');
  17. init_components();
  18. }
  19. issue_issue_event_search();
  20. break;
  21. case 'list.issue':
  22. $('#issuereports').sortable_table({
  23. onSort : issue_issuereport_search
  24. });
  25. break
  26. }
  27. window.documentLoaded = true;
  28. }
  29. function issue_add(){
  30. var button = $('.issue-declare-button');
  31. if(button.attr('data-disabled')=='1') return;
  32. button.attr('data-disabled',1);
  33. button.find('i.fa-bug').addClass('hidden');
  34. button.find('i.fa-cog').removeClass('hidden');
  35. issue_data.height = window.screen.availHeight;
  36. issue_data.width = window.screen.availWidth;
  37. issue_data.browser = '';
  38. //on utilise pas navigator.appName qui est un fake la plupart du temps
  39. issue_data.browser = issue_detect_browser();
  40. issue_data.browserVersion = navigator.appVersion;
  41. issue_data.online = navigator.onLine;
  42. issue_data.os = navigator.platform;
  43. issue_data.from = document.location.href;
  44. issue_data.history = JSON.stringify(ajax_calls);
  45. var modal = $('#issue-report-modal');
  46. reset_inputs(modal);
  47. $('.issue-screenshot').addClass('hidden').children().remove();
  48. $('span.badge.badge-tag.active', modal).removeAttr('style').removeClass('active');
  49. init_components('#issue-report-modal');
  50. modal.modal({
  51. backdrop: 'static',
  52. show: true
  53. });
  54. modal.on('shown.bs.modal', function () {
  55. init_components(modal);
  56. });
  57. modal.on('hidden.bs.modal', function () {
  58. button.removeAttr('data-disabled');
  59. });
  60. for(var key in issue_data){
  61. var element = $('[data-uid="'+key+'"]', modal);
  62. if(element.length == 0) continue;
  63. element.html(issue_data[key] == true ? 'OUI': issue_data[key]);
  64. }
  65. button.find('i.fa-cog').addClass('hidden');
  66. button.find('i.fa-bug').removeClass('hidden');
  67. }
  68. function issue_screenshot(){
  69. //Check if IE
  70. if (window.navigator.userAgent.indexOf("MSIE ") > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)){
  71. alert('Unsupported html2canvas librairy (using ES6 features)');
  72. console.warn('Unsupported html2canvas librairy (using ES6 features)');
  73. return;
  74. }
  75. $('#issue-report-modal').modal('hide');
  76. setTimeout(function(){
  77. html2canvas(document.querySelector("html")).then(function(canvas){
  78. $('#issue-report-modal').modal('show');
  79. issue_data.screenshot = canvas.toDataURL('image/jpg');
  80. $('.issue-screenshot').removeClass('hidden').html('<img class="pointer" src="'+issue_data.screenshot+'"/>');
  81. $('.issue-screenshot img').click(function(){
  82. var image = new Image();
  83. image.src = issue_data.screenshot;
  84. var popup = window.open("");
  85. popup.document.write(image.outerHTML);
  86. });
  87. });
  88. },500);
  89. }
  90. function issue_send(element){
  91. var sendButton = $(element);
  92. var closeButton = sendButton.closest('.modal-footer').find('.close-button');
  93. var modal = $('#issue-report-modal');
  94. var button = $('.issue-declare-button');
  95. sendButton.attr('disabled', true);
  96. closeButton.attr('disabled', true);
  97. sendButton.html('<i class="fas fa-spinner fa-pulse"></i> En cours d\'envoi...');
  98. issue_data.action = 'issue_issuereport_save';
  99. issue_data.tags = $('.issue-modal-tags').val();
  100. data = $.extend(issue_data,$('#issue-report-modal').toJson());
  101. $.action(data,function(response){
  102. issue_data = {};
  103. reset_inputs('#issue-report-modal');
  104. init_components('#issue-report-modal');
  105. sendButton.html('<i class="far fa-paper-plane"></i> Envoyer');
  106. sendButton.attr('disabled', false);
  107. closeButton.attr('disabled', false);
  108. modal.modal('hide');
  109. $.message('info','Rapport envoyé<br><a class="btn btn-mini text-light" href="index.php?module=issue&page=sheet.report&id='+response.item.id+'">> Consulter le rapport</a>',10000);
  110. },function(error){
  111. button.removeAttr('data-disabled');
  112. sendButton.html('<i class="far fa-paper-plane"></i> Envoyer');
  113. sendButton.attr('disabled', false);
  114. closeButton.attr('disabled', false);
  115. sendButton.removeClass('hidden');
  116. issue_issuereport_search();
  117. });
  118. }
  119. function issue_detect_browser(){
  120. // Opera 8.0+
  121. var isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
  122. // Firefox 1.0+
  123. var isFirefox = typeof InstallTrigger !== 'undefined';
  124. // Safari 3.0+ "[object HTMLElementConstructor]"
  125. var isSafari = /constructor/i.test(window.HTMLElement) || (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window['safari'] || (typeof safari !== 'undefined' && safari.pushNotification));
  126. // Internet Explorer 6-11
  127. var isIE = /*@cc_on!@*/false || !!document.documentMode;
  128. // Edge 20+
  129. var isEdge = !isIE && !!window.StyleMedia;
  130. // Chrome 1 - 68
  131. var isChrome = Boolean(window.chrome);
  132. // Blink engine detection
  133. var isBlink = (isChrome || isOpera) && !!window.CSS;
  134. if(isOpera) return 'opera';
  135. if(isFirefox) return 'firefox';
  136. if(isChrome) return 'chrome';
  137. if(isSafari) return 'safari';
  138. if(isIE) return 'ie';
  139. if(isEdge) return 'edge';
  140. if(isBlink) return 'blink';
  141. return 'inconnu';
  142. }
  143. function issue_follow_toggle(element){
  144. $.action({
  145. action : 'issue_follow_toggle',
  146. id : $('#issuereport-form').attr('data-id'),
  147. state : $(element).hasClass('followed') ? 0 : 1
  148. },function(){
  149. //@TODO: Améliorer la mise à jour de la liste des followers (passer via du moustache ?)
  150. $('.issue-followers').load(document.URL + ' .issue-followers>*');
  151. $(element).toggleClass('followed');
  152. });
  153. }
  154. //Enregistrement des configurations
  155. function issue_setting_save(){
  156. $.action({
  157. action : 'issue_setting_save',
  158. fields : $('#issue-setting-form').toJson()
  159. },function(){
  160. $.message('success','Enregistré');
  161. });
  162. }
  163. /** ISSUEREPORT **/
  164. //Récuperation d'une liste de issuereport dans le tableau #issuereports
  165. function issue_issuereport_search(callback){
  166. var box = new FilterBox('#filters');
  167. $('#issuereports').fill({
  168. action:'issue_issuereport_search',
  169. filters : box.filters(),
  170. //differential: true,
  171. sort : $('#issuereports').sortable_table('get'),
  172. tags : $('#report-tags').val()
  173. },function(response){
  174. if(callback!=null) callback();
  175. });
  176. }
  177. //changement d'une meta de ticket (état, assiignation, tags...)
  178. var tagsVal = $('#tags').val();
  179. function issue_issuereport_meta_save(){
  180. if(!window.documentLoaded) return;
  181. $.action({
  182. action : 'issue_issuereport_meta_save',
  183. id : $('#issuereport-form').attr('data-id'),
  184. assign : $('#assign').val(),
  185. tags : $('#tags').val(),
  186. state : $('#reportState').val()
  187. },function(r){
  188. tagsVal = $('#tags').val();
  189. issue_issue_event_search();
  190. },function(r){
  191. $.each(tagsVal.split(','),function(i, val){
  192. var badge = $('.data-type-tagcloud span[data-slug="'+val+'"]');
  193. badge.addClass('active').css({
  194. background: badge.attr('data-color'),
  195. border: '1px solid '+badge.attr('data-color'),
  196. color: '#fff'
  197. });
  198. });
  199. });
  200. }
  201. //Suppression d'élement issuereport
  202. function issue_issuereport_delete(element){
  203. if(!confirm('Êtes-vous sûr de vouloir supprimer ce ticket ?')) return;
  204. var line = $(element).closest('li');
  205. $.action({
  206. action : 'issue_issuereport_delete',
  207. id : line.attr('data-id')
  208. },function(r){
  209. line.remove();
  210. $.message('info','Ticket supprimé');
  211. });
  212. }
  213. /** ISSUEEVENT **/
  214. //Récuperation d'une liste de issueevent dans le tableau #issueevents
  215. function issue_issue_event_search(callback){
  216. if(isProcessing) return;
  217. isProcessing = true;
  218. $('.issue-events').fill({
  219. //differential : true,
  220. action:'issue_issue_event_search',
  221. issue : $('#issuereport-form').attr('data-id'),
  222. templating : function(data, element, defaultTpl){
  223. if(data.type == 'state') return $('.issue-state.hidden:eq(0)').get(0).outerHTML;
  224. if(data.type == 'assignation') return $('.issue-assignation.hidden:eq(0)').get(0).outerHTML;
  225. if(data.type == 'tag') return $('.issue-tag.hidden:eq(0)').get(0).outerHTML;
  226. return defaultTpl;
  227. },
  228. showing : function(item,i){
  229. item.css({
  230. transform:'scale(0)',
  231. transition:'all 0.2s ease-in-out',
  232. opacity : 0
  233. }).removeClass('hidden');
  234. setTimeout(function(){
  235. item.css({
  236. transform:'scale(1)',
  237. opacity : 1
  238. })
  239. },(i+1)*10);
  240. }
  241. },function(response){
  242. $('.comment-message [data-mention-type="object"]').each(function(i,element){
  243. element = $(element);
  244. element.html('<a href="index.php?module=issue&page=sheet.report&id='+element.attr('data-mention-value')+'">#'+element.attr('data-mention-value')+'</a>')
  245. });
  246. isProcessing = false;
  247. if(callback!=null) callback();
  248. });
  249. }
  250. //Ajout ou modification d'élément issueevent
  251. function issue_issue_event_save(element){
  252. if(isProcessing) return;
  253. var sendButton = $(element);
  254. var btnContent = sendButton.html();
  255. var data = $('#issue-event-form').toJson();
  256. data.issue = $('#issuereport-form').attr('data-id');
  257. sendButton.html('<i class="fas fa-pulse fa-spinner"></i> Envoi en cours').addClass('disabled').attr('disabled',true);
  258. isProcessing = true;
  259. $.action(data,function(r){
  260. $('#issue-event-form').attr('data-id','');
  261. $('#content').trumbowyg('html','');
  262. $('#event-files').val('').attr('data-data','{"id":-1}');
  263. isProcessing = false;
  264. issue_issue_event_search();
  265. $.message('success','Enregistré');
  266. sendButton.html(btnContent).removeClass('disabled').removeAttr('disabled');
  267. init_components('#issue-event-form');
  268. }, function(r){
  269. isProcessing = false;
  270. sendButton.html(btnContent).removeClass('disabled').removeAttr('disabled');
  271. });
  272. }
  273. //Récuperation ou edition d'élément issueevent
  274. function issue_issue_event_edit(element){
  275. if(isProcessing) return;
  276. var line = $(element).closest('.issue-event');
  277. isProcessing = true;
  278. $.action({
  279. action:'issue_issue_event_edit',
  280. id:line.attr('data-id')
  281. },function(r){
  282. $.setForm('#issue-event-form',r);
  283. $('#event-files').attr('data-data',JSON.stringify({id:r.id}));
  284. $('#issue-event-form').attr('data-id',r.id);
  285. $('#content').trumbowyg('html',r.content);
  286. isProcessing = false;
  287. init_components();
  288. window.location = '#issue-event-form';
  289. },function(r){
  290. isProcessing = false;
  291. });
  292. }
  293. //Suppression d'élement issueevent
  294. function issue_issue_event_delete(element){
  295. if(isProcessing) return;
  296. if(!confirm('Êtes vous sûr de vouloir supprimer ce commentaire ?')) return;
  297. var line = $(element).closest('.issue-event');
  298. if($('.issue-events .issue-comment:visible').length == 1){
  299. if(!confirm('Si vous supprimez le dernier commentaire, l\'intégralité du rapport sera supprimé')) return;
  300. }
  301. isProcessing = true;
  302. $.action({
  303. action: 'issue_issue_event_delete',
  304. id: line.attr('data-id')
  305. },function(r){
  306. isProcessing = false;
  307. line.css({
  308. transform: 'translateY(-100px)',
  309. opacity: 0
  310. });
  311. setTimeout(function(){
  312. line.remove();
  313. if(r.redirect) window.location = r.redirect;
  314. },300);
  315. },function(r){
  316. isProcessing = false;
  317. });
  318. }