File: 0.00.0a/js/request.js (View as Code)

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: /** 23: * FreeDESK client-side request code 24: **/ 25: 26: function FreeDESK_Request() 27: { 28: var customerIsSelected = false; 29: 30: this.searchCustomer = function() 31: { 32: var url = "entity.php?mode=search&entity=customer&"; 33: url += DESK.formToQuery('customersearch'); 34: url += "&searchnow=1&callback=DESKRequest.searchCustomerCallback&onereturn=1"; 35: url += "&sid=" + DESK.sid; 36: 37: DESK.openWindow("FreeDESK Customer Search", url); 38: } 39: 40: this.searchCustomerCallback = function(customerid) 41: { 42: document.getElementById('customer_id').innerHTML = customerid; 43: document.getElementById('customer_select').style.display = 'none'; 44: document.getElementById('customer_details').style.display = 'block'; 45: DESKRequest.customerSelected(true); 46: } 47: 48: this.searchCustomerAgain = function() 49: { 50: document.getElementById('customer_details').style.display = 'none'; 51: document.getElementById('customer_select').style.display = 'block'; 52: DESKRequest.customerSelected(false); 53: } 54: 55: this.customerSelected = function(sel) 56: { 57: DESKRequest.customerIsSelected = sel; 58: } 59: 60: this.Create = function(closeOnComplete) 61: { 62: if (closeOnComplete == undefined) 63: var closeOnComplete = false; 64: 65: 66: if (!this.customerIsSelected) 67: { 68: alert("Must select a customer"); 69: return; 70: } 71: 72: var detail = DESK.formToQuery("request_create"); 73: var mode = "request_create"; 74: var add = "customer="+document.getElementById('customer_id').innerHTML; 75: 76: var data = "mode="+mode+"&"+add+"&"+detail+"&sid="+DESK.sid; 77: 78: var sr = new ServerRequest(); 79: 80: var add = Array(); 81: 82: if (closeOnComplete) 83: add[0]=1; 84: else 85: add[0]=0; 86: 87: sr.callback = DESKRequest.createCallback; 88: sr.url = "api.php"; 89: sr.additional = add; 90: sr.Post(data); 91: } 92: 93: this.createCallback = function(xml, add) 94: { 95: if (DESK.isError(xml)) 96: { 97: Alerts.add(DESK.getError(xml), 2, 10); 98: } 99: else 100: { 101: var req = xml.getElementsByTagName("request")[0]; 102: var id = (req.textContent == undefined) ? req.firstChild.nodeValue : req.textContent; 103: var url = "request.php?id="+id+"&sid="+DESK.sid; 104: if (add[0] == 1) 105: window.close(); 106: else 107: window.location.href = url; 108: } 109: } 110: 111: } 112: 113: var DESKRequest = new FreeDESK_Request(); 114: 115: