main.js 11 KB

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