10 function setAnimateScroll() {
11 $('a.tic-page-scroll').bind('click', function(event) {
12 var body = $('html, body');
13 var $anchor = $(this);
14 body.stop().animate({scrollTop: $($anchor.attr('href')).offset().top}, 300, 'swing');
15 event.preventDefault();
19 function showLoadingDialog(display) {
21 $('#tic-load-dialog').modal('show');
23 $('#tic-load-dialog').modal('hide');
27 function showAlertDialog(content) {
28 $('#tic-alert-content').html(content);
29 $('#tic-alert-dialog').modal('show');
32 function showInfoDialog(content) {
33 $('#tic-info-content').html(content);
34 $('#tic-info-dialog').modal('show');
37 function showConfirmDialog(content) {
38 return new Promise(function (resolve, reject) {
39 $('#tic-confirm-content').html(content);
40 $('#tic-confirm-ok').on('click', function () {
43 $('#tic-confirm-cancel').on('click', function () {
46 $('#tic-confirm-dialog').modal('show');
50 function bytesToSize(bytes) {
51 var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
55 var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
56 return Math.round(bytes / Math.pow(1024, i)) + ' ' + sizes[i];
59 function validateURL(url) {
60 var urlRegex = /(file|ftp|http|https):\/\/(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
61 return urlRegex.test(url);
64 function POST(url, postData) {
65 return new Promise(function (resolve, reject) {
68 contentType: 'application/json; charset=UTF-8',
70 data: JSON.stringify(postData),
73 success: function (result) {
76 error: function (err) {
84 return new Promise(function (resolve, reject) {
87 contentType: 'application/json; charset=UTF-8',
90 success: function (result) {
93 error: function (err) {
100 function DELETE(url) {
101 return new Promise(function (resolve, reject) {
104 contentType: 'application/json; charset=UTF-8',
107 success: function (result) {
110 error: function (err) {
117 function getAppConfig() {
118 return new Promise(function (resolve, reject) {
119 socket.emit('ws/app/config/from');
120 socket.on('ws/app/config/to', function (data) {
126 function getWebSocket() {
131 socket = io.connect();
138 * Set smooth scrolling, one page websites
139 * @method setAnimateScroll
141 setAnimateScroll: setAnimateScroll,
144 * Display or hide the loading dialog.
145 * @method showLoadingDialog
146 * @param {boolean} display flag
148 showLoadingDialog: showLoadingDialog,
151 * Display the info dialog.
152 * @method showInfoDialog
153 * @param {string} content in dialog
155 showInfoDialog: showInfoDialog,
158 * Display the alert dialog.
159 * @method showAlertDialog
160 * @param {string} content in dialog
162 showAlertDialog: showAlertDialog,
165 * Display the confirm dialog.
166 * @method showLoadingDialog
167 * @param {string} content in dialog
170 showConfirmDialog: showConfirmDialog,
173 * Convert size in bytes to KB, MB, GB, TB
174 * {@link http://stackoverflow.com/questions/15900485/correct-way-to-convert-size-in-bytes-to-kb-mb-gb-in-javascript}
175 * @method bytesToSize
176 * @param {number} byte number
178 bytesToSize: bytesToSize,
181 * Makes the element require a valid url.
182 * @method validateURL
183 * @param {string} url - A string containing the URL.
184 * @return {boolean} Return true, if the value is a valid url.
186 validateURL: validateURL,
189 * Load data from the server using a HTTP POST request.
191 * @param {string} url - A string containing the URL to which the request is sent.
192 * @param {object} data - A plain object or string that is sent to the server with the request.
198 * Load data from the server using a HTTP GET request.
200 * @param {string} url - A string containing the URL to which the request is sent.
206 * Load data from the server using a HTTP DELETE request.
208 * @param {string} url - A string containing the URL to which the request is sent.
214 * Get WebSocket client
215 * @method getWebSocket
216 * @return {object} socket
218 getWebSocket: getWebSocket,
221 * Load app configuration from config.json of root
222 * @method getAppConfig
225 getAppConfig: getAppConfig,