mirror of
https://github.com/gnh1201/welsonjs.git
synced 2024-11-26 07:21:43 +00:00
fix
This commit is contained in:
parent
d3c4292b6f
commit
7809e8ef03
|
@ -20,6 +20,10 @@ WelsonJS - Build a Windows desktop apps with JavaScript, HTML, and CSS based on
|
|||
- [github:Modernizr/Modernizr](https://github.com/Modernizr/Modernizr)
|
||||
- Default CSS Framework
|
||||
- [github:jslegers/cascadeframework](https://github.com/jslegers/cascadeframework)
|
||||
- Included libraries
|
||||
- [jQuery](https://jquery.com/)
|
||||
- [jQuery UI](https://jqueryui.com/)
|
||||
- [github:BorisMoore/jsrender](https://github.com/BorisMoore/jsrender)
|
||||
- [module.exports](https://nodejs.org/en/knowledge/getting-started/what-is-require/) compatibility
|
||||
- [NPM](https://catswords.re.kr/go/npmjs) compatibility
|
||||
- Ready to use on Windows machine immediately. No require additional softwares installation.
|
||||
|
|
4
app/assets/js/jsrender-1.0.8.min.js
vendored
Normal file
4
app/assets/js/jsrender-1.0.8.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
28
app/index.js
28
app/index.js
|
@ -234,6 +234,33 @@ var getAssignedServers = function() {
|
|||
;
|
||||
};
|
||||
|
||||
var getNotices = function() {
|
||||
var onSuccess = function(res) {
|
||||
var template = $("#listview_notices .template");
|
||||
|
||||
for (var i = 0; i < res.data.length; i++) {
|
||||
var entry = template.clone();
|
||||
entry.find("a.title").text(res.data[i].title);
|
||||
entry.find("div.description").text(res.data[i].content);
|
||||
entry.find("span.ping").text(res.data[i].created_on.substring(0, 10));
|
||||
entry.appendTo("#listview_notices");
|
||||
}
|
||||
|
||||
template.css("display", "none");
|
||||
};
|
||||
|
||||
HTTP.create()
|
||||
.setContentType("application/x-www-form-urlencoded")
|
||||
.setParameters({
|
||||
"sort": "-created_on",
|
||||
"limit": 3
|
||||
})
|
||||
.setBearerAuth(token)
|
||||
.setUseCache(false)
|
||||
.get(apiUrl + "/netsolid/items/notices", onSuccess)
|
||||
;
|
||||
};
|
||||
|
||||
if (FILE.fileExists("token.txt")) {
|
||||
token = FILE.readFile("token.txt", "utf-8");
|
||||
}
|
||||
|
@ -245,6 +272,7 @@ if (FILE.fileExists("userid.txt")) {
|
|||
if (typeof(token) !== "undefined") {
|
||||
OldBrowser.setContent(FILE.readFile("app\\servers.html", "utf-8"));
|
||||
getAssignedServers();
|
||||
getNotices();
|
||||
|
||||
document.getElementById("btn_logout").onclick = function() {
|
||||
if (FILE.fileExists("token.txt")) {
|
||||
|
|
|
@ -1,3 +1,32 @@
|
|||
<div class="cell">
|
||||
<div class="col">
|
||||
<div id="listview_notices" class="cell panel">
|
||||
<div class="header">공지사항</div>
|
||||
<div class="template body">
|
||||
<div class="cell">
|
||||
<div class="col">
|
||||
<div class="col width-fit mobile-width-fit"><span class="icon icon-bell color-blue"></span></div>
|
||||
<div class="col width-fill mobile-width-fill">
|
||||
<span class="float-right">
|
||||
<span class="ping text">
|
||||
N/A
|
||||
</span>
|
||||
<span class="icon icon-time"></span>
|
||||
</span>
|
||||
<div class="col width-fill mobile-width-fill">
|
||||
<a class="title fatty" href="#">Repo 1</a>
|
||||
</div>
|
||||
<div class="description col">
|
||||
<span class="text">This is one of my coolest repos.</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="cell">
|
||||
<div class="col width-1of2">
|
||||
<div id="listview_servers" class="cell panel">
|
||||
|
|
91
lib/http.js
91
lib/http.js
|
@ -6,11 +6,12 @@
|
|||
|
||||
var HTTPObject = function() {
|
||||
this.interface = null;
|
||||
this.contentType = "application/octet-stream";
|
||||
this.contentType = "application/x-www-form-urlencoded";
|
||||
this.requestBody = "";
|
||||
this.responseBody = null;
|
||||
this.method = "";
|
||||
this.headers = {};
|
||||
this.parameters = {};
|
||||
this.dataType = "";
|
||||
this.userAgent = "WelsonJS/0.1.4-dev (https://github.com/gnh1201/welsonjs)";
|
||||
|
||||
|
@ -109,7 +110,7 @@ var HTTPObject = function() {
|
|||
try {
|
||||
return this.interface.getResponseHeader(key);
|
||||
} catch (e) {
|
||||
console.error("HTTPObject.getHeader() -> " + e.message);
|
||||
console.error("HTTPObject.getHeader() -> ", e.message);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -126,10 +127,32 @@ var HTTPObject = function() {
|
|||
return acc;
|
||||
}, {});
|
||||
} catch (e) {
|
||||
console.error("HTTPObject.getHeaders() -> " + e.message);
|
||||
console.error("HTTPObject.getHeaders() -> ", e.message);
|
||||
}
|
||||
};
|
||||
|
||||
this.setParameter = function(key, value) {
|
||||
this.parameters[key] = value;
|
||||
return this;
|
||||
};
|
||||
|
||||
this.getParameter = function(key) {
|
||||
return this.parameters[key];
|
||||
};
|
||||
|
||||
this.setParameters = function(params) {
|
||||
var params = (typeof(params) !== "undefined") ? params : {};
|
||||
for (var key in params) {
|
||||
var value = params[key];
|
||||
this.setParameter(key, value);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
this.getParameters = function() {
|
||||
return this.parameters;
|
||||
};
|
||||
|
||||
this.setBearerAuth = function(token) {
|
||||
this.setHeader("Authorization", "Bearer " + token);
|
||||
return this;
|
||||
|
@ -151,17 +174,48 @@ var HTTPObject = function() {
|
|||
this.setHeader("User-Agent", this.userAgent);
|
||||
};
|
||||
|
||||
this.serialize = function() {
|
||||
if (this.isJSONRequest() && typeof(this.requestBody) === "object") {
|
||||
return JSON.stringify(this.requestBody);
|
||||
} else if (typeof(requestBody) === "object") {
|
||||
return this.serializeURL(this.requestBody);
|
||||
} else {
|
||||
return this.requestBody;
|
||||
}
|
||||
};
|
||||
|
||||
this.serializeURL = function(obj) {
|
||||
var str = [];
|
||||
for (var p in obj)
|
||||
if (obj.hasOwnProperty(p)) {
|
||||
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
|
||||
}
|
||||
return str.join("&");
|
||||
};
|
||||
|
||||
this.serializeParameters = function(url) {
|
||||
if (Object.keys(this.parameters).length > 0) {
|
||||
if (url.indexOf('?') > -1) {
|
||||
return url + '&' + this.serializeURL(this.parameters);
|
||||
} else {
|
||||
return url + '?' + this.serializeURL(this.parameters);
|
||||
}
|
||||
} else {
|
||||
return url;
|
||||
}
|
||||
};
|
||||
|
||||
this.open = function(method, url, isAsync) {
|
||||
this.setMethod(method.toUpperCase());
|
||||
|
||||
try {
|
||||
switch (this.method) {
|
||||
case "POST":
|
||||
this.interface.open(method, url, isAsync);
|
||||
this.interface.open(method, this.serializeParameters(url), isAsync);
|
||||
break;
|
||||
|
||||
case "GET":
|
||||
this.interface.open(method, url, isAsync);
|
||||
this.interface.open(method, this.serializeParameters(url), isAsync);
|
||||
break;
|
||||
|
||||
case "PATCH":
|
||||
|
@ -171,7 +225,7 @@ var HTTPObject = function() {
|
|||
console.error("Not supported HTTP method: " + method);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("HTTPObject.open() -> " + e.message);
|
||||
console.error("HTTPObject.open() -> ", e.message);
|
||||
}
|
||||
|
||||
return this;
|
||||
|
@ -185,10 +239,13 @@ var HTTPObject = function() {
|
|||
this.interface.setRequestHeader(key, this.headers[key]);
|
||||
}
|
||||
|
||||
if (this.isJSONRequest() && typeof(this.requestBody) === "object") {
|
||||
this.interface.send(JSON.stringify(this.requestBody));
|
||||
} else {
|
||||
this.interface.send(this.requestBody);
|
||||
switch (this.method) {
|
||||
case "GET":
|
||||
this.interface.send();
|
||||
break;
|
||||
|
||||
default:
|
||||
this.interface.send(this.serialize(this.requestBody));
|
||||
}
|
||||
|
||||
if (this.isJSONResponse()) {
|
||||
|
@ -201,7 +258,7 @@ var HTTPObject = function() {
|
|||
callback(this.responseBody);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("HTTPObject.send() -> " + e.message);
|
||||
console.error("HTTPObject.send() -> ", e.message);
|
||||
}
|
||||
|
||||
return this;
|
||||
|
@ -238,7 +295,7 @@ var HTTPObject = function() {
|
|||
|
||||
return this;
|
||||
} catch (e) {
|
||||
console.error("HTTPObject.patch() -> " + e.message);
|
||||
console.error("HTTPObject.patch() -> ", e.message);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -250,13 +307,13 @@ exports.create = function() {
|
|||
return (new HTTPObject());
|
||||
};
|
||||
|
||||
exports.post = function(url, data, headers) {
|
||||
return (new HTTPObject()).setHeaders(headers).setRequestBody(data).post(url).responseBody;
|
||||
}
|
||||
exports.post = function(url, data, headers, params) {
|
||||
return (new HTTPObject()).setHeaders(headers).setRequestBody(data).setParameters(params).post(url).responseBody;
|
||||
};
|
||||
|
||||
exports.get = function(url, data, headers) {
|
||||
return (new HTTPObject()).setHeaders(headers).setRequestBody(data).get(url).responseBody;
|
||||
}
|
||||
return (new HTTPObject()).setHeaders(headers).setParameters(data).get(url).responseBody;
|
||||
};
|
||||
|
||||
exports.VERSIONINFO = "HTTP Lib (http.js) version 0.2";
|
||||
exports.global = global;
|
||||
|
|
|
@ -196,11 +196,10 @@ exports.setContent = function(content) {
|
|||
exports.start = function(callback) {
|
||||
var IEVersion = exports.getIEVersion();
|
||||
|
||||
// load jQuery and cross browsing libraries
|
||||
if (IEVersion == 8) {
|
||||
exports.addScript("app/assets/css/jquery/webreflection-ie8-0.8.1.min.js");
|
||||
}
|
||||
|
||||
// load javascripts dynamically
|
||||
exports.addScript("app/assets/js/html5shiv-printshiv-3.7.3.min.js");
|
||||
if (IEVersion < 9) {
|
||||
exports.addScript("app/assets/js/welsonjs-respond-1.4.2-modified.js");
|
||||
|
@ -215,6 +214,7 @@ exports.start = function(callback) {
|
|||
return window.jQuery;
|
||||
});
|
||||
}
|
||||
exports.addScript("app/assets/js/jquery.html5-placeholder-shim-5a87f05.js");
|
||||
|
||||
// load Modernizr (2.8.3)
|
||||
exports.addScript("app/assets/js/modernizr-2.8.3.min.js");
|
||||
|
@ -222,10 +222,8 @@ exports.start = function(callback) {
|
|||
// load jQuery UI (1.12.1)
|
||||
exports.addScript("app/assets/js/jquery-ui-1.21.1.min.js");
|
||||
|
||||
// load additional libraries
|
||||
if (IEVersion < 10) {
|
||||
exports.addScript("app/assets/js/jquery.html5-placeholder-shim-5a87f05.js");
|
||||
}
|
||||
// load jsRender (1.0.8)
|
||||
exports.addScript("app/assets/js/jsrender-1.0.8.min.js");
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Reference in New Issue
Block a user