freightTemplate.js 1.33 KB
define(function( require, exports, module ) {

  require( 'fancybox' );
  require('validate.extend');

  // addFancy();
  addForm(function (dataBox) {
    var tr = $("<tr></tr>");

    // when append condition satisfied, clear the source box data.
    $.each(dataBox, function (i) {
      tr.append("<td>"+ dataBox[i].value + "</td>");
      dataBox[i].value = '';
    });

    $("#tablist").append(tr); 

    $.fancybox.close();
  });

  function addFancy () {
    var fancyTag = $("#getfancy");
    var ope = $(".openservice");
    var chk = ope.find('input');

    $("#getfancy").fancybox({
  
    });

    ope.on({
      click: function () {
        console.log(chk[0].checked)
        chk[0].checked ? fancyTag.click() : 0;
      }
    });
  }

  function addForm (fn) {
    var _form = $("#fancyform");
    var _ipts = _form.find('.oneline input');
    var cache = [];

    _form.validate({
      submitHandler: function () {
        $.each(_ipts, function (i) {
          cache[i] = _ipts[i].value;
        });

        addTableData(cache, _ipts, fn);
      }
    });

    $("#altersure").on({
      click: function () {
        _form.submit();
      }
    });
  };

  function addTableData (dataAry, dataBoxAry, fn) {
    if ($("#tablist").length) {
      !fn ? 0 : fn(dataBoxAry);
    }else {
      p = null;
    };
  };

});