This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
*/
|
||||
/*global $, io, app */
|
||||
|
||||
app.api = (function() {
|
||||
app.api = (function () {
|
||||
"use strict";
|
||||
var initModule,
|
||||
getAuthHeaderObject,
|
||||
@@ -32,7 +32,7 @@ app.api = (function() {
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
// NOT AUTHORIZED ERROR HANDLER
|
||||
|
||||
$(document).ajaxError(function(event, jqxhr, settings, thrownError) {
|
||||
$(document).ajaxError(function (event, jqxhr, settings, thrownError) {
|
||||
//unauthorized? Trigger logout which will trigger login after clearing creds
|
||||
if (jqxhr.status == 401) {
|
||||
window.location.replace("#!/logout");
|
||||
@@ -46,7 +46,7 @@ app.api = (function() {
|
||||
// Return the auth token header
|
||||
//
|
||||
//
|
||||
getAuthHeaderObject = function() {
|
||||
getAuthHeaderObject = function () {
|
||||
return {
|
||||
Authorization: "Bearer " + app.shell.stateMap.user.token
|
||||
};
|
||||
@@ -59,7 +59,7 @@ app.api = (function() {
|
||||
//Create
|
||||
//Route app.post('/api/:obj_type/create', function (req, res) {
|
||||
//
|
||||
create = function(apiRoute, objData, callback) {
|
||||
create = function (apiRoute, objData, callback) {
|
||||
$.ajax({
|
||||
method: "post",
|
||||
dataType: "json",
|
||||
@@ -67,10 +67,10 @@ app.api = (function() {
|
||||
headers: getAuthHeaderObject(),
|
||||
contentType: "application/json; charset=utf-8",
|
||||
data: JSON.stringify(objData),
|
||||
success: function(data, textStatus) {
|
||||
success: function (data, textStatus) {
|
||||
callback(data);
|
||||
},
|
||||
error: function(jqXHR, textStatus, errorThrown) {
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
callback({
|
||||
error: 1,
|
||||
msg: textStatus + "\n" + errorThrown,
|
||||
@@ -83,17 +83,17 @@ app.api = (function() {
|
||||
/////////////////
|
||||
//Get - get anything, the caller provides the route, this should replace most legacy get
|
||||
//
|
||||
get = function(apiRoute, callback) {
|
||||
get = function (apiRoute, callback) {
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
dataType: "json",
|
||||
url: app.shell.stateMap.apiUrl + apiRoute,
|
||||
headers: getAuthHeaderObject(),
|
||||
|
||||
success: function(data, textStatus) {
|
||||
success: function (data, textStatus) {
|
||||
callback(data);
|
||||
},
|
||||
error: function(jqXHR, textStatus, errorThrown) {
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
callback({
|
||||
error: 1,
|
||||
msg: textStatus + "\n" + errorThrown,
|
||||
@@ -108,7 +108,7 @@ app.api = (function() {
|
||||
//Update
|
||||
//route: app.post('/api/:obj_type/update/:id', function (req, res) {
|
||||
//
|
||||
update = function(objType, objData, callback) {
|
||||
update = function (objType, objData, callback) {
|
||||
var theId;
|
||||
if (!objData.id) {
|
||||
return callback({
|
||||
@@ -125,14 +125,14 @@ app.api = (function() {
|
||||
headers: getAuthHeaderObject(),
|
||||
contentType: "application/json; charset=utf-8",
|
||||
data: JSON.stringify(objData),
|
||||
success: function(data, textStatus) {
|
||||
success: function (data, textStatus) {
|
||||
if (data == null) {
|
||||
data = { ok: 1 };
|
||||
}
|
||||
|
||||
callback(data);
|
||||
},
|
||||
error: function(jqXHR, textStatus, errorThrown) {
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
callback({
|
||||
error: 1,
|
||||
msg: textStatus + "\n" + errorThrown,
|
||||
@@ -144,16 +144,16 @@ app.api = (function() {
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
//remove Item
|
||||
remove = function(apiRoute, callback) {
|
||||
remove = function (apiRoute, callback) {
|
||||
$.ajax({
|
||||
method: "DELETE",
|
||||
dataType: "json",
|
||||
url: app.shell.stateMap.apiUrl + apiRoute,
|
||||
headers: getAuthHeaderObject(),
|
||||
success: function(data, textStatus) {
|
||||
success: function (data, textStatus) {
|
||||
callback(data);
|
||||
},
|
||||
error: function(jqXHR, textStatus, errorThrown) {
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
callback({
|
||||
error: 1,
|
||||
msg: textStatus + "\n" + errorThrown,
|
||||
@@ -167,7 +167,7 @@ app.api = (function() {
|
||||
// uploadFile
|
||||
// (ajax route to upload a file)
|
||||
//
|
||||
uploadFile = function(apiRoute, objData, callback) {
|
||||
uploadFile = function (apiRoute, objData, callback) {
|
||||
$.ajax({
|
||||
method: "post",
|
||||
dataType: "json",
|
||||
@@ -176,10 +176,10 @@ app.api = (function() {
|
||||
contentType: false,
|
||||
processData: false,
|
||||
data: objData,
|
||||
success: function(data, textStatus) {
|
||||
success: function (data, textStatus) {
|
||||
callback(data);
|
||||
},
|
||||
error: function(jqXHR, textStatus, errorThrown) {
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
callback({
|
||||
error: 1,
|
||||
msg: textStatus + "\n" + errorThrown,
|
||||
@@ -192,7 +192,7 @@ app.api = (function() {
|
||||
//////////////////////////////////////////////////////////////
|
||||
//putAction - ad-hoc put method used to trigger actions etc
|
||||
//
|
||||
putAction = function(apiRoute, callback) {
|
||||
putAction = function (apiRoute, callback) {
|
||||
$.ajax({
|
||||
method: "put",
|
||||
dataType: "json",
|
||||
@@ -200,14 +200,14 @@ app.api = (function() {
|
||||
headers: getAuthHeaderObject(),
|
||||
contentType: "application/json; charset=utf-8",
|
||||
//data: JSON.stringify(objData),
|
||||
success: function(data, textStatus) {
|
||||
success: function (data, textStatus) {
|
||||
if (data == null) {
|
||||
data = { ok: 1 };
|
||||
}
|
||||
|
||||
callback(data);
|
||||
},
|
||||
error: function(jqXHR, textStatus, errorThrown) {
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
callback({
|
||||
error: 1,
|
||||
msg: textStatus + "\n" + errorThrown,
|
||||
@@ -216,6 +216,34 @@ app.api = (function() {
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
//postAction - ad-hoc post method used to trigger actions etc
|
||||
// (becuase it shouldn't have been put in the first place above)
|
||||
postAction = function (apiRoute, callback) {
|
||||
$.ajax({
|
||||
method: "post",
|
||||
dataType: "json",
|
||||
url: app.shell.stateMap.apiUrl + apiRoute,
|
||||
headers: getAuthHeaderObject(),
|
||||
contentType: "application/json; charset=utf-8",
|
||||
success: function (data, textStatus) {
|
||||
if (data == null) {
|
||||
data = { ok: 1 };
|
||||
}
|
||||
|
||||
callback(data);
|
||||
},
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
callback({
|
||||
error: 1,
|
||||
msg: textStatus + "\n" + errorThrown,
|
||||
error_detail: {}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
// LICENSE KEY RELATED API METHODS
|
||||
|
||||
@@ -223,7 +251,7 @@ app.api = (function() {
|
||||
//CreateLicense
|
||||
//Route app.post('/api/license/create', function (req, res) {
|
||||
//
|
||||
createLicense = function(objData, callback) {
|
||||
createLicense = function (objData, callback) {
|
||||
$.ajax({
|
||||
method: "post",
|
||||
dataType: "text",
|
||||
@@ -231,10 +259,10 @@ app.api = (function() {
|
||||
headers: getAuthHeaderObject(),
|
||||
contentType: "application/json; charset=utf-8",
|
||||
data: JSON.stringify(objData),
|
||||
success: function(data, textStatus) {
|
||||
success: function (data, textStatus) {
|
||||
callback(data);
|
||||
},
|
||||
error: function(jqXHR, textStatus, errorThrown) {
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
callback({
|
||||
error: 1,
|
||||
msg: textStatus + "\n" + errorThrown,
|
||||
@@ -249,16 +277,16 @@ app.api = (function() {
|
||||
//Fetch license requests
|
||||
//route: app.get('/api/license/requests', function (req, res) {
|
||||
//
|
||||
getLicenseRequests = function(callback) {
|
||||
getLicenseRequests = function (callback) {
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
dataType: "json",
|
||||
url: app.shell.stateMap.apiUrl + "license/requests",
|
||||
headers: getAuthHeaderObject(),
|
||||
success: function(data, textStatus) {
|
||||
success: function (data, textStatus) {
|
||||
callback(data);
|
||||
},
|
||||
error: function(jqXHR, textStatus, errorThrown) {
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
callback({
|
||||
error: 1,
|
||||
msg: textStatus + "\n" + errorThrown,
|
||||
@@ -273,16 +301,16 @@ app.api = (function() {
|
||||
//Fetch generated response to license request
|
||||
//route: app.get('/api/license/generateFromRequest/:uid', function (req, res) {
|
||||
//
|
||||
generateFromRequest = function(uid, callback) {
|
||||
generateFromRequest = function (uid, callback) {
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
dataType: "json",
|
||||
url: app.shell.stateMap.apiUrl + "license/generateFromRequest/" + uid,
|
||||
headers: getAuthHeaderObject(),
|
||||
success: function(data, textStatus) {
|
||||
success: function (data, textStatus) {
|
||||
callback(data);
|
||||
},
|
||||
error: function(jqXHR, textStatus, errorThrown) {
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
callback({
|
||||
error: 1,
|
||||
msg: textStatus + "\n" + errorThrown,
|
||||
@@ -296,7 +324,7 @@ app.api = (function() {
|
||||
//Email license request response
|
||||
//app.post('/api/license/email_response', function (req, res) {
|
||||
//
|
||||
licenseEmailResponse = function(objData, callback) {
|
||||
licenseEmailResponse = function (objData, callback) {
|
||||
$.ajax({
|
||||
method: "post",
|
||||
dataType: "text",
|
||||
@@ -304,10 +332,10 @@ app.api = (function() {
|
||||
headers: getAuthHeaderObject(),
|
||||
contentType: "application/json; charset=utf-8",
|
||||
data: JSON.stringify(objData),
|
||||
success: function(data, textStatus) {
|
||||
success: function (data, textStatus) {
|
||||
callback(data);
|
||||
},
|
||||
error: function(jqXHR, textStatus, errorThrown) {
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
callback({
|
||||
error: 1,
|
||||
msg: textStatus + "\n" + errorThrown,
|
||||
@@ -317,7 +345,7 @@ app.api = (function() {
|
||||
});
|
||||
};
|
||||
|
||||
initModule = function() {};
|
||||
initModule = function () {};
|
||||
|
||||
return {
|
||||
initModule: initModule,
|
||||
@@ -329,6 +357,7 @@ app.api = (function() {
|
||||
update: update,
|
||||
uploadFile: uploadFile,
|
||||
putAction: putAction,
|
||||
postAction: postAction,
|
||||
createLicense: createLicense,
|
||||
getLicenseRequests: getLicenseRequests,
|
||||
generateFromRequest: generateFromRequest,
|
||||
|
||||
@@ -12,16 +12,34 @@ app.trialEdit = (function () {
|
||||
//---------------- BEGIN MODULE SCOPE VARIABLES --------------
|
||||
var
|
||||
stateMap = {},
|
||||
onSave, onDelete,
|
||||
onApprove, onReject, onDelete,
|
||||
configModule, initModule;
|
||||
//----------------- END MODULE SCOPE VARIABLES ---------------
|
||||
|
||||
|
||||
//------------------- BEGIN EVENT HANDLERS -------------------
|
||||
|
||||
//ONSAVE
|
||||
//ONAPPROVE
|
||||
//
|
||||
onSave = function (event) {
|
||||
onApprove = function (event) {
|
||||
event.preventDefault();
|
||||
$.gevent.publish('app-clear-error');
|
||||
|
||||
var isFetched=$('#fetched').prop('checked')
|
||||
|
||||
|
||||
app.api.postAction('trial/fetched/' + stateMap.id + "/" + isFetched, function (res) {
|
||||
if (res.error) {
|
||||
$.gevent.publish('app-show-error', res.msg);
|
||||
}
|
||||
});
|
||||
|
||||
return false; //prevent default?
|
||||
};
|
||||
|
||||
//ONREJECT
|
||||
//
|
||||
onReject = function (event) {
|
||||
event.preventDefault();
|
||||
$.gevent.publish('app-clear-error');
|
||||
|
||||
@@ -37,6 +55,7 @@ app.trialEdit = (function () {
|
||||
return false; //prevent default?
|
||||
};
|
||||
|
||||
|
||||
//ONDELETE
|
||||
//
|
||||
onDelete = function (event) {
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="rejectReason">Reject reason</label>
|
||||
<label for="rejectReason">Reject reason *emailed to user</label>
|
||||
<input class="form-control" type="text" id="rejectReason" name="rejectReason" value="" >
|
||||
</div>
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user