1 /**
  2  * @fileOverview  
  3  * Copyright (c) 2013 Regione Autonoma della Sardegna
  4  * Published under the GPL license.<br>
  5  * See <a href="https://sardegnageoportale.it/webgis/license.txt">https://sardegnageoportale.it/webgis/license.txt</a>
  6  * for the full text of the license.
  7  * @version 0.1
  8  */
  9 
 10 /**
 11  * @require plugins/Tool.js
 12  * @require GeoExt/widgets/Action.js
 13  */
 14 
 15 /**
 16  * @namespace framework.plugins
 17  */
 18 Ext.ns("framework.plugins");
 19 
 20 /** 
 21  *  Show button for logout.
 22  *  @name_ Logoff 
 23  *  @class Show button for logout.
 24  *  @constructor
 25  *  @extends <a target="_blank" href="http://gxp.opengeo.org/master/doc/lib/plugins/Tool.html">gxp.plugins.Tool</a>
 26  */
 27 framework.plugins.Logoff = Ext.extend(gxp.plugins.Tool,
 28         /** 
 29          * @lends framework.plugins.Logoff.prototype 
 30          */
 31                 {
 32                     /**
 33                      * framework_logoff plugin type.
 34                      * @public
 35                      * @type String
 36                      */
 37                     ptype: "framework_logoff",
 38                     /** 
 39                      * logout Url for ajax request
 40                      * default ""
 41                      * @public
 42                      * @type String
 43                      */
 44                     logoutUrl: "",
 45                      /** 
 46                      * redirect Url for logout
 47                      * default ""
 48                      * @public
 49                      * @type String
 50                      */
 51                     redirectUrl: "",
 52                     /**
 53                      * Adds the action to be runned on click event
 54                      * @private
 55                      */
 56                     addActions: function() {
 57                         this.logged = false; //initially user is not logged
 58                         var map = this.target.mapPanel.map;
 59                         var _self = this;
 60                         var action = new GeoExt.Action({
 61                             iconCls: "gxp-icon-login",
 62                             tooltip: "Logoff",
 63                             map: map,
 64                             handler: function() {
 65                                 var redirect =  _self.redirectUrl;
 66                                 Ext.Ajax.request({
 67                                     method: 'GET',
 68                                     url: _self.logoutUrl,
 69                                     success: function(response, opts) {
 70                                         window.location=redirect;
 71                                     },
 72                                     failure: function(response, opts) {
 73                                         Ext.MessageBox.alert('Errore', 'Error server-side');
 74                                     }
 75                                 });
 76                             }
 77                         });
 78                         return framework.plugins.Logoff.superclass.addActions.apply(this, [action]);
 79                     }
 80                 });
 81               
 82         Ext.preg(framework.plugins.Logoff.prototype.ptype, framework.plugins.Logoff);
 83