This commit is contained in:
2020-06-18 00:00:19 +00:00
parent 1daa40a804
commit e5858bebd1
4 changed files with 327 additions and 314 deletions

View File

@@ -108,7 +108,10 @@ namespace rockfishCore.Controllers
newLicense.RegisteredTo = l.RegisteredTo; newLicense.RegisteredTo = l.RegisteredTo;
newLicense.DbId = l.DbId; newLicense.DbId = l.DbId;
if (l.LicenseExpires)
newLicense.LicenseExpiration = DateUtil.EpochToDate(l.LicenseExpirationDate); newLicense.LicenseExpiration = DateUtil.EpochToDate(l.LicenseExpirationDate);
else
newLicense.LicenseExpiration = DateUtil.EmptyDateValue;
newLicense.MaintenanceExpiration = DateUtil.EpochToDate(l.MaintenanceExpirationDate); newLicense.MaintenanceExpiration = DateUtil.EpochToDate(l.MaintenanceExpirationDate);
foreach (dtoLicenseFeature f in l.Features) foreach (dtoLicenseFeature f in l.Features)
{ {
@@ -125,6 +128,7 @@ namespace rockfishCore.Controllers
DBLicense.SiteId = l.SiteId; DBLicense.SiteId = l.SiteId;
DBLicense.Email = Customer.AdminEmail; DBLicense.Email = Customer.AdminEmail;
DBLicense.DbId = l.DbId; DBLicense.DbId = l.DbId;
DBLicense.Code = "na";
DBLicense.Key = Key; DBLicense.Key = Key;
DBLicense.RegTo = l.RegisteredTo; DBLicense.RegTo = l.RegisteredTo;
await ct.License.AddAsync(DBLicense); await ct.License.AddAsync(DBLicense);
@@ -142,7 +146,7 @@ throw new System.Exception("UNCOMMENT THIS FOR PRODUCTION");
#endif #endif
return NoContent(); return Ok("ok");
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@@ -64,16 +64,26 @@ app.ravLicense = (function () {
}); });
var submitData = app.utilB.objectifyFormDataArray(formData); var submitData = app.utilB.objectifyFormDataArray(formData);
//do features separately, above can't deal with multi select and we need to add schedtechs anyway
let features = [];
features.push({
Feature: "ServiceTechs",
Count: Number($("#techcount").val())
});
let options = $("#options").val();
//clean up the data before submit for (let i = 0; i < options.length; i++) {
debugger; features.push({ Feature: options[i], Count: 0 });
}
submitData["features"]=features;
//submit //submit
// alert("STUB submit"); // alert("STUB submit");
app.api.createRavLicense(submitData, function (res) { app.api.createRavLicense(submitData, function (res) {
if (res.error) { if (res.error) {
$.gevent.publish('app-show-error', res.msg); $.gevent.publish("app-show-error", res.msg);
} else { } else {
$('#key').val(res); $("#key").val(res);
return false; return false;
} }
}); });

View File

