EasyUI Forum
May 03, 2024, 11:13:21 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
  Home Help Search Login Register  
  Show Posts
Pages: [1]
1  General Category / EasyUI for jQuery / Re: Edatagrid how to add additional parameter to saveurl on: July 12, 2017, 12:09:22 PM
Hi markalves,
You can try to add some hidden fields with the values of your additional parameter
as <th field="param1" data-options="hidden:true  ..
If you cannot set the values for these parameters within the datagrid data
you can use calculated fields, assuming that this parameters values are changing
at the same time with the values in edited fields.
https://www.jeasyui.com/tutorial/datagrid/datagrid15.php
2  General Category / EasyUI for jQuery / Re: messager.progress with Chrome on: July 12, 2017, 10:34:51 AM
Two more approaches
First, the newest async/await flow, promised based, also looklike sync flow
enabled in FF52+ and Chrome55+, works with FF , again failed with Chrome
And last one tested, the old (and good) worker aproach.
Works with FF (althought not so good), and also work well with Chrome (thank God !!!)
So, if you are stuck into the "callback hell", workers seems to be the last chance

But, one question remain: different  behavior FF vs Chrome means different JS engine
implementation ? It seems like it means, because I did a test with the equivalent
messagebox and progressbar from another JS UI (Sencha ExtJS) and the results
are identically with EasyUI, exactly the same behavior.

Ok, these being said, I hope someone can find these tests useful, and I think this
topic can be closed,  if there's nothing else to add.

Thanks to @jarry for help ! Smiley

Code:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Progress Messager</title>
<link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../../themes/icon.css">
<link rel="stylesheet" type="text/css" href="../demo.css">
<script type="text/javascript" src="../../jquery.min.js"></script>
<script type="text/javascript" src="../../jquery.easyui.min.js"></script>
</head>
<body>
<h2>Progress Messager</h2>

<div id="p" class="easyui-panel" title="Messages" style="width:700px;height:200px;padding:10px;">
</div>

<div style="margin:20px 0;">
<a href="#" class="easyui-linkbutton" onclick="processAsync()">Async flow</a>
<a href="#" class="easyui-linkbutton" onclick="processSync()">Sync flow</a>
<a href="#" class="easyui-linkbutton" onclick="processGen()">Gen flow</a>
<a href="#" class="easyui-linkbutton" onclick="processAwait()">Await flow</a>
<a href="#" class="easyui-linkbutton" onclick="processWorker()">Worker flow</a>
</div>

<script type="text/javascript">
      
  function showWaitMsg(message) {
var win = $.messager.progress({
title:'Please wait ...',
msg: message
});
}    

function closeWaitMsg() {
var bar = $.messager.progress('bar');
$.messager.progress('close');
}    

function changeProgressBar(index, max) {
var bar = $.messager.progress('bar');
var prval =  Math.floor((10000 * index) / max)/100;
bar.progressbar('setValue', prval);
}

function loadPage(aurl, fCallback) {
var xhr = new XMLHttpRequest();
if(typeof fCallback === 'function') {
xhr.callback = fCallback;
function xhrSuccess () {
this.callback.apply(this, this.arguments);
}
xhr.onload = xhrSuccess;
}
xhr.open('get', aurl, false);
xhr.send();
}

function processSync() {
$('#p').html('');
$('#p').append('Start page processing<br>');
showWaitMsg('Processing pages ...');
setTimeout(function() {
for(var i=0; i<100; i++) {
changeProgressBar(i,100);
loadPage('/');
$('#p').append('Page: '+i.toString()+'<br>');
}
closeWaitMsg();
$('#p').append('Stop page processing <br>');
},1);
}

function processPage(i) {
setTimeout(function() {
changeProgressBar(i,100);
loadPage('/',
function() {      
$('#p').append('Page: '+i.toString()+'<br>');
if(i<100) {
processPage(i+1); // recursion
} else {
closeWaitMsg();
$('#p').append('Stop page processing <br>');        
}
}
);
},1);
}

