File: 0.00.1a/plugins/workload/workload.js (View as HTML)

  1: /* -------------------------------------------------------------
  2: This file is part of FreeDESK
  3: 
  4: FreeDESK is (C) Copyright 2012 David Cutting
  5: 
  6: FreeDESK is free software: you can redistribute it and/or modify
  7: it under the terms of the GNU General Public License as published by
  8: the Free Software Foundation, either version 3 of the License, or
  9: (at your option) any later version.
 10: 
 11: FreeDESK is distributed in the hope that it will be useful,
 12: but WITHOUT ANY WARRANTY; without even the implied warranty of
 13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14: GNU General Public License for more details.
 15: 
 16: You should have received a copy of the GNU General Public License
 17: along with FreeDESK.  If not, see www.gnu.org/licenses
 18: 
 19: For more information see www.purplepixie.org/freedesk/
 20: -------------------------------------------------------------- */
 21: 
 22: // The PIM Function
 23: function workloadPIM()
 24: {
 25:   // Last detail items asked for
 26:   var teamid = 0;
 27:   var username = "";
 28:   
 29:   // Get detail for the given team and user
 30:   this.Detail = function(teamid, username)
 31:   {
 32:     // Set last requested items
 33:     this.teamid = teamid;
 34:     this.username = username;
 35:     
 36:     // Create a ServerRequest object
 37:     var sr = new ServerRequest();
 38:     // Build the URL to the API
 39:     var url = "api.php?";
 40:     // Add the mode
 41:     url += "mode=workload_api";
 42:     // And the team and user detail
 43:     url += "&teamid="+teamid+"&username="+username;
 44:     // And the SID from FreeDESK
 45:     url += "&sid="+DESK.sid;
 46:     // Define the callback
 47:     sr.callback = Workload.Callback;
 48:     // Set the URL
 49:     sr.url = url;
 50:     // Set to XML
 51:     sr.xmlrequest = true;
 52:     // Call the API
 53:     sr.Post();
 54:   }
 55:   
 56:   // The callback method (API response)
 57:   this.Callback = function(xml, additional)
 58:   {
 59:     // Check if the API has returned an error
 60:     if (DESK.isError(xml))
 61:     {
 62:       // Display error
 63:       Alerts.add(DESK.getError(xml), 2, 10);
 64:       // Exit
 65:       return;
 66:     } // no error so continue
 67:     // Strip the response from the server
 68:     var data = xml.getElementsByTagName("data")[0]
 69:       .firstChild.nodeValue;
 70:     // Get the element to display it in
 71:     var eleID = 'detail_'
 72:       +Workload.teamid
 73:       +"_"+Workload.username;
 74:     var ele = document.getElementById(eleID);
 75:     // And display the data
 76:     ele.innerHTML = data;
 77:   }
 78: }
 79: // Instantiate the workloadPIM object
 80: var Workload = new workloadPIM();
 81: 
 82: