--- /dev/null
+/*
+Copyright (c) Igor Barma, Alexandre Desoubeaux, Christian Martel, Eric Brun, Mathieu Amblard, Gwenael Gevet, Pierre Guillot, 2012
+ * Copyright Alexandre Desoubeaux, Christian Martel, Cedric Lecarpentier, Alexandre Lefevre, Marc Salvat 2014-2016
+ * Copyright Alexandre Desoubeaux, Christian Martel, Cedric Lecarpentier, Marc Salvat, Marc Suarez, Harifetra Ramamonjy 2017
+For licensing, see README.txt or http://www.pentilanero.com (Cecill-C or AGPL or LGPL)
+*/
+Ext.ns("EntSavoie.Incidents");
+EntSavoie.Incidents.IncidentsWindow = function (config) {
+ Ext.apply(this, config);
+
+ // Ajoute le texte des erreurs
+ //Ext.QuickTips.init();
+
+ this.waitPanel = new Ext.LoadMask(Ext.getBody(), {msg:this.i18n.Incidents.IncidentsWindow.waitPanel.msg});
+
+ this.validBtn = this.validBtn || new Ext.Button({
+ text: this.i18n.Incidents.IncidentsWindow.validBtn.text,
+ handler: this.onSendMessage,
+ scope: this
+ });
+
+ this.cancelBtn = this.cancelBtn || new Ext.Button({
+ text: this.i18n.Incidents.IncidentsWindow.cancelBtn.text,
+ handler: this.onCancel,
+ scope: this
+ });
+
+ this.accroche = this.accroche || new Ext.form.Label({
+ text: this.i18n.Incidents.IncidentsWindow.accroche.text,
+ style: "font-size: 12px; line-height: 2; font-weight: bold"
+ });
+
+ this.courrielField = this.courrielField || new Ext.form.TextField({
+ fieldLabel: this.i18n.Incidents.IncidentsWindow.courrielField.label,
+ labelSeparator: "",
+ width: 300,
+ name: 'email',
+ vtype:'email',
+ allowBlank:false
+ });
+
+
+ this.incidentType = this.incidentType || new Ext.form.ComboBox({
+ fieldLabel: this.i18n.Incidents.IncidentsWindow.incidentType.fieldLabel,
+ valueField: 'incidentValue',
+ displayField: 'incidentLabel',
+ labelSeparator: "",
+ store: new Ext.data.ArrayStore({
+ id: 0,
+ fields: [
+ 'incidentValue', // numeric value is the key
+ 'incidentLabel'
+ ],
+ data: [
+ [1, this.i18n.Incidents.IncidentsWindow.incidentType.data[0]],
+ [2, this.i18n.Incidents.IncidentsWindow.incidentType.data[1]],
+ [3, this.i18n.Incidents.IncidentsWindow.incidentType.data[2]],
+ [4, this.i18n.Incidents.IncidentsWindow.incidentType.data[3]],
+ [5, this.i18n.Incidents.IncidentsWindow.incidentType.data[4]]
+ ] // data is local
+ }),
+ editable: false,
+ triggerAction: 'all',
+ mode: 'local',
+ width: 300,
+ allowBlank: false,
+ validateOnBlur: false,
+ padding: 5
+ });
+
+ this.serviceStore = this.serviceStore || new Ext.data.JsonStore({
+ root: 'items',
+ idProperty: 'id',
+ fields: ['id', 'name'],
+ sortInfo: {
+ field: 'name',
+ direction: 'ASC'
+ },
+ autoLoad: true,
+ url: this.renderURLAjax+'&jspPage=%2Fajax%2FlistServices.jsp'
+ });
+
+ this.serviceAffected = this.serviceAffected || new Ext.form.ComboBox({
+ fieldLabel: this.i18n.Incidents.IncidentsWindow.serviceAffected.fieldLabel,
+ valueField: 'id',
+ displayField: 'name',
+ store: this.serviceStore,
+ editable: false,
+ triggerAction: 'all',
+ mode: 'local',
+ width: 300,
+ allowBlank: false,
+ padding: 5
+ });
+
+ this.incidentLabel = this.incidentLabel || new Ext.form.Label({
+ text: this.i18n.Incidents.IncidentsWindow.incidentLabel.text,
+ style: "font-size: 12px; line-height: 2; font-weight: bold"
+ });
+
+ this.actionTried = this.actionTried || new Ext.form.TextArea({
+ fieldLabel: this.i18n.Incidents.IncidentsWindow.actionTried.fieldLabel,
+ width: 300,
+ height: 100,
+ allowBlank: false,
+ style: "margin-top: 5px"
+ });
+
+ this.resultObtained = this.resultObtained || new Ext.form.TextArea({
+ width: 300,
+ height: 100,
+ allowBlank: false,
+ fieldLabel: this.i18n.Incidents.IncidentsWindow.resultObtained.fieldLabel,
+ style: "margin-top: 5px"
+ });
+
+ this.incidentDescription = this.incidentDescription || new Ext.form.TextArea({
+ fieldLabel: this.i18n.Incidents.IncidentsWindow.incidentDescription.fieldLabel,
+ width: 300,
+ height: 280,
+ allowBlank: false,
+ style: "margin-top: 5px"
+ });
+
+ // Pieces jointes
+ this.attachFileChooserAdvanced = this.attachFileChooserAdvanced || new EntSavoie.AttachFileChooserAdvanced({
+ actionURLAjax: this.actionURLAjax,
+ renderURLAjax: this.renderURLAjax,
+ btnText: this.i18n.Incidents.IncidentsWindow.attachFileChooserAdvanced.btnText,
+ btnStyle: "margin-right: 5px",
+ bodyCssClass: 'panelAttachChooserStyle',
+ draggable: false,
+ attachFile_gridWidth: 300,
+ attachFile_gridStyle: "margin-left: 49px;",
+ showFacultativeInfos: true,
+ y: 30
+ });
+
+ var me = this;
+
+ this.selectDomElement = DomOutline({
+ onClick: me.onSelectDomElement,
+ onEscape: me.onEscapeDomSelection,
+ scope: me
+ });
+
+ this.screenshotBtn = this.screenshotBtn || new Ext.Button({
+ hidden: Ext.isIE,
+ iconCls: "screenshot",
+ text: this.i18n.Incidents.IncidentsWindow.screenshotBtn.text,
+ handler: this.onScreenshotBtn,
+ scope: this
+ });
+
+ this.screenshotLabel = this.screenshotLabel || new Ext.form.Label({
+ hidden: Ext.isIE,
+ html: "<i>"+this.i18n.Incidents.IncidentsWindow.screenshotLabel.html+"</i>",
+ style: "font-size: 11px;"
+ });
+
+ //TODO checkbox :
+ this.usurpationCB = this.usurpationCB || new Ext.form.Checkbox({
+ fieldLabel: this.i18n.Incidents.IncidentsWindow.usurpationCB.fieldLabel,
+ boxLabel: this.i18n.Incidents.IncidentsWindow.usurpationCB.boxLabel,
+ labelSeparator: "",
+ hidden: true
+ })
+
+ EntSavoie.Incidents.IncidentsWindow.superclass.constructor.call(this, {
+ title: this.i18n.Incidents.IncidentsWindow.constructor.title,
+ modal: true,
+ height: 600,
+ width: 510,
+ layout: 'fit',
+ autoScroll: true,
+ closable: false,
+ closeAction: "hide",
+ items: [
+ {
+ xtype: "form",
+ border: false,
+ labelWidth: 140,
+ padding: 10,
+ bodyStyle:{"background-color": "#DFE8F6"},
+ items: [
+ this.accroche,
+ this.usurpationCB,
+ this.courrielField,
+ this.incidentType,
+ this.incidentLabel,
+ this.incidentDescription,
+ this.serviceAffected,
+ this.actionTried,
+ this.resultObtained,
+ this.attachFileChooserAdvanced,
+ {
+ border: false,
+ bodyStyle:{"background-color": "#DFE8F6"},
+ html: "<br/>"
+ },
+ this.screenshotBtn,
+ this.screenshotLabel
+ ],
+ buttons: [
+ this.validBtn,
+ this.cancelBtn
+ ]
+ }
+ ]
+ });
+
+ this.incidentType.on('select', this.onSelectIncident, this);
+
+};
+
+Ext.extend(EntSavoie.Incidents.IncidentsWindow, Ext.Window, {
+ initComponent: function () {
+ EntSavoie.Incidents.IncidentsWindow.superclass.initComponent.call(this);
+ },
+
+ showAndRefresh: function(){
+ this.show();
+ this.resetInterface();
+ },
+
+ resetInterface: function(){
+ if (this.isUsurpationEnable) {
+ this.usurpationCB.show();
+ }
+ this.incidentType.reset();
+ this.courrielField.setValue(this.emailAdress);
+ if(this.serviceAffected.getValue() != ""){
+ this.serviceAffected.reset();
+ }
+ this.incidentDescription.reset();
+ this.actionTried.reset();
+ this.resultObtained.reset();
+ this.accroche.show();
+ this.incidentDescription.hide();
+ this.incidentLabel.hide();
+ this.incidentDescription.hide();
+ this.serviceAffected.hide();
+ this.actionTried.hide();
+ this.resultObtained.hide();
+ this.attachFileChooserAdvanced.attachFile_store.removeAll();
+ this.attachFileChooserAdvanced.attachFile_grid.hide();
+ },
+
+ onSendMessage: function(btn){
+ if(this.courrielField.isValid() && this.incidentType.isValid()){
+
+ var userAgent = navigator.userAgent;
+
+ var contentField = this.i18n.Incidents.IncidentsWindow.onSendMessage.contentField[0]+ this.incidentType.getRawValue() + ".<br/>";
+ contentField += this.i18n.Incidents.IncidentsWindow.onSendMessage.contentField[7]+ " " + userAgent + ".<br/>";
+
+ if (this.incidentType.getValue() === 1) {
+ if (!this.serviceAffected.isValid() || !this.actionTried.isValid() || /*!this.resultExpected.isValid() ||*/ !this.resultObtained.isValid()){
+ return false;
+ }
+
+ contentField += this.i18n.Incidents.IncidentsWindow.onSendMessage.contentField[1]+ this.serviceAffected.getRawValue() +"</p><br/>";
+ contentField += this.i18n.Incidents.IncidentsWindow.onSendMessage.contentField[2]+ this.actionTried.getValue() +"</p><br/>";
+ contentField += this.i18n.Incidents.IncidentsWindow.onSendMessage.contentField[4]+ this.resultObtained.getValue() +"</p>";
+
+
+ }
+ else {
+ if (!this.incidentDescription.isValid()){
+ return false;
+ }
+
+ contentField += this.i18n.Incidents.IncidentsWindow.onSendMessage.contentField[5]+ this.incidentDescription.getValue() +"</p>";
+ }
+
+ this.waitPanel.show();
+
+ // on ajoute les pieces jointes
+ var pjArray = new Array();
+ for (i=0; i<this.attachFileChooserAdvanced.attachFile_store.getCount(); i++) {
+ var pjRec = this.attachFileChooserAdvanced.attachFile_store.getAt(i);
+ var pjObj = {};
+ pjObj.type = pjRec.get("type");
+ pjObj.id = pjRec.get("id");
+ pjArray.push(pjObj);
+ }
+
+ Ext.Ajax.request({
+ url: this.actionURLAjax,
+ params: {
+ cmd: 'createMessage',
+ subjectField: this.incidentType.getRawValue(),
+ contentField: contentField,
+ mail: this.courrielField.getValue(),
+ attachFiles: Ext.util.JSON.encode(pjArray),
+ isUsurpationAllowed : this.usurpationCB.checked
+ },
+ scope: this,
+ success: this.onSuccessSendMessage,
+ failure: this.onFailureSendMessage
+ });
+ }
+
+ },
+
+ onSuccessSendMessage : function(){
+ this.waitPanel.hide();
+ Ext.slideMsg.msg(this.i18n.Incidents.IncidentsWindow.onSuccessSendMessage.slideMsg[0], this.i18n.Incidents.IncidentsWindow.onSuccessSendMessage.slideMsg[1]);
+ this.hide();
+
+ },
+
+ onFailureSendMessage : function(){
+ Ext.slideMsg.msg(this.i18n.Incidents.IncidentsWindow.onFailureSendMessage.slideMsg[0], this.i18n.Incidents.IncidentsWindow.onFailureSendMessage.slideMsg[1]);
+ this.waitPanel.hide();
+ },
+
+ onCancel: function(btn){
+ this.hide();
+ },
+
+ onSelectIncident: function(){
+ if(this.incidentType.getValue() === 1){
+ this.incidentLabel.show();
+ this.serviceAffected.show();
+ this.actionTried.show();
+ this.resultObtained.show();
+ this.incidentDescription.hide();
+ } else {
+ this.incidentLabel.hide();
+ this.incidentDescription.show();
+ this.serviceAffected.hide();
+ this.actionTried.hide();
+ this.resultObtained.hide();
+ }
+ },
+
+ onScreenshotBtn: function(btn){
+ Ext.MessageBox.show({
+ icon:Ext.Msg.QUESTION,
+ title: this.i18n.Incidents.IncidentsWindow.onScreenshotBtn.title,
+ msg: this.i18n.Incidents.IncidentsWindow.onScreenshotBtn.msg,
+ buttons: {yes: this.i18n.Incidents.IncidentsWindow.onScreenshotBtn.buttons.yes,
+ no: this.i18n.Incidents.IncidentsWindow.onScreenshotBtn.buttons.no,
+ cancel: this.i18n.Incidents.IncidentsWindow.onScreenshotBtn.buttons.cancel},
+ fn: this.onScreenshotBtnCall,
+ scope: this
+ });
+ },
+
+ onScreenshotBtnCall: function(btn){
+ if(btn=="cancel") {
+ return;
+ }
+ else if(btn == "no"){
+ // Start outline
+ this.selectDomElement.start();
+ this.hide();
+ }
+ else {
+ var htmlId;
+ if ($("#banner").get(0)) {
+ htmlId = "wrapper";
+ }
+ else {
+ htmlId = "main_table";
+ }
+ this.processScreenshot(Ext.fly(htmlId).dom, this);
+ }
+ },
+
+ onSelectDomElement: function(element){
+ var me = this.scope;
+ me.show();
+ me.processScreenshot(element, me);
+ },
+
+ onEscapeDomSelection: function(){
+ var me = this.scope;
+ me.show();
+ },
+
+ processScreenshot: function(element, scope){
+
+ scope.wait = new Ext.LoadMask(this.id, {msg: this.i18n.Incidents.IncidentsWindow.processScreenshot.msg});
+ scope.wait.show();
+
+ html2canvas(element, {
+ onrendered: function(canvas) {
+ var img = canvas.toDataURL("image/png");
+ Ext.Ajax.request({
+ url: scope.actionURLAjax,
+ params:{
+ cmd: "screenshot",
+ img: img
+ },
+ success: scope.onSuccessProcessScreenshot,
+ failure: scope.onFailureProcessScreenshot,
+ scope: scope
+ });
+ },
+ background: "#fff"
+ });
+ },
+
+ onSuccessProcessScreenshot: function(response, options) {
+ this.wait.hide();
+ // Traitement des messages
+ var backObj = Ext.decode(response.responseText);
+ if (!backObj.success) {
+ Ext.MessageBox.alert(this.i18n.Incidents.IncidentsWindow.onSuccessProcessScreenshot.alert.title, this.i18n.Incidents.IncidentsWindow.onSuccessProcessScreenshot.alert.msg, function(btn){}, this);
+ } else {
+ this.attachFileChooserAdvanced.reloadTreeElt();
+ Ext.slideMsg.msg(this.i18n.Incidents.IncidentsWindow.onSuccessProcessScreenshot.slideMsg.title, this.i18n.Incidents.IncidentsWindow.onSuccessProcessScreenshot.slideMsg.msg);
+ }
+ },
+
+ onFailureProcessScreenshot: function(response, options) {
+ this.wait.hide();
+ Ext.MessageBox.alert(this.i18n.Incidents.IncidentsWindow.onFailureProcessScreenshot.alert.title, this.i18n.Incidents.IncidentsWindow.onFailureProcessScreenshot.alert.msg, function(btn){}, this);
+ }
+
+});