function processAsync() {  
$('#p').html('');
$('#p').append('Start page processing<br>');
showWaitMsg('Processing pages ...');
processPage(0);
}

  function getPage(i) {
    changeProgressBar(i,100);
    loadPage('/');
    $('#p').append('Page: '+i.toString()+'<br>');
  }
  
  function* getPages() {
    var i=0;
    while(i<100) {
      yield getPage(i);
      i++;
    }
  };

  function runner(f) {
    var fn = f();
    var next = function (err, arg) {
      if (err) return fn.throw(err);
      var res = fn.next(arg);
      if (res.done) return;
      var func = res.value
      if (typeof func == 'function')
        func(next);
      else
        next(null, func);
    }
    next();
  }

  function processGen() {
    $('#p').html('');
    $('#p').append('Start page processing<br>');
    showWaitMsg('Processing pages ...');  
    setTimeout(function() {  
      runner(getPages);
      closeWaitMsg();
      $('#p').append('Stop page processing <br>');
    },1);
  }

  function processWorker() {
    $('#p').html('');
    showWaitMsg('Processing pages ...');  
    var worker = new Worker('worker.js');
    var i = 0;
    worker.onmessage = function (event) {
      i++;
      if(i<100) {
        changeProgressBar(i,100);
        $('#p').append('Page: '+i.toString()+'<br>');
      } else {
        closeWaitMsg();
        $('#p').append('Stop page processing <br>');          
      }
    };  
  }


function promisePage() {
    return new Promise(resolve => {
        loadPage('/');
    });
  }
  
  async function getPromisePage() {
     await promisePage();
  }

function processAwait() {
$('#p').html('');
$('#p').append('Start page processing<br>');
showWaitMsg('Processing pages ...');
setTimeout(function() {
for(var i=0; i<100; i++) {
changeProgressBar(i,100);
getPromisePage();
$('#p').append('Page: '+i.toString()+'<br>');
}
closeWaitMsg();
$('#p').append('Stop page processing <br>');
},1);  
}

</script>
</body>
</html>

worker.js
Code:
function loadPage(aurl, fCallback) {
  var xhr = new XMLHttpRequest();
  if(typeof fCallback === 'function') {
    xhr.callback = fCallback;
    function xhrSuccess () {
      this.callback.apply(this, this.arguments);
    }
    xhr.onload = xhrSuccess;
  }
  xhr.open('get', aurl, false);
  xhr.send();
}

for(var i=0; i<100; i++) {
  loadPage('/');
  postMessage(i);
}
3  General Category / EasyUI for jQuery / Re: messager.progress with Chrome on: July 11, 2017, 11:01:44 AM
Ok , let's try another approach, the generator flow control
The generator/yield version looks like synchronous code, but it is
in fact a true async code, because it yields the promise, exits the function,
and free the ES6/7 engine to do other tasks.
Not a surprise, Firefox pass also the generator test, but Chrome failed again, as in sync flow.

Help, help, help ...  Shocked

Code:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Progress Messager</title>
<link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../../themes/icon.css">
<link rel="stylesheet" type="text/css" href="../demo.css">
<script type="text/javascript" src="../../jquery.min.js"></script>
<script type="text/javascript" src="../../jquery.easyui.min.js"></script>
</head>
<body>
<h2>Progress Messager</h2>

<div id="p" class="easyui-panel" title="Messages" style="width:700px;height:200px;padding:10px;">
</div>

<div style="margin:20px 0;">
<a href="#" class="easyui-linkbutton" onclick="processAsync()">Async flow</a>
<a href="#" class="easyui-linkbutton" onclick="processSync()">Sync flow</a>
<a href="#" class="easyui-linkbutton" onclick="processGen()">Gen flow</a>
</div>

<script type="text/javascript">
    "use strict";
     
  function showWaitMsg(message) {
var win = $.messager.progress({
title:'Please wait ...',
msg: message
});
}   

function closeWaitMsg() {
var bar = $.messager.progress('bar');
$.messager.progress('close');
}   

function changeProgressBar(index, max) {
var bar = $.messager.progress('bar');
var prval =  Math.floor((10000 * index) / max)/100;
bar.progressbar('setValue', prval);
}

function loadPage(aurl, fCallback) {
var xhr = new XMLHttpRequest();
if(typeof fCallback === 'function') {
xhr.callback = fCallback;
function xhrSuccess () {
this.callback.apply(this, this.arguments);
}
xhr.onload = xhrSuccess;
}
xhr.open('get', aurl, false);
xhr.send();
}

