main.js 9.0 KB

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