Advertisement
ReutenkoIvan

strange request

Nov 4th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         function init() {
  2.           const res_flags = wialon.item.Item.dataFlag.base | wialon.item.Resource.dataFlag.reports;
  3.           const unit_flags = wialon.item.Item.dataFlag.base;
  4.           const initProps = [
  5.             { type: "type", data: "avl_resource", flags: res_flags, mode: 0 },
  6.             { type: "type", data: "avl_unit", flags: unit_flags, mode: 0 }
  7.       ];
  8.  
  9.           let getterResult;
  10.  
  11.           const sess = wialon.core.Session.getInstance();
  12.           sess.loadLibrary("resourceReports");
  13.  
  14.           function getterFunc(code) {
  15.             if (code) {
  16.               msg(wialon.core.Errors.getErrorText(code));
  17.               return;
  18.             }
  19.  
  20.             const res = sess.getItems("avl_resource");
  21.             if (!res || !res.length) {
  22.               msg("Resources not found");
  23.               return
  24.             }
  25.  
  26.             for (let i = 0; i < res.length; i++) {
  27.               $("#res").append(`<option value='${res[i].getId()}'>${res[i].getName()}</option>`);
  28.             }
  29.  
  30.             const units = sess.getItems("avl_unit");
  31.             if (!units || !units.length) {
  32.               msg("Units not found");
  33.               return
  34.             }
  35.  
  36.             for (let i = 0; i < units.length; i++) {
  37.               const u = units[i];
  38.               $("#units").append(`<p id='pbox'><input class='inpcheck' type='checkbox' value='${u.getId()}'/> ${u.getName()}</p>`);
  39.             };
  40.  
  41.             getterResult = units
  42.           }
  43.  
  44.           sess.updateDataFlags(initProps, getterFunc);
  45.  
  46.           return getterResult;
  47.         }
  48.  
  49.  
  50.         const bbb = init()
  51.         // bbb === units
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement