Tuesday, January 28, 2014

Add customize clear button and Clear Date from Datebox through Jquery in ZK framework


version - zk 6.5.3
<zk>
    <script><![CDATA[
    zk.afterLoad('zul.db', function () {
    var _xRenderer = {};
    zk.override(zul.db.Renderer, _xRenderer, {
    titleHTML: function (wgt, out, localizedSymbols) {
    _xRenderer.titleHTML.apply(this, arguments); //call the original method
    var uuid = wgt.uuid,
       view = wgt._view,
       text = wgt.getZclass() + '-ctrler';

    if(view == 'day') {
    out.push('<button id="', uuid, '-today" class="', text, '"', 
    ' onClick="var cal = zk.Widget.$(\'$', wgt.parent.id, '\')._pop; cal._value = null; cal._setTime();"',
    ' >', ' today', '</button>');
    }
              out.push('<button id="', uuid, '-clear" class="', text, '"', 
    ' onClick="clearDatebox(this)"',
    ' >', ' clear', '</button>');
    }
    });
    });
    function clearDatebox (btn) {

     var str = btn.id;
    var res = str.substring(3,4); 

      if(res==0){
        var id = jq('.z-datebox-inp')[res].id,
            dbx = zk.Widget.$('#' + id);
        dbx.getInputNode().value = '';
        dbx.updateChange_();
      }else{
      var id = jq('.z-datebox-inp')[res/2].id,
            dbx = zk.Widget.$('#' + id);
        dbx.getInputNode().value = '';
        dbx.updateChange_();
      }
    }
    ]]></script>
    <datebox id="db" ></datebox>
  <datebox id="db1" ></datebox>
  <datebox id="db2" ></datebox>
  <datebox id="db3" ></datebox>
</zk>
or
change this method.
function clearDatebox (btn) {

      var d=jq('.z-datebox-pp').length-1;
        var id = jq('.z-datebox-pp')[d].id.replace('-pp', ''),
            dbx = zk.Widget.$('#' + id);
        dbx.getInputNode().value = '';
        dbx.updateChange_();
    }
for zk version 7.0 code here
      <zk>
        <script><![CDATA[
        zk.afterLoad('zul.db', function () {
        var _xRenderer = {};
        zk.override(zul.db.Renderer, _xRenderer, {
        titleHTML: function (wgt, out, localizedSymbols) {
        _xRenderer.titleHTML.apply(this, arguments); //call the original method
        var uuid = wgt.uuid,
           view = wgt._view,
           text = wgt.getZclass() + '-ctrler';

        if(view == 'day') {
        out.push('<button id="', uuid, '-today" class="', text, '"', 
        ' onClick="setDatebox(this)"',
        ' >', ' today', '</button>');
        }
                  out.push('<button id="', uuid, '-clear" class="', text, '"', 
        ' onClick="clearDatebox(this)"',
        ' >', ' clear', '</button>');
        }
        });
        });
        function clearDatebox (btn) {

         var str = btn.id;
        var res = str.substring(3,4); 

          if(res==0){
          document.getElementById(jq('.z-datebox-input')[res].id).value='';
          }else{
            document.getElementById(jq('.z-datebox-input')[res/2].id).value='';
          }
        }
           function setDatebox (btn) {
         var today = new Date();
        var dd = today.getDate();
        var mm = today.getMonth()+1; //January is 0!

        var yyyy = today.getFullYear();
        if(dd<10){dd='0'+dd} if(mm<10){mm='0'+mm}
 today = mm+'/'+dd+'/'+yyyy;

             var str = btn.id;
            var res = str.substring(3,4); 

             if(res==0){
             document.getElementById(jq('.z-datebox-input')[res].id).value=today;
             }else{
                document.getElementById(jq('.z-datebox-input')[res/2].id).value=today;
            }
        }

        ]]></script>
        <datebox id="db" ></datebox>
      <datebox id="db1" ></datebox>
      <datebox id="db2" ></datebox>
      <datebox id="db3" ></datebox>
    </zk>

How to Calculate the Future Investment Value of Investment.

Below java program for calculate future investment value. Here calculate s using the formula futureInvestmentValue =investmentAmount x (...