|
|
@@ -66,6 +66,58 @@
|
|
|
|
|
|
</style>
|
|
|
<?php S::printTimeoutUpdateJs(); ?>
|
|
|
+ <?php if (DBG::isActive()) : ?>
|
|
|
+ <script>
|
|
|
+ jQuery(document).on('DBG:notify', function(e, payload) {
|
|
|
+ console.log('DBG:notify', payload);
|
|
|
+ });
|
|
|
+ </script>
|
|
|
+ <?php endif; ?>
|
|
|
+<script>
|
|
|
+function p5UI__ButtonAjax(n, props) {
|
|
|
+ var dbg = <?php echo (DBG::isActive())? 1 : 0; ?>;
|
|
|
+ var $n = jQuery(n);
|
|
|
+ var state = {
|
|
|
+ baseCssClassNames: n.className,
|
|
|
+ href: props.href
|
|
|
+ };
|
|
|
+ jQuery(document).trigger('p5UI__ButtonAjax:click', [n, state]);
|
|
|
+ if ($n.hasClass('disabled')) {// bootstrap already prevent this action
|
|
|
+ if(dbg)console.log('WARNING: btn disabled - waiting for response - Cancel?');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ $n.removeClass('btn-primary').addClass('btn-default disabled btn-loading');
|
|
|
+
|
|
|
+ var req = superagent
|
|
|
+ .post(props.href)
|
|
|
+ .type('json') // header ĺapplication/x-www-form-urlencoded' requires type('form');
|
|
|
+ .send(props.data)
|
|
|
+ .set('Accept', 'application/json')
|
|
|
+ .end(function(err, res) {
|
|
|
+ if(dbg)console.log('DBG: res:', res, 'res.body:', res.body);
|
|
|
+ $n.removeClass('btn-default disabled btn-loading').addClass(state.baseCssClassNames);
|
|
|
+ if (err || !res.ok) {
|
|
|
+ jQuery(document).trigger('DBG:notify', {type: 'warning', msg: 'Req error', err: err});
|
|
|
+ } else {
|
|
|
+ //form.log('DBG:REQ('+reqCounter+'). res.status(' + res.status + ') body:' + JSON.stringify(res.body), 'info');
|
|
|
+ if ('application/json' !== res.type) {
|
|
|
+ jQuery(document).trigger('DBG:notify', {type: 'warning', msg: 'Wrong response type - required json. ' + res.text});
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ jQuery(document).trigger('DBG:notify', {type: 'success', msg: 'res.status:' + res.status + '. res.body:' + JSON.stringify(res.body)});
|
|
|
+ jQuery(document).trigger('p5UI__ButtonAjax:ajaxLoaded', [n, {type: 'success', msg: res.body.msg, body: res.body}]);
|
|
|
+ }
|
|
|
+ req = null;
|
|
|
+ });
|
|
|
+
|
|
|
+ // setTimeout(function() {
|
|
|
+ // console.log('Test click p5UI__ButtonAjax - setTimeOut', $n, state);
|
|
|
+ // jQuery(document).trigger('p5UI__ButtonAjax:ajaxLoaded', [n, state]);
|
|
|
+ // $n.removeClass('btn-default disabled btn-loading').addClass(state.baseCssClassNames);
|
|
|
+ // }, 1000);
|
|
|
+ return false;
|
|
|
+}
|
|
|
+ </script>
|
|
|
<script>
|
|
|
function initDateTimePicker(node) {
|
|
|
node.find('.se_type-date').parent().datetimepicker({
|