function processSync() {
$('#p').html('');
$('#p').append('Start page processing<br>');
showWaitMsg('Processing pages ...');
setTimeout(function() {
for(var i=0; i<100; i++) {
changeProgressBar(i,100);
loadPage('/');
$('#p').append('Page: '+i.toString()+'<br>');
}
closeWaitMsg();
$('#p').append('Stop page processing <br>');
},1);
}

function processPage(i) {
setTimeout(function() {
changeProgressBar(i,100);
loadPage('/',
function() {     
$('#p').append('Page: '+i.toString()+'<br>');
if(i<100) {
processPage(i+1); // recursion
} else {
closeWaitMsg();
$('#p').append('Stop page processing <br>');       
}
}
);
},1);
}

function processAsync() { 
$('#p').html('');
$('#p').append('Start page processing<br>');
showWaitMsg('Processing pages ...');
processPage(0);
}

  function getPage(i) {
    changeProgressBar(i,100);
    loadPage('/');
    $('#p').append('Page: '+i.toString()+'<br>');
  }
 
  function* getPages() {
    var i=0;
    while(i<100) {
      yield getPage(i);
      i++;
    }
  };

  function runner(f) {
    var fn = f();
    var next = function (err, arg) {
      if (err) return fn.throw(err);
      var res = fn.next(arg);
      if (res.done) return;
      var func = res.value
      if (typeof func == 'function')
        func(next);
      else
        next(null, func);
    }
    next();
  }

  function processGen() {
    $('#p').html('');
    $('#p').append('Start page processing<br>');
    showWaitMsg('Processing pages ...'); 
    setTimeout(function() { 
      runner(getPages);
      closeWaitMsg();
      $('#p').append('Stop page processing <br>');
    },1);
  }

</script>
</body>
</html>
4  General Category / EasyUI for jQuery / messager.progress with Chrome on: June 29, 2017, 11:18:31 AM
Hi,
I have a problem with messager.progress
I am changing the progress bar value
after each page loading, doing this in
sync and async manner
Works well in Firefox sync and async
but fail in Chrome sync mode.

Please, help !
Thank you.

Code:
	<div id="p" class="easyui-panel" title="Messages" style="width:700px;height:200px;padding:10px;">
</div>

<div style="margin:20px 0;">
<a href="#" class="easyui-linkbutton" onclick="processAsync()">Async flow</a>
<a href="#" class="easyui-linkbutton" onclick="processSync()">Sync flow</a>
</div>
<script type="text/javascript">

function showWaitMsg(message) {
var win = $.messager.progress({
title:'Please wait ...',
msg: message
});
}   

function closeWaitMsg() {
var bar = $.messager.progress('bar');
$.messager.progress('close');
}   

function changeProgressBar(index, max) {
var bar = $.messager.progress('bar');
var prval =  Math.floor((10000 * index) / max)/100;
bar.progressbar('setValue', prval);
}

function loadPage(aurl, fCallback) {
var xhr = new XMLHttpRequest();
if(typeof fCallback === 'function') {
xhr.callback = fCallback;
function xhrSuccess () {
this.callback.apply(this, this.arguments);
}
xhr.onload = xhrSuccess;
}
xhr.open('get', aurl, false);
xhr.send();
}

function processSync() {
$('#p').html('');
$('#p').append('Start page processing<br>');
showWaitMsg('Processing pages ...');
setTimeout(function() {
for(var i=0; i<100; i++) {
changeProgressBar(i,100);
loadPage('/');
$('#p').append('Page: '+i.toString()+'<br>');
}
closeWaitMsg();
$('#p').append('Stop page processing <br>');
},1);
}

function processPage(i) {
setTimeout(function() {
changeProgressBar(i,100);
loadPage('/',
function() {     
$('#p').append('Page: '+i.toString()+'<br>');
if(i<100) {
processPage(i+1); // recursion
} else {
closeWaitMsg();
$('#p').append('Stop page processing <br>');       
}
}
);
},1);
}

function processAsync() { 
$('#p').html('');
$('#p').append('Start page processing<br>');
showWaitMsg('Processing pages ...');
processPage(0);
}
</script>
Pages: [1]
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!