@jd-data-limited/easy-fm 3.0.7 → 3.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@jd-data-limited/easy-fm",
3
- "version": "3.0.7",
3
+ "version": "3.0.9",
4
4
  "dependencies": {
5
5
  "@types/btoa": "^1.2.3",
6
6
  "@types/events": "^3.0.0",
7
7
  "moment": "^2.29.4",
8
8
  "node-fetch": "3.2.8",
9
- "typescript": "^4.9.4"
9
+ "typescript": "^4.9.4",
10
+ "ytdl-core": "^4.11.4"
10
11
  },
11
12
  "type": "module",
12
13
  "main": "src/index.js",
package/src/index.js CHANGED
@@ -1300,7 +1300,12 @@ export class Layout {
1300
1300
  })
1301
1301
  .then(res => {
1302
1302
  if (res.messages[0].code === "0") {
1303
- resolve(res.response);
1303
+ let error = parseInt(res.response.scriptError);
1304
+ let msg = {
1305
+ scriptError: error ? new FMError(error, 200, res, trace) : undefined,
1306
+ scriptResult: res.response.scriptResult
1307
+ };
1308
+ resolve(msg);
1304
1309
  }
1305
1310
  else {
1306
1311
  // console.log(res)
@@ -1483,17 +1488,17 @@ export class LayoutRecord extends RecordBase {
1483
1488
  if ((_a = extraBody.scripts) === null || _a === void 0 ? void 0 : _a.after) {
1484
1489
  data["script"] = extraBody.scripts.after.name;
1485
1490
  if (extraBody.scripts.after.parameter)
1486
- data["param"] = extraBody.scripts.after.parameter;
1491
+ data["script.param"] = extraBody.scripts.after.parameter;
1487
1492
  }
1488
1493
  if ((_b = extraBody.scripts) === null || _b === void 0 ? void 0 : _b.prerequest) {
1489
- data["script"] = extraBody.scripts.after.name;
1494
+ data["script.prerequest"] = extraBody.scripts.after.name;
1490
1495
  if (extraBody.scripts.prerequest.parameter)
1491
- data["param"] = extraBody.scripts.prerequest.parameter;
1496
+ data["script.prerequest.param"] = extraBody.scripts.prerequest.parameter;
1492
1497
  }
1493
1498
  if ((_c = extraBody.scripts) === null || _c === void 0 ? void 0 : _c.presort) {
1494
- data["script"] = extraBody.scripts.presort.name;
1499
+ data["script.presort"] = extraBody.scripts.presort.name;
1495
1500
  if (extraBody.scripts.presort.parameter)
1496
- data["param"] = extraBody.scripts.presort.parameter;
1501
+ data["script.presort.param"] = extraBody.scripts.presort.parameter;
1497
1502
  }
1498
1503
  if (this.recordId === -1) {
1499
1504
  // This is a new LayoutRecord
package/src/index.ts CHANGED
@@ -1146,6 +1146,11 @@ interface FMHostMetadata {
1146
1146
  }
1147
1147
  }
1148
1148
 
1149
+ export interface ScriptResult {
1150
+ scriptError?: FMError,
1151
+ scriptResult?: string
1152
+ }
1153
+
1149
1154
  export interface ContainerBufferResult {
1150
1155
  buffer: Buffer,
1151
1156
  mime: string,
@@ -1441,9 +1446,9 @@ export class Layout {
1441
1446
  return this.records.find()
1442
1447
  }
1443
1448
 
1444
- runScript(script): Promise<string> {
1449
+ runScript(script): Promise<ScriptResult> {
1445
1450
  let trace = new Error()
1446
- return new Promise(async (resolve, reject) => {
1451
+ return new Promise(async (resolve, reject) => {
1447
1452
  let url = `${this.endpoint}/script/${encodeURIComponent(script.name)}`
1448
1453
  if (script.parameter) url += "?script.param=" + encodeURIComponent(script.parameter)
1449
1454
  this.database.apiRequest(url, {
@@ -1452,7 +1457,12 @@ export class Layout {
1452
1457
  })
1453
1458
  .then(res => {
1454
1459
  if (res.messages[0].code === "0") {
1455
- resolve(res.response)
1460
+ let error = parseInt(res.response.scriptError)
1461
+ let msg: ScriptResult = {
1462
+ scriptError: error ? new FMError(error, 200, res, trace) : undefined,
1463
+ scriptResult: res.response.scriptResult
1464
+ }
1465
+ resolve(msg)
1456
1466
  }
1457
1467
  else {
1458
1468
  // console.log(res)
@@ -1666,15 +1676,15 @@ export class LayoutRecord extends RecordBase {
1666
1676
 
1667
1677
  if (extraBody.scripts?.after) {
1668
1678
  data["script"] = extraBody.scripts.after.name
1669
- if (extraBody.scripts.after.parameter) data["param"] = extraBody.scripts.after.parameter
1679
+ if (extraBody.scripts.after.parameter) data["script.param"] = extraBody.scripts.after.parameter
1670
1680
  }
1671
1681
  if (extraBody.scripts?.prerequest) {
1672
- data["script"] = extraBody.scripts.after.name
1673
- if (extraBody.scripts.prerequest.parameter) data["param"] = extraBody.scripts.prerequest.parameter
1682
+ data["script.prerequest"] = extraBody.scripts.after.name
1683
+ if (extraBody.scripts.prerequest.parameter) data["script.prerequest.param"] = extraBody.scripts.prerequest.parameter
1674
1684
  }
1675
1685
  if (extraBody.scripts?.presort) {
1676
- data["script"] = extraBody.scripts.presort.name
1677
- if (extraBody.scripts.presort.parameter) data["param"] = extraBody.scripts.presort.parameter
1686
+ data["script.presort"] = extraBody.scripts.presort.name
1687
+ if (extraBody.scripts.presort.parameter) data["script.presort.param"] = extraBody.scripts.presort.parameter
1678
1688
  }
1679
1689
 
1680
1690
  if (this.recordId === -1) {
package/img.png DELETED
Binary file
package/prop1.toml DELETED
@@ -1,58 +0,0 @@
1
- #Minecraft server properties
2
- #Wed May 03 20:32:16 AEST 2023
3
- allow-flight=false
4
- allow-nether=true
5
- broadcast-console-to-ops=true
6
- broadcast-rcon-to-ops=true
7
- difficulty=easy
8
- enable-command-block=false
9
- enable-jmx-monitoring=false
10
- enable-query=false
11
- enable-rcon=false
12
- enable-status=true
13
- enforce-secure-profile=true
14
- enforce-whitelist=false
15
- entity-broadcast-range-percentage=100
16
- force-gamemode=false
17
- function-permission-level=2
18
- gamemode=survival
19
- generate-structures=true
20
- generator-settings={}
21
- hardcore=false
22
- hide-online-players=false
23
- level-name=world
24
- level-seed=
25
- level-type=minecraft\:normal
26
- max-chained-neighbor-updates=1000000
27
- max-players=20
28
- max-threads=6
29
- max-tick-time=-1
30
- max-world-size=29999984
31
- motd=A Minecraft Server
32
- network-compression-threshold=256
33
- online-mode=false
34
- op-permission-level=4
35
- player-idle-timeout=0
36
- prevent-proxy-connections=false
37
- previews-chat=false
38
- pvp=true
39
- query.port=25565
40
- rate-limit=0
41
- rcon.password=
42
- rcon.port=25575
43
- require-resource-pack=false
44
- resource-pack=
45
- resource-pack-prompt=
46
- resource-pack-sha1=
47
- server-ip=119.252.189.11
48
- server-port=27002
49
- simulation-distance=10
50
- spawn-animals=true
51
- spawn-monsters=true
52
- spawn-npcs=true
53
- spawn-protection=16
54
- sync-chunk-writes=false
55
- text-filtering-config=
56
- use-native-transport=true
57
- view-distance=10
58
- white-list=false
package/prop2.toml DELETED
@@ -1,58 +0,0 @@
1
- #Minecraft server properties
2
- #Wed May 03 12:46:20 CEST 2023
3
- allow-flight=false
4
- allow-nether=true
5
- broadcast-console-to-ops=true
6
- broadcast-rcon-to-ops=true
7
- difficulty=easy
8
- enable-command-block=true
9
- enable-jmx-monitoring=false
10
- enable-query=true
11
- enable-rcon=false
12
- enable-status=true
13
- enforce-secure-profile=true
14
- enforce-whitelist=false
15
- entity-broadcast-range-percentage=100
16
- force-gamemode=false
17
- function-permission-level=2
18
- gamemode=survival
19
- generate-structures=true
20
- generator-settings={}
21
- hardcore=false
22
- hide-online-players=false
23
- level-name=world
24
- level-seed=
25
- level-type=minecraft\:normal
26
- max-chained-neighbor-updates=1000000
27
- max-players=100
28
- max-tick-time=60000
29
- max-world-size=29999984
30
- motd=4vNBdJ
31
- network-compression-threshold=256
32
- online-mode=true
33
- op-permission-level=4
34
- player-idle-timeout=0
35
- prevent-proxy-connections=false
36
- previews-chat=false
37
- pvp=true
38
- query.port=41305
39
- rate-limit=0
40
- rcon.password=
41
- rcon.port=25575
42
- require-resource-pack=false
43
- resource-pack=
44
- resource-pack-prompt=
45
- resource-pack-sha1=
46
- server-ip=
47
- server-port=41305
48
- simulation-distance=10
49
- snooper-enabled=false
50
- spawn-animals=true
51
- spawn-monsters=true
52
- spawn-npcs=true
53
- spawn-protection=16
54
- sync-chunk-writes=true
55
- text-filtering-config=
56
- use-native-transport=true
57
- view-distance=10
58
- white-list=false
package/test.js DELETED
@@ -1,35 +0,0 @@
1
- import FMHost from "./src/index.js";
2
- import * as fs from "fs";
3
- import {DOWNLOAD_MODES} from "./src/index.js";
4
-
5
- process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
6
-
7
- const host = new FMHost("https://192.168.2.128", 0, false)
8
- const database = host.database({
9
- database: "Snapshot_2",
10
- credentials: {
11
- method: "filemaker",
12
- username: "jhawinkels",
13
- password: "ZTw8&8E7"
14
- },
15
- externalSources: []
16
- })
17
- database.login()
18
- .then(async () => {
19
- let layout = database.getLayout("ReportsJSON")
20
- await layout.getLayoutMeta()
21
- console.log(layout.metadata)
22
-
23
- let record = (await layout.records.range(4, 9).fetch())[0]
24
-
25
- record.getField("In|PartnerID").set("42565F30-5F5D-44A4-83A0-E52128974581")
26
-
27
-
28
- let portal = record.getPortal("Reports|Archive")
29
- let portal_record = portal.create()
30
- portal_record.getField("SampleClass").set("Hello!")
31
-
32
- await record.commit()
33
- await record.get()
34
- console.log(record.getField("__PrimaryKey").value)
35
- })
package/test2.js DELETED
@@ -1,413 +0,0 @@
1
- const date = new Date();
2
- let [month, day, year] = [
3
- date.getMonth() + 1,
4
- date.getDate(),
5
- date.getFullYear(),
6
- ];
7
-
8
- if (day < 10) day = '0' + day;
9
- if (month < 10) month = '0' + month;
10
-
11
- console.log(window.location.href);
12
- var currloc = window.location.href.split('&fname=');
13
- var location_split = currloc[0].split('&location=');
14
- console.log(decodeURIComponent(location_split[1]).replace('&', '& '));
15
-
16
- var loc = location_split[0].replace('https://www.farmmedix.com/milk-sampling-consent/?location=', '');
17
- console.log(decodeURIComponent(loc));
18
-
19
- $('#date-today').html(day + '/' + month + '/' + year);
20
- $('#owner_name').html(decodeURIComponent(urlParam("fname")) + ' ' + decodeURI(urlParam("lname")));
21
- $('#farm-business-name').html('');
22
- $('#owner-phone').html('');
23
- $('#owner-email').html(decodeURIComponent(urlParam("email")))
24
-
25
- $("input[name=hidden_2]").val(day + '/' + month + '/' + year);
26
- $("input[name=hidden]").val(decodeURIComponent(urlParam("fname")));
27
- $("input[name=hidden_11]").val(decodeURIComponent(urlParam("lname")));
28
- $("input[name=hidden_1]").val(decodeURIComponent(urlParam("business_name")));
29
- $("input[name=hidden_4]").val(decodeURIComponent(urlParam("email")));
30
- $("input[name=hidden_3]").val(decodeURIComponent(urlParam("phone")));
31
- $("input[name=hidden_10]").val(decodeURIComponent(loc));
32
- $("input[name=hidden_12]").val(decodeURIComponent(urlParam("role")));
33
- $("input[name=show_staph]").val(decodeURIComponent(urlParam("show_staph")));
34
-
35
- $("input[name=show_staph]").trigger("change");
36
-
37
-
38
- var html = '<strong>Farm/Business Name</strong>: ' + decodeURI(urlParam("business_name"));
39
- html += '<br><strong>Location</strong>: ' + decodeURIComponent(loc);
40
- html += '<br><strong>First Name</strong>: ' + decodeURI(urlParam("fname"));
41
- html += '<br><strong>Last Name</strong>: ' + decodeURI(urlParam("lname"));
42
- html += '<br><strong>Email</strong>: ' + decodeURI(urlParam("email"));
43
- html += '<br><strong>Phone</strong>: ' + decodeURI(urlParam("phone"));
44
- html += '<br><strong>Role</strong>: ' + decodeURI(urlParam("role"));
45
-
46
- var allsuppliers = decodeURIComponent(urlParam("suppliers")).replace(' ', '').split(',');
47
- //console.log(decodeURIComponent(allsuppliers));
48
-
49
- var lis = '';
50
- var list_num = 13;
51
- var extralistnum = 1;
52
- var suppliers_all = '';
53
- var output = [];
54
- var newsupp = [];
55
- var suppliers_obj = {};
56
-
57
- var extra_html = '';
58
-
59
- $.each(allsuppliers, function( k, v ) {
60
- //newsupp.push(v.split('-'));
61
- var o = v.split('-');
62
- suppliers_obj[o[0]] += decodeURIComponent(o[1]) + ', ';
63
-
64
- extra_html += '<div style="width: 100%; display: inline-block; color: #000"><strong>'+v.replace('-', ' ')+'</strong></div><div style="width: 100%">';
65
- extra_html += '<div><div style="float: left; margin-right: 10px;"><div class="ff-el-input--label ff-el-is-required asterisk-right"><label>Number of animals</label></div><input id="extra-list-animal" class="ff-el-form-control" required="" type="number" data-animal="'+extralistnum+'" aria-required="true" /></div>';
66
- extra_html += '<div style="float: left; margin-right: 10px;"><div class="ff-el-input--label ff-el-is-required asterisk-right"><label>Number of Clinical Mastitis Cases</label></div><input id="extra-list-mastitis" class="ff-el-form-control" required="" type="number" data-mastitis="'+extralistnum+'" aria-required="true" /></div>';
67
- extra_html += '<div style="float: left; margin-right: 10px;"><div class="ff-el-input--label ff-el-is-required asterisk-right"><label>Bulk tank SCC level</label></div><input id="extra-list-scc" class="ff-el-form-control" required="" type="number" data-scc="'+extralistnum+'" aria-required="true" /></div>';
68
- extra_html += '<div style="float: left; margin-right: 10px;"><div class="ff-el-input--label"><label>Comment on SCC and Mastitis Cases</label></div><textarea id="extra-list-comment" class="ff-el-form-control" data-comment="'+extralistnum+'"></textarea></div>';
69
- extra_html += '</div></div>';
70
-
71
- extralistnum++;
72
- })
73
-
74
- $('#extra-fields').html(extra_html);
75
-
76
- $.each(suppliers_obj, function( i, v ) {
77
- //console.log(i, v)
78
- //html += '<br><strong>Supplier '+(i+1)+'</strong>: ' + v.replace("-", " - ");
79
- suppliers_all += '<span style="color: #000000;">- <b>'+ i + ' ' + v.replace('undefined', '').slice(0, -2) +'</b></span><br>';
80
- $('input[name=hidden_'+list_num+']').val('- ' + i + ' ' + v.replace('undefined', '').slice(0, -2));
81
- if(i != 'Fonterra'){
82
- $('input[name="has_nonfonterra"').val('yes');
83
- }
84
- list_num++;
85
- //extralistnum++;
86
- });
87
-
88
- $('#loc').html(decodeURIComponent(loc))
89
- $('#suppliers-all').html('');
90
- $('#total-samples').html('');
91
- $('#role').html($("input[name=hidden_4]").val());
92
- $('#user-full-name').html(decodeURIComponent(urlParam("fname")) + ' ' + decodeURIComponent(urlParam("lname")));
93
-
94
- $(document).on('change', '#extra-list-animal', function(){
95
- var data_id = $(this).data('animal');
96
- $('[name="num_animals_'+data_id+'"]').val($(this).val());
97
- });
98
-
99
- $(document).on('change', '#extra-list-mastitis', function(){
100
- var data_id = $(this).data('mastitis');
101
- $('[name="num_clinical_mastisis_'+data_id+'"]').val($(this).val());
102
- });
103
-
104
- $(document).on('change', '#extra-list-scc', function(){
105
- var data_id = $(this).data('scc');
106
- $('[name="bulk_tank_scc_'+data_id+'"]').val($(this).val());
107
- });
108
-
109
- $(document).on('change', '#extra-list-comment', function(){
110
- var data_id = $(this).data('rolomment');
111
- $('[name="comment_scc_'+data_id+'"]').val($(this).val());
112
- });
113
-
114
- //$("input[name=hidden_6]").val(allsuppliers.length);
115
-
116
- $('#preview').html(html)
117
-
118
- function urlParam(name) {
119
- var results = (new RegExp("[\\?&]" + name + "=([^&#]*)")).exec(window.location.href);
120
- if (results == null) return null;
121
- else return results[1] || 0;
122
- };
123
-
124
- /*** added ***/
125
-
126
- var settings = {
127
- "url": "https://snapshot-2-testenv-snpgtklz4a-ts.a.run.app/api/v2/farms/simple",
128
- "method": "GET",
129
- "timeout": 0,
130
- "headers": {
131
- "Authorization": "Bot L9lrcc3z+MqZFq2QWfiAuvNkbWyjisIA2BehMuLcw9Q=",
132
- "Content-Type": "application/json",
133
- "Cookie": "GAESA=CoQBMDAxMjE3ODliM2MyNzI0MDMzZTE1Yjk2OTFmOWRiNWNlODliMjhmMWU3YTI2ZjFmYTJiNGE5OGE0ZDBlMjQ1NDhkY2U5MWI5NGM2NzgxOTFmZjBjMTk5NDU4MTgwMTBjYjMwMzNiOWFlYTdkMjk5Zjc3ZDUyYjI4M2UzNjE3OWRmYzYyEMS59cD3MA"
134
- },
135
- };
136
-
137
- var allSuppliers = [];
138
- var suppliersName = [];
139
-
140
- $.ajax(settings).done(function (response) {
141
- //console.log(response);
142
- var ff_11_dropdown_2_val = '';
143
- //allSuppliers.push(response);
144
- var voidSuppliers = ["TEST SUPPLIER", "UNKNOWN SUPPLIER", ""];
145
- $.map(response, function(val) {
146
- allSuppliers.push({supplier_name: val.supplierName, id: val.supplierNumber, name: val.bussinessName});
147
- if($.inArray(val.supplierName, suppliersName) === -1) {
148
- if($.inArray(val.supplierName, voidSuppliers) === -1){
149
- suppliersName.push(val.supplierName);
150
- ff_11_dropdown_2_val += '<option value="'+val.supplierName+'">'+val.supplierName+'</option>';
151
- }
152
- }
153
- });
154
-
155
- $('#ff_11_dropdown_2').html(ff_11_dropdown_2_val);
156
- });
157
-
158
- //console.log(allSuppliers);
159
-
160
- function urlParam(name) {
161
- var results = (new RegExp("[\\?&]" + name + "=([^&#]*)")).exec(window.location.href);
162
- if (results == null) return null;
163
- else return results[1] || 0;
164
- };
165
-
166
- let location = decodeURI(urlParam("location"));
167
- let formnum = 1;
168
-
169
- $('.ff-el-form-check').eq(0).find('input').click();
170
- $('#ff_11_input_text').val(decodeURI(urlParam("farm_name")) === 'null' ? '' : decodeURI(urlParam("farm_name")));
171
- $('#ff_11_dropdown option[value="'+location+'"]').attr("selected","selected");
172
- $('#ff_11_names_first_name_').val(decodeURI(urlParam("fname")) === 'null' ? '' : decodeURI(urlParam("fname")));
173
- $('#ff_11_names_last_name_').val(decodeURI(urlParam("lname")) === 'null' ? '' : decodeURI(urlParam("lname")));
174
- $('#ff_11_email').val(decodeURI(urlParam("email")) === 'null' ? '' : decodeURI(urlParam("email")));
175
-
176
- $('#add-supplier').click(function(e){
177
- e.preventDefault();
178
- console.log('new supplier click');
179
- formnum++;
180
- var newfrm = '<div data-name="ff_cn_id_7" class="ff-t-container ff-column-container ff_columns_total_2 supplier_container"><div class="ff-t-cell ff-t-column-1" style="flex-basis: 50%;"><div class="ff-el-group"><div class="ff-el-input--label ff-el-is-required asterisk-right"><label for="ff_11_dropdown_2" aria-label="Supplier Name 1">Supplier Name '+formnum+'</label> </div><div class="ff-el-input--content"><select name="dropdown_2" id="ff_11_dropdown_2" class="ff-el-form-control" data-name="dropdown_2" data-calc_value="0" aria-invalid="false" aria-required="true"><option value="">– Select Supplier '+ formnum +' –</option><option value="Fonterra">Fonterra</option><option value="Arrabawn">Arrabawn</option><option value="Aurivo">Aurivo</option><option value="Carbery">Carbery</option><option value="Dairy Goat Coop">Dairy Goat Coop</option><option value="Dairygold">Dairygold</option><option value="Green Valley Dairies">Green Valley Dairies</option><option value="Mataura Valley Milk">Mataura Valley Milk</option><option value="Maui">Maui</option><option value="Miraka">Miraka</option><option value="Open Country">Open Country</option><option value="Organic Dairy Hub">Organic Dairy Hub</option><option value="Synlait">Synlait</option><option value="Tatua">Tatua</option><option value="Waiau">Waiau</option><option value="Westland">Westland</option></select></div></div></div><div class="ff-t-cell ff-t-column-2" style="flex-basis: 50%;"><div class="ff-el-group"><div class="ff-el-input--label ff-el-is-required asterisk-right"><label for="ff_11_numeric-field" aria-label="Supplier Number 1">Supplier Number '+formnum+'</label> <span id="remove-supplier">x remove</span></div><div class="ff-el-input--content"><input type="number" name="numeric-field" id="ff_11_numeric-field" class="ff-el-form-control" data-name="numeric-field" inputmode="numeric" step="any" aria-invalid="false" aria-required="true"><div id="res_dropdown"></div></div></div></div></div>';
181
- if (decodeURIComponent(urlParam("show_staph")) !== "true") newfrm += "<div style='display:none;'>"
182
- newfrm += '<div data-name="ff_cn_id_6" class="ff-t-container ff-column-container ff_columns_total_4 div4 "><div class="ff-t-cell ff-t-column-1" style="flex-basis: 25%;"><div class="ff-el-group"><div class="ff-el-input--label ff-el-is-required asterisk-right"><label for="number_of_animals_'+formnum+'" aria-label="Number of Animals">Number of Animals</label> </div><div class="ff-el-input--content"><input data-name="num_animals_'+formnum+'" type="number" name="number_of_animals_'+formnum+'" id="extra" class="ff-el-form-control" inputmode="numeric" step="any" aria-invalid="false" aria-required="true"><div id="res_dropdown2"></div></div></div></div><div class="ff-t-cell ff-t-column-2" style="flex-basis: 25%;"><div class="ff-el-group"><div class="ff-el-input--label ff-el-is-required asterisk-right"><label for="number_of_clinicalmastisis_'+formnum+'" aria-label="Number of Clinical Mastitis Cases">Number of Clinical Mastitis Cases</label> </div><div class="ff-el-input--content"><input type="number" name="number_of_clinicalmastisis_'+formnum+'" id="extra" class="ff-el-form-control" data-name="num_clinical_mastisis_'+formnum+'" inputmode="numeric" step="any" aria-invalid="false" aria-required="true"></div></div></div><div class="ff-t-cell ff-t-column-3" style="flex-basis: 25%;"><div class="ff-el-group"><div class="ff-el-input--label ff-el-is-required asterisk-right"><label for="bulk_tank_level'+formnum+'" aria-label="Bulk tank SCC level">Bulk tank SCC level</label> </div><div class="ff-el-input--content"><input type="number" name="bulk_tank_level'+formnum+'" id="extra" class="ff-el-form-control" data-name="bulk_tank_scc_'+formnum+'" inputmode="numeric" step="any" aria-invalid="false" aria-required="true"></div></div></div><div class="ff-t-cell ff-t-column-4" style="flex-basis: 25%;"><div class="ff-el-group"><div class="ff-el-input--label asterisk-right"><label for="comment_scc_mastisis'+formnum+'" aria-label="Comment on SCC and Mastitis Cases">Comment on SCC and Mastitis Cases</label> </div><div class="ff-el-input--content"><textarea aria-invalid="false" aria-required="false" name="comment_scc_mastisis'+formnum+'" id="extra" class="ff-el-form-control" rows="3" cols="2" data-name="comment_scc_'+formnum+'"></textarea></div></div></div></div>';
183
- if (decodeURIComponent(urlParam("show_staph")) !== "true") newfrm += "</div>"
184
-
185
- $('.div4:last').after('<div class="newdiv" id="form-container-'+formnum+'"></div>');
186
-
187
- //$(this).prepend(newfrm)
188
- $(document).find("#form-container-"+formnum).html(newfrm);
189
- });
190
-
191
- $(document).on('click', '#remove-supplier', function(){
192
- var p = $(this).parent().parent().parent().parent().parent();
193
- formnum -= 1;
194
- p.remove();
195
- console.log(p);
196
- fill_suppliers();
197
- });
198
-
199
- //disabled
200
- $(document).on('click', '#ff_11_numeric-field_disabled', function(){
201
- var supplier_name = $(this).parent().parent().parent().parent().find('#ff_11_dropdown_2').val();
202
- var result = [];
203
- var res = '';
204
- var el = $(this);
205
- if(supplier_name !== ''){
206
- console.log('here' + supplier_name);
207
-
208
- $.map(allSuppliers, function(val) {
209
- console.log(val.supplier_name);
210
- if(supplier_name == val.supplier_name){
211
- result.push({id: val.id, milk_supplier: val.name});
212
- }
213
-
214
- });
215
-
216
- $.map(result, function(value) {
217
- console.log(value)
218
- res += '<div id="milk-supplier" data-id="'+value.id+'">'+value.id+'-'+value.milk_supplier+'</div>';
219
- });
220
-
221
- console.log(result);
222
-
223
-
224
- el.next('#res_dropdown').html(res).css('display', 'block');
225
-
226
-
227
- }
228
-
229
- });
230
- $('#ff_11_numeric-field').after('<div id="res_dropdown"></div>');
231
-
232
- var result = {};
233
- var result2 = {};
234
- var allsuppliers = [];
235
-
236
- function fill_suppliers(){
237
- let suppliers_arr = [];
238
- let supplier_arr2 = [{}];
239
- $(".supplier_container").each(function() {
240
- var supplier = $(this).find('#ff_11_dropdown_2').val();
241
- var supplier_id = $(this).find('#ff_11_numeric-field').val();
242
- suppliers_arr.push(supplier+'-'+supplier_id);
243
- supplier_arr2.push({supplier: supplier, supplier_id: supplier_id});
244
- });
245
- allsuppliers = [];
246
- allsuppliers.push([suppliers_arr]);
247
- $('#total-samples').html(suppliers_arr.length);
248
- $('[name="hidden_6"]').val(suppliers_arr.length);
249
-
250
- //console.log(supplier_arr2)
251
- grouped = [];
252
-
253
- supplier_arr2.forEach(function (hash) {
254
- return function (o) {
255
- if (!hash[o.supplier]) {
256
- hash[o.supplier] = { supplier: o.supplier, supplier_id: '' };
257
- grouped.push(hash[o.supplier]);
258
- }
259
- if(o.supplier !== undefined){
260
- hash[o.supplier].supplier_id += o.supplier_id + '|';
261
- }
262
-
263
- };
264
- }(Object.create(null)));
265
-
266
- var grouped_suppliers = '';
267
- $('#suppliers-all').html('');
268
- //console.log('grouped')
269
- let groupnum = 13;
270
- grouped.forEach(function (item, index) {
271
- //console.log(item.supplier);
272
- if(item.supplier !== undefined){
273
- grouped_suppliers += '- ' + item.supplier + ' ' + item.supplier_id.substring(0, item.supplier_id.length-1).replace('|', ', ') + '\r\n<br>';
274
- $('[name="hidden_'+groupnum+'"]').val(' - ' + item.supplier + ' ' + item.supplier_id.substring(0, item.supplier_id.length-1).replace('|', ', '));
275
- groupnum++;
276
- }
277
-
278
- });
279
-
280
- //console.log(grouped_suppliers);
281
- $('#suppliers-all').html(grouped_suppliers);
282
- //$('[name="hidden_suppliers"]').val(allsuppliers);
283
- //$('[name="suppliers_field"]').val(grouped_suppliers);
284
- }
285
-
286
- $(document).on('blur', '#ff_11_numeric-field', function(){
287
- fill_suppliers();
288
- //console.log(allsuppliers)
289
- $('[id=res_dropdown]').slideUp();
290
- });
291
-
292
- $(document).on('keyup', '#ff_11_numeric-field_disabled', function(){
293
- res = '';
294
- var i = $(this).val();
295
- var supplier_name = $(this).parent().parent().parent().parent().find('#ff_11_dropdown_2').val();
296
- result = [];
297
- $.map(suppliers_json[supplier_name], function(val) {
298
- result.push(val);
299
- });
300
-
301
- $.map(result, function(value) {
302
-
303
- if(i != ''){
304
- var varid = value.id;
305
- var regex = new RegExp(this.value);
306
- res += varid.includes(i) ? '<div id="milk-supplier" data-id="'+value.id+'">'+value.id+'-'+value.milk_supplier+'</div>' : "";
307
- }
308
- });
309
-
310
- if(i !== ''){
311
- $(this).next('#res_dropdown').show();
312
- $(this).next('#res_dropdown').html(res);
313
- }else{
314
- $(this).next('#res_dropdown').hide();
315
- }
316
-
317
- res = '';
318
- });
319
-
320
- $(document).on('click', '#milk-supplier', function(){
321
- console.log('supplier' + $(this).data('id'));
322
- $(this).parent().parent().find('#ff_11_numeric-field').val($(this).data('id'));
323
- $(this).parent().parent().find('#ff_11_numeric-field').focus();
324
- $('[id=res_dropdown]').slideUp();
325
- })
326
-
327
- $('#ff_11_numeric-field_1').after('<div id="res_dropdown2"></div>');
328
-
329
- $("#ff_11_dropdown_3").change(function(){
330
- result2 = [];
331
- $.map(suppliers_json[this.value], function(val) {
332
- result2.push(val);
333
- });
334
- console.log(result2);
335
- console.log(result2);
336
- });
337
-
338
- var all_suppliers = {};
339
-
340
- $('#ff_11_numeric-field_1').on('keyup', function(){
341
- res2 = '';
342
- var i = $(this).val();
343
- $.map(result2, function(value) {
344
- //res += val.id +'-'+ val.milk_supplier + '\r\n';
345
- //console.log(1);
346
- if(i !== ''){
347
- var varid = value.id;
348
- var regex = new RegExp(this.value);
349
- //console.log(varid);
350
- //console.log(this.value);
351
-
352
- res2 += varid.includes(i) ? '<div>'+value.id+'-'+value.milk_supplier+'</div>' : "";
353
- $('#res_dropdown2').css('display', 'block');
354
-
355
- var last_supplier = $(this).prev('#ff_11_dropdown_2').val();
356
- //console.log(last_supplier);
357
- }
358
-
359
-
360
- });
361
- if(i !== ''){
362
- $('#res_dropdown2').html(res2);
363
- }else{
364
- $('#res_dropdown2').css('display', 'none');
365
- }
366
-
367
- res = ''
368
- });
369
-
370
- $('#ff_11_dropdown_2').change(function(){
371
- $('#ff_11_numeric-field').val('');
372
- });
373
-
374
- $('#ff_11_phone_1').on('keyup', function(){
375
- $('#owner-phone').html($(this).val());
376
- $("input[name=hidden_3]").val($(this).val());
377
- });
378
-
379
- $('#ff_11_input_text').on('keyup', function(){
380
- $('#farm-business-name').html($(this).val());
381
- $("input[name=hidden_1]").val($(this).val());
382
- });
383
-
384
- // $('#ff_11_dropdown_1').change(function(){
385
- // $('#role').html($(this).val());
386
- // $("input[name=hidden_12]").val($(this).val());
387
- // });
388
-
389
- $(document).on('change', '#extra', function(){
390
- var name = $(this).data('name');
391
- var value = $(this).val();
392
- console.log(name, value);
393
- $('input[name="'+name+'"]').val(value);
394
- });
395
-
396
- $('#ff_11_number_of_animals_1').change(function(){
397
- var value = $(this).val();
398
- $('input[name="num_animals_1"]').val(value);
399
- });
400
- $('#ff_11_number_of_clinicalmastisis_1').change(function(){
401
- var value = $(this).val();
402
- $('input[name="num_clinical_mastisis_1"]').val(value);
403
- });
404
- $('#ff_11_bulk_tank_level2').change(function(){
405
- var value = $(this).val();
406
- $('input[name="bulk_tank_scc_1"]').val(value);
407
- });
408
- $('#ff_11_comment_scc_mastisis2').change(function(){
409
- var value = $(this).val();
410
- $('input[name="comment_scc_1"]').val(value);
411
- });
412
-
413
-