@@ -13,54 +13,65 @@
/*global $, app, getComputedStyle */ /*global $, app, getComputedStyle */
app.utilB = (function () { app.utilB = (function () {
'use strict'; "use strict";
//---------------- BEGIN MODULE SCOPE VARIABLES -------------- //---------------- BEGIN MODULE SCOPE VARIABLES --------------
var var configMap = {
configMap = {
regex_encode_html: /[&"'><]/g, regex_encode_html: /[&"'><]/g,
regex_encode_noamp: /["'><]/g, regex_encode_noamp: /["'><]/g,
html_encode_map: { html_encode_map: {
'&': '&#38;', "&": "&#38;",
'"': '&#34;', '"': "&#34;",
"'": '&#39;', "'": "&#39;",
'>': '&#62;', ">": "&#62;",
'<': '&#60;' "<": "&#60;"
} }
}, },
decodeHtml,
decodeHtml, encodeHtml, getEmSize, getApiUrl, getUrlParams, formData, objectifyFormDataArray, encodeHtml,
getMediaSize, prepareObjectForClient, fixDatesToStrings, getEmSize,
epochToShortDate, epochToLocalShortDate, epochToLocalShortDateTime, getCurrentDateTimeAsEpoch, getApiUrl,
getUrlParams,
formData,
objectifyFormDataArray,
getMediaSize,
prepareObjectForClient,
fixDatesToStrings,
epochToShortDate,
epochToLocalShortDate,
epochToLocalShortDateTime,
getCurrentDateTimeAsEpoch,
genListColumn, genListColumn,
genListColumnNoLink, autoComplete, prepareObjectDatesForServer, genListColumnNoLink,
autoComplete,
prepareObjectDatesForServer,
fixStringToServerDate; fixStringToServerDate;
configMap.encode_noamp_map = $.extend({}, configMap.html_encode_map); configMap.encode_noamp_map = $.extend({}, configMap.html_encode_map);
delete configMap.encode_noamp_map['&']; delete configMap.encode_noamp_map["&"];
//----------------- END MODULE SCOPE VARIABLES --------------- //----------------- END MODULE SCOPE VARIABLES ---------------
//------------------- BEGIN UTILITY METHODS ------------------ //------------------- BEGIN UTILITY METHODS ------------------
// Begin decodeHtml // Begin decodeHtml
// Decodes HTML entities in a browser-friendly way // Decodes HTML entities in a browser-friendly way
// See http://stackoverflow.com/questions/1912501/\ // See http://stackoverflow.com/questions/1912501/\
// unescape-html-entities-in-javascript // unescape-html-entities-in-javascript
// //
decodeHtml = function (str) { decodeHtml = function (str) {
return $('<div/>').html(str || '').text(); return $("<div/>")
.html(str || "")
.text();
}; };
// End decodeHtml // End decodeHtml
// Begin encodeHtml // Begin encodeHtml
// This is single pass encoder for html entities and handles // This is single pass encoder for html entities and handles
// an arbitrary number of characters // an arbitrary number of characters
// //
encodeHtml = function (input_arg_str, exclude_amp) { encodeHtml = function (input_arg_str, exclude_amp) {
var var input_str = String(input_arg_str),
input_str = String(input_arg_str), regex,
regex, lookup_map; lookup_map;
if (exclude_amp) { if (exclude_amp) {
lookup_map = configMap.encode_noamp_map; lookup_map = configMap.encode_noamp_map;
@@ -69,11 +80,9 @@ app.utilB = (function () {
lookup_map = configMap.html_encode_map; lookup_map = configMap.html_encode_map;
regex = configMap.regex_encode_html; regex = configMap.regex_encode_html;
} }
return input_str.replace(regex, return input_str.replace(regex, function (match, name) {
function (match, name) { return lookup_map[match] || "";
return lookup_map[match] || ''; });
}
);
}; };
// End encodeHtml // End encodeHtml
@@ -81,18 +90,18 @@ app.utilB = (function () {
// returns size of ems in pixels // returns size of ems in pixels
// //
getEmSize = function (elem) { getEmSize = function (elem) {
return Number( return Number(getComputedStyle(elem, "").fontSize.match(/\d*\.?\d*/)[0]);
getComputedStyle(elem, '').fontSize.match(/\d*\.?\d*/)[0]
);
}; };
// End getEmSize // End getEmSize
//Begin getApiUrl //Begin getApiUrl
//returns url for api methods by parsing current window location url //returns url for api methods by parsing current window location url
// //
getApiUrl = function () { getApiUrl = function () {
var u = window.location.href.replace(window.location.hash, "").replace('default.htm', '') + "api/"; var u =
window.location.href
.replace(window.location.hash, "")
.replace("default.htm", "") + "api/";
//is it a dev local url? //is it a dev local url?
if (u.indexOf("localhost:8080") != -1) { if (u.indexOf("localhost:8080") != -1) {
u = u.replace("8080", "8081"); u = u.replace("8080", "8081");
@@ -104,21 +113,15 @@ app.utilB = (function () {
u = u.replace("?", ""); u = u.replace("?", "");
return u; return u;
} };
// Begin formData // Begin formData
// Get or set all form fields // Get or set all form fields
// //
formData = function (data) { formData = function (data) {
//fix dates into strings //fix dates into strings
prepareObjectForClient(data); prepareObjectForClient(data);
var inps = $(":input").get(); var inps = $(":input").get();
if (typeof data != "object") { if (typeof data != "object") {
@@ -126,7 +129,12 @@ app.utilB = (function () {
data = {}; data = {};
$.each(inps, function () { $.each(inps, function () {
if (this.name && (this.checked || /select|textarea/i.test(this.nodeName) || /text|hidden|password/i.test(this.type))) { if (
this.name &&
(this.checked ||
/select|textarea/i.test(this.nodeName) ||
/text|hidden|password/i.test(this.type))
) {
data[this.name] = $(this).val(); data[this.name] = $(this).val();
} }
}); });
@@ -135,7 +143,7 @@ app.utilB = (function () {
$.each(inps, function () { $.each(inps, function () {
if (this.name && data[this.name]) { if (this.name && data[this.name]) {
if (this.type == "checkbox" || this.type == "radio") { if (this.type == "checkbox" || this.type == "radio") {
$(this).prop("checked", (data[this.name])); $(this).prop("checked", data[this.name]);
} else { } else {
$(this).val(data[this.name]); $(this).val(data[this.name]);
} }
@@ -153,14 +161,13 @@ app.utilB = (function () {
// :after body element // :after body element
//objectifyFormDataArray //objectifyFormDataArray
getMediaSize = function () { getMediaSize = function () {
return window.getComputedStyle(document.querySelector('body'), ':after').getPropertyValue('content').replace(/\"/g, ''); return window
.getComputedStyle(document.querySelector("body"), ":after")
.getPropertyValue("content")
.replace(/\"/g, "");
}; };
// End getMediaSize // End getMediaSize
//Begin objectifyFormDataArray //Begin objectifyFormDataArray
//takes name value form input pairs in array and turns into a keyed object //takes name value form input pairs in array and turns into a keyed object
//suitable for sending as json object //suitable for sending as json object
@@ -169,14 +176,10 @@ app.utilB = (function () {
var rv = {}; var rv = {};
for (var i = 0; i < arr.length; ++i) for (var i = 0; i < arr.length; ++i)
if (arr[i] !== undefined) { if (arr[i] !== undefined) {
rv[arr[i].name] = arr[i].value.trim();//case 3205 added trim rv[arr[i].name] = arr[i].value.trim(); //case 3205 added trim
} }
return prepareObjectDatesForServer(rv); return prepareObjectDatesForServer(rv);
} };
//Prepare an object for server needed format before submission //Prepare an object for server needed format before submission
//called by objectifyFormDataArray //called by objectifyFormDataArray
@@ -189,17 +192,17 @@ app.utilB = (function () {
fixStringToServerDate(obj); fixStringToServerDate(obj);
} }
return obj; return obj;
} };
// //
//Turn string date fields from client into server compatible format (Unix epoch like this: 1498262400 1499904000) //Turn string date fields from client into server compatible format (Unix epoch like this: 1498262400 1499904000)
fixStringToServerDate = function (obj) { fixStringToServerDate = function (obj) {
var keys = Object.keys(obj); var keys = Object.keys(obj);
keys.forEach(function (key) { keys.forEach(function (key) {
if (key.endsWith('Date') || key.startsWith('dt')) { if (key.endsWith("Date") || key.startsWith("dt")) {
var value = obj[key]; var value = obj[key];
if (value == null) { if (value == null) {
obj[key] = ''; obj[key] = "";
} else { } else {
//this is the sample format we will see: 2017-07-13 //this is the sample format we will see: 2017-07-13
//TODO: is this assuming UTC? //TODO: is this assuming UTC?
@@ -207,9 +210,7 @@ app.utilB = (function () {
} }
} }
}); });
} };
//This function exists to change the properties of the passed in object //This function exists to change the properties of the passed in object
//to values compatible with jquery form filling functions (mostly dates to strings for now) //to values compatible with jquery form filling functions (mostly dates to strings for now)
@@ -223,7 +224,7 @@ app.utilB = (function () {
fixDatesToStrings(obj); fixDatesToStrings(obj);
} }
return obj; return obj;
} };
// //
//Turn date fields of object coming from db into stringified values for consumption by client //Turn date fields of object coming from db into stringified values for consumption by client
@@ -231,10 +232,10 @@ app.utilB = (function () {
fixDatesToStrings = function (obj) { fixDatesToStrings = function (obj) {
var keys = Object.keys(obj); var keys = Object.keys(obj);
keys.forEach(function (key) { keys.forEach(function (key) {
if (key.endsWith('Date') || key.startsWith('dt')) { if (key.endsWith("Date") || key.startsWith("dt")) {
var value = obj[key]; var value = obj[key];
if (value == null) { if (value == null) {
obj[key] = ''; obj[key] = "";
} else { } else {
//Now with sqlite they come and go as unix epoch seconds //Now with sqlite they come and go as unix epoch seconds
//needs to be yyyy-MM-dd //needs to be yyyy-MM-dd
@@ -242,46 +243,46 @@ app.utilB = (function () {
} }
} }
}); });
} };
// //
//Turn date values coming in from server into displayable short date format //Turn date values coming in from server into displayable short date format
//used to display dates in various lists (where the source epoch is already localized) //used to display dates in various lists (where the source epoch is already localized)
epochToShortDate = function (epoch) { epochToShortDate = function (epoch) {
if (epoch == null || epoch == 0) return ''; if (epoch == null || epoch == 0) return "";
return moment.utc(new Date(epoch * 1000)).format("YYYY-MM-DD"); return moment.utc(new Date(epoch * 1000)).format("YYYY-MM-DD");
} };
// //
//LOCAL VERSION: Turn date values coming in from server into displayable short date format //LOCAL VERSION: Turn date values coming in from server into displayable short date format
//used to display dates in various lists where the source epoch is in UTC //used to display dates in various lists where the source epoch is in UTC
epochToLocalShortDate = function (epoch) { epochToLocalShortDate = function (epoch) {
if (epoch == null || epoch == 0) return ''; if (epoch == null || epoch == 0) return "";
var utdate = moment.utc(new Date(epoch * 1000)); var utdate = moment.utc(new Date(epoch * 1000));
var localdate = moment(utdate).local(); var localdate = moment(utdate).local();
return localdate.format("YYYY-MM-DD"); return localdate.format("YYYY-MM-DD");
} };
//LOCAL VERSION: Turn date values coming in from server into displayable short date AND TIME format //LOCAL VERSION: Turn date values coming in from server into displayable short date AND TIME format
//used to display dates in various lists where the source epoch is in UTC //used to display dates in various lists where the source epoch is in UTC
epochToLocalShortDateTime = function (epoch) { epochToLocalShortDateTime = function (epoch) {
if (epoch == null || epoch == 0) return ''; if (epoch == null || epoch == 0) return "";
var utdate = moment.utc(new Date(epoch * 1000)); var utdate = moment.utc(new Date(epoch * 1000));
var localdate = moment(utdate).local(); var localdate = moment(utdate).local();
return localdate.format("YYYY-MM-DD LT"); return localdate.format("YYYY-MM-DD LT");
} };
////////////////////////// //////////////////////////
//Get current date and time as a utc unix epoch //Get current date and time as a utc unix epoch
getCurrentDateTimeAsEpoch = function () { getCurrentDateTimeAsEpoch = function () {
return moment().utc().unix(); return moment().utc().unix();
} };
// Begin genListColumn // Begin genListColumn
// This function is used to demarcate 'columns' of fields in basic list forms by wrapping each column field in html // This function is used to demarcate 'columns' of fields in basic list forms by wrapping each column field in html
// //
genListColumn = function (val) { genListColumn = function (val) {
return '<span class="rf-list-column">' + val + '</span>' return '<span class="rf-list-column">' + val + "</span>";
}; };
// End genListColumn // End genListColumn
@@ -289,17 +290,16 @@ app.utilB = (function () {
// This function is used to demarcate and style 'columns' of fields in basic list forms by wrapping each column field in html // This function is used to demarcate and style 'columns' of fields in basic list forms by wrapping each column field in html
// that are not link columns // that are not link columns
genListColumnNoLink = function (val) { genListColumnNoLink = function (val) {
return '<span class="rf-list-column-nolink">' + val + '</span>' return '<span class="rf-list-column-nolink">' + val + "</span>";
}; };
// End genListColumn // End genListColumn
// Begin autoComplete // Begin autoComplete
// This function is used to attach an autocomplete method to an input // This function is used to attach an autocomplete method to an input
// //
autoComplete = function (controlId, acGetToken) { autoComplete = function (controlId, acGetToken) {
$('#' + controlId).autocomplete({ $("#" + controlId).autocomplete({
serviceUrl: app.shell.stateMap.apiUrl + 'autocomplete', serviceUrl: app.shell.stateMap.apiUrl + "autocomplete",
params: { params: {
acget: acGetToken acget: acGetToken
}, },
@@ -310,8 +310,6 @@ app.utilB = (function () {
}; };
// End autoComplete // End autoComplete
// export methods // export methods
return { return {
decodeHtml: decodeHtml, decodeHtml: decodeHtml,
@@ -331,4 +329,4 @@ app.utilB = (function () {
autoComplete: autoComplete autoComplete: autoComplete
}; };
//------------------- END PUBLIC METHODS --------------------- //------------------- END PUBLIC METHODS ---------------------
}()); })();

View File

@@ -21,8 +21,8 @@
<div class="col-sm-6"> <div class="col-sm-6">
<div class="form-group"> <div class="form-group">
<label for="maintenanceExpirationDate">Support expires</label> <label for="maintenanceExpirationDate">Support expires</label>
<input class="form-control" type="date" id="maintenanceExpirationDate" name="maintenanceExpirationDate" <input class="form-control" type="date" id="maintenanceExpirationDate"
value=""> name="maintenanceExpirationDate" value="">
</div> </div>
</div> </div>
@@ -32,7 +32,8 @@
<input class="form-check-input" type="checkbox" name="licenseExpires" id="licenseExpires"> <input class="form-check-input" type="checkbox" name="licenseExpires" id="licenseExpires">
Temporary key / expires Temporary key / expires
</label> </label>
<input class="form-control" type="date" id="licenseExpirationDate" name="licenseExpirationDate" value=""> <input class="form-control" type="date" id="licenseExpirationDate" name="licenseExpirationDate"
value="">
</div> </div>
</div> </div>
@@ -46,7 +47,7 @@
<div class="col-sm-6"> <div class="col-sm-6">
<div class="form-group"> <div class="form-group">
<label for="options">Additional features</label> <label for="options">Additional features</label>
<select class="form-control" name="options" multiple> <select class="form-control" name="options" id="options" multiple>
<option value="ServiceMode">Rental Key</option> <option value="ServiceMode">Rental Key</option>
<option value="Accounting">Accounting</option> <option value="Accounting">Accounting</option>
</select> </select>