Skip to content
This repository was archived by the owner on Jan 9, 2019. It is now read-only.

Commit cc4e922

Browse files
authored
Merge pull request #32 from daeks/sqlite
sqlite
2 parents cd8e734 + 3361b26 commit cc4e922

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+8853
-637
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
data/
1+
data/*
22
!data/README
3+
!data/index.php
34
!data/cache/README

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ install:
1212
script:
1313
- ./vendor/bin/phpcs ./
1414
--standard=ruleset.xml
15-
--ignore="vendor/*,core/js/*,core/css/*"
15+
--ignore="data/*,vendor/*,core/js/*,core/css/*"
1616
--colors
1717
--extensions=php,js,css

config.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
define('DATA', BASE.DIRECTORY_SEPARATOR.'data');
1313
define('CACHE', BASE.DIRECTORY_SEPARATOR.'data'.DIRECTORY_SEPARATOR.'cache');
1414
define('MODULES', BASE.DIRECTORY_SEPARATOR.'modules');
15+
define('SCRIPTS', BASE.DIRECTORY_SEPARATOR.'core'.DIRECTORY_SEPARATOR.'scripts');
1516

1617
define('MODULE', 'config.json');
1718
define('URL_SEPARATOR', '/');
@@ -21,6 +22,7 @@
2122

2223
config::includes(INC);
2324
session::construct();
25+
db::instance()->construct();
2426

2527
class config
2628
{

core/cache.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class cache
55
public static function setClientVariable($key, $val, $time = COOKIE_LIFETIME)
66
{
77
$_SESSION[$key] = $val;
8-
setcookie($key, rawurlencode($val), time() + $time, URL_SEPARATOR);
8+
@setcookie($key, rawurlencode($val), time() + $time, URL_SEPARATOR);
99
}
1010

1111
public static function unsetClientVariable($key)

core/core.async.js

Lines changed: 90 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22

33
var async = (function () {
44

5-
var time;
5+
var time = [];
66

77
var init = function () {
88
$(document).ajaxSend(function (event, request, settings) {
99
$('#loading').removeClass('hidden');
10-
core.async.time = new Date().getTime();
10+
core.async.time[btoa(settings.url)] = new Date().getTime();
1111
});
1212

1313
$(document).ajaxComplete(function (event, request, settings) {
1414
$('#loading').addClass('hidden');
15-
core.async.time = (new Date().getTime() - core.async.time) / 1000;
16-
$('#async').html('- queried in ' + core.async.time + 's');
15+
core.async.time[btoa(settings.url)] = (new Date().getTime() - core.async.time[btoa(settings.url)]) / 1000;
16+
$('#async').html('- queried in ' + core.async.time[btoa(settings.url)] + 's');
17+
delete core.async.time[btoa(settings.url)];
1718
});
1819

1920
$(document.body).on('click', '[data-toggle="async"]', function (e) {
@@ -42,12 +43,49 @@
4243
core.message.toast('danger', true, obj.data);
4344
}
4445
} catch (e) {
45-
core.message.infobox('danger', 0, e.message + data);
46+
core.message.infobox('danger', 0, e.message + '<br>' + data);
4647
}
4748
});
49+
$('.dropdown.open .dropdown-toggle').dropdown('toggle');
4850
return false;
4951
});
50-
52+
53+
$(document.body).on('click', '[data-toggle="tab"]', function (e) {
54+
e.preventDefault();
55+
$('.nav').children('li').each(function () {
56+
$(this).removeClass('active');
57+
});
58+
$(this).parent().addClass('active');
59+
var loadurl = $(this).attr('data-query');
60+
var target = $($(this).attr('data-target'));
61+
$.get(loadurl, function (data) {
62+
try {
63+
var obj = $.parseJSON(data);
64+
if (obj.status == 200) {
65+
if (obj.event.length > 0) {
66+
if (obj.data.length > 0) {
67+
core.message.toast('success', false, obj.data);
68+
}
69+
eval(obj.event);
70+
} else {
71+
var data = $('<textarea/>').html(obj.data).val();
72+
target.html(data);
73+
core.validator.init();
74+
core.form.init();
75+
core.proxy.init();
76+
}
77+
} else if (obj.status == 500) {
78+
core.message.toast('danger', false, obj.data);
79+
} else {
80+
core.message.toast('danger', true, obj.data);
81+
}
82+
} catch (e) {
83+
core.message.infobox('danger', 0, e.message + '<br>' + data);
84+
}
85+
});
86+
return false;
87+
});
88+
5189
$('[data-toggle="select"]').on('change', function (e) {
5290
e.preventDefault();
5391
var loadurl = $(this).attr('data-query') + encodeURIComponent($(this).val());
@@ -74,7 +112,7 @@
74112
core.message.toast('danger', true, obj.data);
75113
}
76114
} catch (e) {
77-
core.message.infobox('danger', 0, e.message + data);
115+
core.message.infobox('danger', 0, e.message + '<br>' + data);
78116
}
79117
});
80118
return false;
@@ -103,8 +141,52 @@
103141
core.message.toast('danger', true, obj.data);
104142
}
105143
} catch (e) {
106-
core.message.infobox('danger', 0, e.message + data);
144+
core.message.infobox('danger', 0, e.message + '<br>' + data);
145+
}
146+
$('button[data-validate="post"]').prop('disabled', true);
147+
});
148+
return false;
149+
});
150+
151+
$(document.body).on('submit', '[data-toggle="form"]', function (e) {
152+
e.preventDefault();
153+
var loadurl = $(this).attr('data-query');
154+
var target = $($(this).attr('data-target'));
155+
156+
var dataset = [];
157+
$(this).find('tr').each(function () {
158+
if ($(this).attr('id')) {
159+
var tmp = new Object();
160+
tmp['id'] = $(this).attr('id');
161+
$(this).find('input').each(function () {
162+
tmp[$(this).attr('id')] = $(this).val();
163+
});
164+
dataset.push(tmp);
165+
}
166+
});
167+
168+
$.post(loadurl, {data: JSON.stringify(dataset)}, function (data) {
169+
try {
170+
var obj = $.parseJSON(data);
171+
if (obj.status == 200) {
172+
if (obj.event.length > 0) {
173+
if (obj.data.length > 0) {
174+
core.message.toast('success', false, obj.data);
175+
}
176+
eval(obj.event);
177+
} else {
178+
var data = $('<textarea/>').html(obj.data).val();
179+
target.html(data);
180+
}
181+
} else if (obj.status == 500) {
182+
core.message.toast('danger', false, obj.data);
183+
} else {
184+
core.message.toast('danger', true, obj.data);
185+
}
186+
} catch (e) {
187+
core.message.infobox('danger', 0, e.message + '<br>' + data);
107188
}
189+
$('button[data-validate="form"]').prop('disabled', true);
108190
});
109191
return false;
110192
});

core/core.charts.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@
33
var charts = (function () {
44
var init = function () {
55
$('[data-provider="gauge"]').each(function () {
6+
if (typeof $(this).attr('height') == 'undefined') {
7+
$(this).css('height', '150px');
8+
} else {
9+
$(this).css('height', $(this).attr('height') + 'px');
10+
}
11+
12+
if (typeof $(this).attr('width') == 'undefined') {
13+
$(this).css('width', '200px');
14+
} else {
15+
$(this).css('width', $(this).attr('width') + 'px');
16+
}
17+
618
var g = new JustGage({
719
id: $(this).attr('id'),
820
value: $(this).attr('data-query'),

core/core.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,13 @@ body {
3030
background: white;
3131
cursor: inherit;
3232
display: block;
33+
}
34+
.dropzone {
35+
display: block;
36+
outline: 2px dashed #92b0b3;
37+
padding: 50px 20px;
38+
text-align: center;
39+
font-size: 20px;
40+
font-weight: bold;
41+
color: #d7cfcf;
3342
}

core/core.form.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
var form = (function () {
44
var init = function () {
55
$('[data-provider="datepicker"]').datepicker({
6-
format: "yyyy/mm/dd"
6+
format: "yyyy/mm/dd"
7+
});
8+
$("[data-title='tooltip']").tooltip();
9+
$("[data-title='popover']").popover({
10+
trigger: 'hover'
711
});
812
};
913

core/core.js

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
(function ($) {
2+
3+
var core = (function () {
4+
5+
var init = function () {
6+
$.get('/modules/setup/controller.php?action=init', function (data) {
7+
try {
8+
var obj = $.parseJSON(data);
9+
if (obj.status == 200) {
10+
if (obj.data > 0) {
11+
$('.modal-content').load('/modules/setup/dialog.php?action=sync',function (result) {
12+
$('.modal').modal({
13+
show:true,
14+
backdrop: 'static',
15+
keyboard: false
16+
});
17+
$('.modal').css('display', 'block');
18+
var $dialog = $('.modal').find('.modal-dialog');
19+
var offset = ($(window).height() - $dialog.height()) / 2;
20+
var bottomMargin = $dialog.css('marginBottom');
21+
bottomMargin = parseInt(bottomMargin);
22+
if (offset < bottomMargin) {
23+
offset = bottomMargin;
24+
}
25+
$dialog.css("margin-top", offset);
26+
$('button[data-query="modal-install"]').on('click', function (event) {
27+
event.preventDefault();
28+
$(this).html('<i class="fa fa-spinner fa-spin"></i> ' + $(this).html());
29+
$(this).prop('disabled', true);
30+
core.sync();
31+
return false;
32+
});
33+
});
34+
}
35+
} else if (obj.status == 500) {
36+
core.toast('danger', false, obj.data);
37+
} else {
38+
core.toast('danger', true, obj.data);
39+
}
40+
} catch (e) {
41+
core.infobox('danger', 0, e.message + data);
42+
}
43+
});
44+
};
45+
46+
var sync = function () {
47+
if ($('#modal-data').length > 0) {
48+
var $form = $('#modal-data');
49+
var $target = $($form.attr('data-target'));
50+
51+
$.ajax({
52+
type: $form.attr('method'),
53+
url: $form.attr('action'),
54+
data: $form.serialize(),
55+
56+
success: function (data, status) {
57+
try {
58+
var obj = $.parseJSON(data);
59+
if (obj.status == 200) {
60+
$('.modal').modal('hide');
61+
if (obj.data.length > 0) {
62+
core.toast('success', false, obj.data);
63+
}
64+
eval(obj.event);
65+
} else if (obj.status == 301) {
66+
var data = $('<textarea/>').html(obj.data).val();
67+
$target.html(data);
68+
$(".progress-bar").addClass('active');
69+
eval(obj.event);
70+
}
71+
} catch (e) {
72+
$('.modal').modal('hide');
73+
core.infobox('danger', 0, e.message + data);
74+
}
75+
}
76+
});
77+
}
78+
};
79+
80+
var infobox = function (type, time, value) {
81+
$('#infobox').html('<div class="alert alert-' + type + '" tabindex="-1"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button><span>' + value.replace('Unexpected token <', '').trim() + '</span></div>');
82+
$('#infobox').show();
83+
if (time > 0) {
84+
setTimeout(function () {
85+
$("#infobox").hide();
86+
}, time);
87+
}
88+
};
89+
90+
var toast = function (type, sticky, value) {
91+
$().toastmessage('showToast', {
92+
text: value,
93+
sticky: sticky,
94+
position: 'bottom-right',
95+
type: type
96+
});
97+
};
98+
99+
return {
100+
init: init,
101+
infobox: infobox,
102+
toast: toast,
103+
sync: sync
104+
};
105+
})();
106+
107+
$.extend(true, window, {
108+
core: core
109+
});
110+
111+
$(function () {
112+
core.init();
113+
});
114+
115+
}(jQuery));

core/core.modal.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@
22

33
var modal = (function () {
44
var init = function () {
5+
$('.modal').on('show.bs.modal', core.modal.center);
56
$('.modal').on('loaded.bs.modal', core.modal.center);
67
$('.modal').on('hidden.bs.modal', function (e) {
78
$('.modal').removeData('bs.modal');
8-
$('#modal-content').html('');
9+
$('#modal-content').html('<br>&nbsp;&nbsp;<i class="fa fa-spinner fa-spin"></i> Loading...<br><br>');
910
});
1011

1112
$(window).on('resize', function () {
1213
$('.modal:visible').each(core.modal.center);
1314
});
1415

1516
$('.modal').on('success.form.fv', function (event) {
16-
if ($('form[data-toggle="modal"]').length > 0) {
17-
var $form = $('form[data-toggle="modal"]');
17+
$('button[data-query="modal-data"]').html('<i id="loading" class="fa fa-spinner fa-spin"></i> ' + $('button[data-query="modal-data"]').html());
18+
$('button[data-query="modal-data"]').prop('disabled', true);
19+
if ($('#modal-data').length > 0) {
20+
var $form = $('#modal-data');
1821
var $target = $($form.attr('data-target'));
1922

2023
$.ajax({
@@ -45,7 +48,7 @@
4548
}
4649
} catch (e) {
4750
$('.modal').modal('hide');
48-
core.message.infobox('danger', 0, e.message + data);
51+
core.message.infobox('danger', 0, e.message + '<br>' + data);
4952
}
5053
}
5154
});

0 commit comments

Comments
 (0)