/*
Copyright 2017 apHarmony

This file is part of jsHarmony.

jsHarmony is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

jsHarmony is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this package.  If not, see <http://www.gnu.org/licenses/>.
*/
//DataModel
(function(jsh){
  var modelid = '<%=model.id%>';
  var xmodel = jsh.XModels[modelid];
  var XExt = jsh.XExt;

  var xdatamodel = xmodel.datamodel = function(){ }

  xdatamodel.prototype.Fields = xmodel.fields = {
    <% _.each(model.fields,function(field){ if(!('actions' in field)) return; if(field.control=='subform') return; if(field.control=='html') return; if(!field.name) return; %>
      "<%=field.name%>":new XExt.XModel.XField({"name":"<%=field.name%>",
        "caption":<%-JSON.stringify(field.caption_ext||field.caption||"")%>,
      <%-xejs.iif('format' in field,'"format":'+JSON.stringify(field.format)+',') %>
      <%-xejs.iif('actions' in field,'"actions":'+JSON.stringify(field.actions)+',') %>
      <%-xejs.iif('ongetvalue' in field,'"ongetvalue":function(val,field,xmodel,jctrl,parentobj){'+jslocals+field.ongetvalue+'},') %>
      <%-xejs.iif('key' in field,'"key":'+JSON.stringify(field.key)+',') %>
      <%-xejs.iif('lovkey' in field,'"lovkey":'+JSON.stringify(field.lovkey)+',') %>
      }), <%});%>
  };

})(<%-instance%>);