Skip to content
PDF

Widgets behaviours

Several widgets within the Beautiful WebForms's widget library require the presence of a specific piece of code within one of the CLEH scripts in order to properly work. Most of these widgets will prompt you for injecting its piece of script directly from the configuration panel.

The injected script will be bound to the current widget's configuration, thus any change applied to the widget's configuration will be automatically reflected on the injected piece of script. In order to disable this binding you can either switch off the "Auto-inject code" switch on the widget's configuration panel or remove the binding key from the injected script snippet.

The Content Script snippets to be injected are stored in the Content Script Volume under: CSScriptSnippets:Beautiful WebForms. For most of the widgets that require a CLEH counterpart, the AnswerModule's team has codified the most appropriate business logic in the form of a reusable closures. These closures have been organized in families and have been made easily accessible through the AMBWFWidgetsLib utility class.

The AMBWFWidgetsLib utility class features the following API:

@ContentScriptAPIMethod(params=["nameSpace", "closureName", "callingScript"], description="Returns a well configured closure for managing the BL of a BFW widget")
public static Closure getBehaviour(String nameSpace, String closureName, def delegate){

Behaviours reference

The next chapters will give a reference implementation for the available closures.

getSmartUISprite

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
"getSmartUISprite": {def node ->

  def candidates = []
  def nodeSprites = [
    [
      // excel
      equals: [
      mime_type: [
        'application/vnd.ms-excel',
        'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
        'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
        'application/vnd.ms-excel.sheet.macroEnabled.12',
        'application/vnd.ms-excel.template.macroEnabled.12',
        'application/vnd.ms-excel.addin.macroEnabled.12',
        'application/vnd.ms-excel.sheet.binary.macroEnabled.12'
      ]
      ],
      className: 'csui-icon mime_excel',

      sequence: 50
    ],
    [
      // visio
      equals: [
      mime_type: [
        'application/visio',
        'application/x-visio',
        'application/vnd.visio',
        'application/visio.drawing',
        'application/vsd',
        'application/x-vsd',
        'image/x-vsd',
        'application/vnd.visio2013',
        'application/vnd.ms-visio.drawing',
        'application/vnd.ms-visio.viewer',
        'application/vnd.ms-visio.stencil',
        'application/vnd.ms-visio.template'
      ]
      ],
      className: 'csui-icon mime_visio',

      sequence: 50
    ],
    [
      // spreadsheets
      equals: [
      mime_type: [
        'application/vnd.oasis.opendocument.spreadsheet',
        'application/vnd.oasis.opendocument.spreadsheet-template',
        'application/vnd.sun.xml.calc',
        'application/vnd.sun.xml.calc.template',
        'application/vnd.stardivision.calc',
        'application/x-starcalc'
      ]
      ],
      className: 'csui-icon mime_spreadsheet',

      sequence: 50
    ],
    [
      // powerpoint
      equals: [
      mime_type: [
        'application/vnd.ms-powerpoint',
        'application/vnd.openxmlformats-officedocument.presentationml.presentation',
        'application/vnd.openxmlformats-officedocument.presentationml.template',
        'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
        'application/vnd.ms-powerpoint.addin.macroEnabled.12',
        'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
        'application/vnd.ms-powerpoint.template.macroEnabled.12',
        'application/vnd.ms-powerpoint.slideshow.macroEnabled.12'
      ]
      ],
      className: 'csui-icon mime_powerpoint',

      sequence: 50
    ],
    [
      // presentations
      equals: [
      mime_type: [
        'application/vnd.google-apps.presentation', // GSLIDE - Google Drive Presentation
        'application/x-iwork-keynote-sffkey', // KEY, KEYNOTE — Apple Keynote Presentation
        'application/vnd.wolfram.mathematica', // NB — Mathematica Slideshow
        'application/vnd.wolfram.player', // NBP — Mathematica Player slideshow
        'application/vnd.oasis.opendocument.presentation', // ODP — OpenDocument Presentation
        'application/vnd.oasis.opendocument.presentation-template', // OTP - ODP Template
        'application/vnd.sun.xml.impress',
        'application/vnd.sun.xml.impress.template',
        'application/vnd.stardivision.impress',
        'application/vnd.stardivision.impress-packed',
        'application/x-starimpress',
        'application/vnd.lotus-freelance', // PRZ — Lotus Freelance Graphics
        'application/vnd.stardivision.impress', // SDD - Star Office's StarImpress
        'application/vnd.corel-presentations', // SHW — Corel Presentations slide show creation
        'application/vnd.sun.xml.impress', // SXI — OpenOffice.org XML (obsolete) Presentation
        'application/vnd.ms-officetheme', // THMX — Microsoft PowerPoint theme template
        'application/vnd.sun.xml.impress.template '// STI — OpenOffice Impress template

        // the following extensions could not mapped to a mime-type
        // todo: intro mapping to file extensions
        // WATCH — Dataton Watchout Presentation
        // PEZ — Prezi Desktop Presentation
        // SHF — ThinkFree Show
        // SHOW — Haansoft(Hancom) Presentation software document
        // SLP — Logix-4D Manager Show Control Project
        // SSPSS — SongShow Plus Slide Show

      ]
      ],
      className: 'csui-icon mime_presentation',

      sequence: 50
    ],
    [
      // MS Office publisher
      equals: [
      mime_type: [
        'application/vnd.ms-publisher',
        'application/x-mspublisher'
      ]
      ],
      className: 'csui-icon mime_publisher',

      sequence: 50
    ],
    [
      // formulas
      equals: [
      mime_type: [
        'application/vnd.oasis.opendocument.formula',
        'application/vnd.sun.xml.math',
        'application/vnd.stardivision.math',
        'application/x-starmath'
      ]
      ],
      className: 'csui-icon mime_formula',

      sequence: 50
    ],
    [
      // pdf
      equals: [
      mime_type: [
        'application/vnd.pdf',
        'application/x-pdf',
        'application/pdf'
      ]
      ],
      className: 'csui-icon mime_pdf',

      sequence: 50
    ],
    [
      // word
      equals: [
      mime_type: [
        'application/msword',
        'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
        'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
        'application/vnd.ms-word.document.macroEnabled.12',
        'application/vnd.ms-word.template.macroEnabled.12'
      ]
      ],
      className: 'csui-icon mime_word',

      sequence: 50
    ],
    [
      // MS OneNote
      equals: [
      mime_type: [
        'application/onenote',
        'application/msonenote'
      ]
      ],
      className: 'csui-icon mime_onenote',

      sequence: 50
    ],
    [
      // MS project
      equals: [
      mime_type: [
        'application/vnd.ms-project',
        'application/msproj',
        'application/msproject',
        'application/x-msproject',
        'application/x-ms-project',
        'application/mpp'
      ]
      ],
      className: 'csui-icon mime_project',

      sequence: 50
    ],
    [
      // image
      startsWith: [mime_type: 'image/'],
      className: 'csui-icon mime_image',

      sequence: 50
    ],
    [
      // audio
      startsWith: [mime_type: 'audio/'],
      className: 'csui-icon mime_audio',

      sequence: 50
    ],
    [
      // text
      startsWith: [mime_type: 'text/'],
      className: 'csui-icon mime_paper',

      sequence: 50
    ],
    [
      // text
      equals: [mime_type: 'text/html'],
      className: 'csui-icon mime_html',

      // startsWith 'text/' operation happens first, which would decide the icon otherwise;
      // it has the sequence number 50 in common
      // do not set sequence to 30 that would take over the 'type' that has this MIME type
      // and do not set to 50 because this object with this MIME type would have a different icon
      sequence: 40
    ],
    [
      // video
      startsWith: [mime_type: 'video/'],
      className: 'csui-icon mime_video',

      sequence: 50
    ],
    [
      // zip
      equals: [
      mime_type: [
        'application/x-rar-compressed',
        'application/zip',
        'application/x-zip',
        'application/x-zip-compressed'
      ]
      ],
      className: 'csui-icon mime_zip',

      sequence: 50
    ],
    [
      // compound document
      equals: [type: 136],
      className: 'csui-icon compound_document',
      sequence: 100
    ],
    [
      // document
      equals: [type: 144],
      className: 'csui-icon mime_document',
      sequence: 100
    ],
    [
      // CAD
      equals: [type: 736],
      className: 'csui-icon mime_drawing',
      sequence: 100
    ],
    [
      // saved search query
      equals: [type: 258],
      className: 'csui-icon csui-icon-saved-search-query',

      sequence: 100
    ],
    [
      // e-mail
      equals: [type: 749],
      className: 'csui-icon mime_mail',
      sequence: 100
    ],
    [
      // URL link
      equals: [type: 140],
      className: 'csui-icon url1',

      sequence: 100
    ],
    [
      // shortcut
      equals: [type: 1],
      className: 'csui-icon shortcut1',
      sequence: 100
    ],
    [
      // generation
      // note: since the RestAPI at the moment does not return the document version, showing the
      // latest document mime-type icon with the shortcut overlay is incorrect.  Use the
      // generation icon for now.  When the RestAPI and UI supports Generation, switch this to
      // generation-overlay.
      equals: [type: 2],
      className: 'csui-icon mime_generation',
      sequence: 100
    ],
    [
      // category
      equals: [type: 131],
      className: 'csui-icon category1',
      sequence: 100
    ],
    [
      // project
      equals: [type: 202],
      className: 'csui-icon csui-icon-project',
      sequence: 100
    ],
    [
      // collection
      equals: [type: 298],
      className: 'csui-icon collection',
      sequence: 100
    ],
    [
      equals: [type: 141],
      className: 'csui-icon csui-icon-enterprise-volume',
      sequence: 100
    ],
    [
      equals: [type: 142],
      className: 'csui-icon csui-icon-personal-volume',
      sequence: 100
    ],
    [
      equals: [type: 133],
      className: 'csui-icon csui-icon-category-volume',
      sequence: 100
    ],
    [
      // Category Folder
      equals: [type: 132],
      className: 'csui-icon csui-icon-node-category-folder',
      sequence: 100
    ],
    [
      // E-mail Folder
      equals: [type: 751],
      className: 'csui-icon csui-icon-node-mail-folder',
      sequence: 100
    ],
    [
      // LiveReport
      equals: [type: 299],
      className: 'csui-icon csui-icon-node-livereport',
      sequence: 100
    ],
    [
      // Milestone
      equals: [type: 212],
      className: 'csui-icon csui-icon-node-milestone',
      sequence: 100
    ],
    [
      // Poll
      equals: [type: 218],
      className: 'csui-icon csui-icon-node-poll',
      sequence: 100
    ],
    [
      // Prospector
      equals: [type: 384],
      className: 'csui-icon csui-icon-node-prospector',
      sequence: 100
    ],
    [
      // Task
      equals: [type: 206],
      className: 'csui-icon csui-icon-node-task',
      sequence: 100
    ],
    [
      // Task Group
      equals: [type: 205],
      className: 'csui-icon csui-icon-node-task-group',
      sequence: 100
    ],
    [
      // Task List
      equals: [type: 204],
      className: 'csui-icon csui-icon-node-task-list',
      sequence: 100
    ],
    [
      // Virtual Folder
      equals: [type: 899],
      className: 'csui-icon csui-icon-node-virtual-folder',
      sequence: 100
    ],
    [
      // Custom View
      equals: [type: 146],
      className: 'csui-icon mime_custom_view',
      // Custom View has a MIME type, which would decide the icon otherwise;
      // the MIME type icons have the sequence number 50 in common
      sequence: 30
    ],
    [
      // Workflow Step
      equals: [type: 153],
      className: 'csui-icon assignment-workflow',
      sequence: 100
    ],
    [
      // Workflow Map
      equals: [type: 128],
      className: 'csui-icon mime_workflow_map',
      sequence: 100
    ],
    [
      // Workflow Status
      equals: [type: 190],
      className: 'csui-icon mime_workflow_status',
      sequence: 100
    ],
    [
      // Channel
      equals: [type: 207],
      className: 'csui-icon mime_channel',
      sequence: 100
    ],
    [
      // News item
      equals: [type: 208],
      className: 'csui-icon mime_news',
      sequence: 100
    ],
    [
      // Discussion
      equals: [type: 215],
      className: 'csui-icon mime_discussion',
      sequence: 100
    ],
    [
      // XML DTD
      equals: [type: 335],
      className: 'csui-icon mime_xml_dtd',
      // XML DTD has a MIME type, which would decide the icon otherwise;
      // the MIME type icons have the sequence number 50 in common
      sequence: 30
    ],
    [
      // form
      equals: [type: 223],
      className: 'csui-icon mime_form',
      sequence: 100
    ],
    [
      // form template
      equals: [type: 230],
      className: 'csui-icon mime_form_template',
      sequence: 100
    ],
    [
      // pulse comments
      equals: [type: 1281],
      className: 'csui-icon icon-pulse-comment',
      sequence: 100
    ],
    [
      // wiki pages
      equals: [type: 5574],
      className: 'csui-icon mime_wiki_page',
      sequence: 10
    ],
    // wikis
    [
      equals: [type: 5573],
      className: 'csui-icon mime_wiki',
      sequence: 10
    ],
    [
      // default container
      equals: [container: 'nonselectable'],
      className: 'csui-icon mime_folder_nonselectable',
      sequence: 1000
    ],
    [
      // default container; covers folder-like nodes too
      equals: [container: true],
      className: 'csui-icon mime_folder',
      sequence: 1000
    ],
    [
      // default node
      className: 'csui-icon mime_document',
      sequence: 10000
    ]
    ]

  nodeSprites.each{ sprite->
    if(sprite.startsWith){
      if(sprite.startsWith.mime_type){
        if(node?.mimeType?.startsWith(sprite.startsWith.mime_type)){
          candidates+=sprite
        }
      }
    }else if(sprite.equals){
      if(sprite.equals.mime_type){
        sprite.equals.mime_type.each{ val->
          if(node?.mimeType?.equals(val)){
            candidates+=sprite
          }
        }

      }else if(sprite.equals.type){
        if(node.subtype == (sprite.equals.type)){
          candidates+=sprite
        }
      }else if(sprite.equals.container && sprite.equals.container == true){
        if(node.isContainer){
          candidates+=sprite
        }
      }
    }
  }

  candidates += [
    // default node
    className: 'csui-icon mime_document',
    sequence: 10000
  ]
  return candidates.sort{it.sequence}[0].className

}

generateRandomHTMLColor

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
"generateRandomHTMLColor": { Random r = AMBWFWidgetsLib.random  ->
    def hex = "0123456789abcdef".toCharArray()
    char [] s = new char[7];
    int     n = r.nextInt(0x1000000);
    s[0] = '#';
    for (int i=1;i<7;i++) {
        s[i] = hex[n & 0xf];
        n >>= 4;
    }
    return new String(s);
}

handsOnTable

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
"handsOnTable":{ setNameOriginal, colHeadersMappingMap, configureColumns={}, colHeadersTotalsMappingMap=[:]->
  def setName = setNameOriginal.split("\\.").last()
  def identifier = "amhot_"+form[setName].id

  if(params.am_Action == 'amhot_loadData' &&  params.am_ActionParams != form[setName].id){
    return
  }

  def colHeadersMapping = colHeadersMappingMap.collectEntries{
    [(it.key.replaceAll("form\\.${setName}\\.", "") as String):it.value]
  }

  def colHeadersTotalsMapping = colHeadersTotalsMappingMap.collectEntries{
    [(it.key.replaceAll("form\\.${setName}\\.", "") as String):it.value]
  }

  if(params.am_Action == 'am_removeMultipleRows'){
    def actionsParameters = params.am_ActionParams
    def elements = params.am_ActionParams.split(",")
    if(elements.size()==3){
      ((elements[2] as int)).times{
        form.removeField(elements[0], (elements[1] as int))
      }
    }
  }

  if(params.am_Action == 'am_moveRows'){
    def actionsParameters = params.am_ActionParams
    def elements = params.am_ActionParams.split("\\|")
    if(elements.size()==3){
      def mySetName = elements[0].split("\\.").last()
      elements[1].split(",").each{
        form[mySetName].swap(it as int, (elements[2] as int)-1)
      }
      form[mySetName].updateFieldId()
    }
  }


  def handontableData = [:]
  handontableData.columns = []
  handontableData.colHeaders = colHeadersMapping*.value
  handontableData.data = []
  handontableData.totals = [:]
  handontableData.maxRows = form[setName].max

  def list = []

  def keys = colHeadersMapping.keySet()

  form[setName].eachWithIndex{ setRow, index->
    def map = [:]
    map.id = (index+1)
    keys.each{
      map[colHeadersMapping[it]] = (setRow[it].value)
      if(colHeadersTotalsMapping[it]){
        if(!handontableData.totals[colHeadersMapping[it]]){
          handontableData.totals[colHeadersMapping[it]] = [setRow[it].value]
        }else{
          handontableData.totals[colHeadersMapping[it]] << setRow[it].value
        }
      }
    }
    handontableData.data.add(map)
  }

  colHeadersTotalsMapping.each{
    switch(it.value?.toUpperCase()){
      case "COUNT":
        handontableData.totals[colHeadersMapping[it.key]] = handontableData.totals[colHeadersMapping[it.key]].size()
        break;
      case "SUM":
        handontableData.totals[colHeadersMapping[it.key]] = handontableData.totals[colHeadersMapping[it.key]].inject(0) { tot, ele -> 
              if(ele){
                tot += (ele as BigDecimal)
              } 
              return tot
            }
        break;
      case "AVG":
        def size = handontableData.totals[colHeadersMapping[it.key]].size()
        if(size>0){
          handontableData.totals[colHeadersMapping[it.key]] = (handontableData.totals[colHeadersMapping[it.key]].inject(0) { tot, ele -> 
              if(ele){
                tot += (ele as BigDecimal)
              } 
              return tot
            })/size
            /**/
        }else{
          handontableData.totals[colHeadersMapping[it.key]] = 0
        }
        break;
      case "MIN":
        if(form[setName][0][it.key].fieldType == 301){
          def format = form[setName][0][it.key].format
          handontableData.totals[colHeadersMapping[it.key]] = handontableData.totals[colHeadersMapping[it.key]].findAll{it}.collect { ele -> Date.parse(format,ele) }.min()?.format(format)
        }else {
          handontableData.totals[colHeadersMapping[it.key]] = handontableData.totals[colHeadersMapping[it.key]].findAll{it}.collect { ele -> 
            if(ele){
              return (ele as BigDecimal)
            }else{
              return 0
            } }.min()
        }
        break;
      case "MAX":
        if(form[setName][0][it.key].fieldType == 301){
          def format = form[setName][0][it.key].format
          handontableData.totals[colHeadersMapping[it.key]] = handontableData.totals[colHeadersMapping[it.key]].findAll{it}.collect { ele -> Date.parse(format,ele) }.max()?.format(format)
        }else {
          handontableData.totals[colHeadersMapping[it.key]] = handontableData.totals[colHeadersMapping[it.key]].findAll{it}.collect { ele -> 
            if(ele){
              return (ele as BigDecimal)
            }else{
              return 0
            } }.max()
        }
        break;

    }

  }

  if(colHeadersTotalsMapping && handontableData.totals){
    handontableData.totals = [handontableData.totals]
  }

  colHeadersMapping.eachWithIndex{ it, index->
    def col = [:]
    def type =""


    col.data = it.value
    col.allowInvalid= false
    col.formID =  form[setName][0][it.key].id

    switch( form[setName][0][it.key].fieldType){
      case 11: //TextArea
      case -1: //String
        break;
      case 301: //Date
        col.type= "date"
        col.dateFormat =  form[setName][0][it.key].format.toUpperCase()?.replace("'", "")
        col.correctFormat=true
        break;
      case 5: //Boolean
      case 300: //CheckBoxBoolean
        col.type='checkbox'
        col.checkedTemplate='true'
        col.uncheckedTemplate='false'
        break;
      case -4://Real
        col.type ="numeric"
        col.format =  form[setName][0][it.key].format?.replace("'", "")
        break;
      case 14://User
      case 2: //Integer
        col.type = "numeric"
        break;
      case 10: //TextPopup
      case 13: //Date popup
      case 20: //Real popup
      case 12: //IntegerPopup
        col.type = "dropdown"
        break
    }
    handontableData.columns += col
  }


  configureColumns(handontableData.columns)
  if(params.am_Action == 'amhot_loadData'){
    json(handontableData)
    return
  }
  def builder = new JsonBuilder()
  builder(handontableData)
  def tempString= builder.toString()

  form.viewParams.handontableData = (form.viewParams.handontableData?:[:])
  form.viewParams.handontableData[identifier] = tempString

}

defineViewParamVar

1
2
3
4
5
6
7
8
9
"defineViewParamVar":{ String name, Closure loadClosure->
  if(!form.viewParams[name]){
    try{
      form.viewParams[name] = loadClosure()
    }catch(e){
      log.error("Unable to gather information for loading '${name}' viewParams variable", e)
    }
  }
}

fileUpload

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"fileUpload":{ boolean errorsAsFormValidationErrors, String action=null, String fileName='am_dropFile'->
  if(params.am_Action == (action?:'am_dropFile') || action == "*"){
    def file = new File(params[fileName])
    if(file.exists()){
      try{
        def parentSpace = docman.getNodeFast(params[fileName+"ParentID"] as long)
        if(parentSpace){
          docman.createDocument( parentSpace,
              org.apache.commons.io.FilenameUtils.getName(params[fileName+"_filename"]),
              file,
              "",
              false,
              parentSpace)
        }else{
          log.error("Unable to locate parent space where to upload file parent ID ${params.am_dropFileParentID}")
          if(errorsAsFormValidationErrors){
            form.addValidationError("Unable to locate parent space where to upload file parent ID ${params.am_dropFileParentID}")
          }
        }

      }catch(e){
        log.error('Unable to upload file',e)
        if(errorsAsFormValidationErrors){
          form.addValidationError("Unable to upload file ${file.name} in space ${params.am_dropFileParentID as long}")
        }
      }
    }
  }
}

getFormViewsConsole

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
"getFormViewsConsole":{
  if(!form.viewParams.views){
    if(form.viewParams.am_viewDefinition){
      form.viewParams.am_viewDefinition.each{ 
        def subViewId = it.id
        if(subViewId){
          def subViewFile = form.amRemotePack.views[subViewId as Long]
          if(!form.viewParams.views[subViewName]){
            form.viewParams.views[subViewName] = subViewFile.text
          }
        }
      }
    }
  }
  return form.viewParams.views
}

runSubViewOnLoadConsole

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
"runSubViewOnLoadConsole":{String... subViewNames->
  if(!form.viewParams.views){
    form.viewParams.views = [:]
  }
  if(!form.viewParams.am_JsViewDependecies){
    form.viewParams.am_JsViewDependecies = []
  }
  if(!form.viewParams.am_CssViewDependecies){
    form.viewParams.am_CssViewDependecies = []
  }
  def scriptsToExecute = []
  if(form.viewParams.am_viewDefinition){
    subViewNames.each{ subViewName ->
      def subViewDefinition = form.viewParams.am_viewDefinition.find{it.name== subViewName}
      if(subViewDefinition){
        def subViewId = subViewDefinition.id
        if(subViewId){
          def subViewFile = form.amRemotePack.views[subViewId as Long]
          if(!form.viewParams.views[subViewName]){
            form.viewParams.views[subViewName] = subViewId 

            form.viewParams.am_JsViewDependecies.addAll(subViewDefinition.depJs)
            form.viewParams.am_CssViewDependecies.addAll(subViewDefinition.depCss)
          }

          def viewOnLoad = new File(subViewFile.absolutePath+"_onLoad.cs")
          if(viewOnLoad.exists()){
            scriptsToExecute.add(viewOnLoad.text)
          }
        }
      }
    }
  }
  for(String script : scriptsToExecute){
    if(script){
      def scriptExResult = evaluate(script)
      if(response.getHeader('Content-Type')?.contains("application/json")){
        return true
      }
      if(response.status == 302){
        return true
      } else if( scriptExResult instanceof File ){
        sendFile(scriptExResult)
        return true
      } else if( scriptExResult instanceof CSResource ){

        if(scriptExResult.name){
          sendFile(scriptExResult.content, scriptExResult.name, null)
        } else {
          sendFile(scriptExResult.content)
        }
        return true
      }
    }
  }

}```

###runSubViewOnLoad
``` Groovy linenums="1"
"runSubViewOnLoad":{ String... subViewNames->
  if(form.amRemotePack){
    return AMBWFWidgetsLib.getBehaviour("ambwf", "runSubViewOnLoadConsole", delegate)(*subViewNames)
  }
  AMBWFWidgetsLib.getBehaviour("ambwf", "getFormViews", delegate)()
  sql.runSQLFast("""select  s.VersionNum VN,
                              s.DataID SID, 
                              s.ExtendedData ETD 
                      from DTree v, DTree s 
                      where v.SubType = 43100
            and v.Name in (${subViewNames.collect{"'${it}'"}.join(",")})
                      and v.ParentID = %1
                      and v.DataID = s.ParentID 
                      and s.Name ='OnLoad'
                      and s.SubType =43200""", false, false, -1, form.getAmTemplateId()).rows.each{
  def extData = it.ETD
  def extDataMap =[:]
  if(extData){
    extDataMap = extData.getMapFromOscript()
  }
    runCS(new com.answer.modules.cscript.scripting.ContentScript(null, "${it.SID}", it.VN), extDataMap)
  }

  /*def views= AMBWFWidgetsLib.getBehaviour("ambwf", "getFormViews", delegate)()
  subViewNames.each{ subViewName->
    if(views[subViewName]){
      def script = docman.getNodeByName(docman.getNodeFast(views[subViewName]), "OnLoad")
      if(script){
        runCS(script.ID)
      }
    }
  }*/
}

getFormViews

1
2
3
4
5
6
7
8
"getFormViews":{
  if(!form.viewParams.views){
    form.viewParams.views= docman.getNodeFast(form.getAmTemplateId()).childrenFast.collectEntries{
      [(it.name):it.ID]
    }
  }
  return form.viewParams.views
}

getWorkflowComments

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"getWorkflowComments":{ String dateFormat->
  if(form.getAmSubWorkID()){
    if(params.am_wfcomment){
      try{
        workflow.getWorkFlowTask(form.getAmWorkID(), form.getAmSubWorkID(), form.getAmTaskID()).addComment(params.am_wfcomment, true)
      }catch(e){
        log.error("Unable to add a comment",e)
        form.addValidationError('Error adding comment to workflow.')
      }
    }
    form.viewParams.workflowComments = workflow.getWorkflowStatus(form.getAmWorkID(), form.getAmSubWorkID()).comments.collect{
      def memberName
      def commentDate
      try{
        memberName = users.getMemberById(it.memberID)?.displayName
      } catch(e){
        memberName = null
      }

      try{
        commentDate = it.commentDate?.format(dateFormat)
      } catch(e){
        commentDate = null
      }
      [
        memberName: memberName,
        commentDate: (commentDate) ? commentDate : it.commentDate,
        memberid: it.memberID,
        comment: it.comment?:''
      ]
    }.grep{ it.comment }
  }
}

smartLookup

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
"smartLookup": { tableName, keyCol, valCol, additionalInfo, imageInfo, additionalSQL ->

  imageInfo = (imageInfo)?", ${imageInfo} IMMINFO":""
  additionalInfo = (additionalInfo)?", ${additionalInfo} AINFO":""
  def processLookup = {
    def lookupSql = ""
    def first = 2
    def values =[]
    if(params."lookup[]_list"){

      lookupSql = params."lookup[]_list".collect{
        def elements = it.split("@@")
        if(elements.size()==2){
          values.add(elements[1])
          return "AND ${elements[0]} = %${first++}"
        }else{
          "AND ${elements[0]} = ''"
        }
      }.join(" ")
    }else if(params."lookup[]"){

      def elements = params."lookup[]".split("@@")
      if(elements.size()==2){
        values.add(elements[1])
        lookupSql = "AND ${elements[0]} =%${first++}"
      }else{
        lookupSql = "AND ${elements[0]} =''"
      }
    }
    return [sql:lookupSql, vals:values]
  }

  def list = []
  if(params.id){
    //Requested a single item
    // Retrive and filter items from your datasource here
    def lookUps = processLookup()
    lookUps.vals.add(0, params.id)
    list = sql.runSQL("""
    select ${keyCol} AMKEY, ${valCol} AMVAL ${additionalInfo}${imageInfo}
    from ${tableName}
    where 
    ${keyCol} = %1

    ${lookUps.sql}
${additionalSQL}
    """, true, true, 500, *lookUps.vals).rows

    if(list.size() == 1){
      elem = list[0]
      json(
          [
            id:     elem.AMKEY,
            text:   elem.AMVAL,
            image:  elem.IMMINFO,
            desc:   elem.AINFO
          ]

          )
      return
    }

  }else{
    //Requested a list of items
    // Retrive and filter items from your datasource here
    def lookUps = processLookup()
    lookUps.vals.add(0, params.term.toUpperCase())
    if(params.term){

      list = sql.runSQL("""
    select ${keyCol} AMKEY, ${valCol} AMVAL ${additionalInfo}${imageInfo}
    from ${tableName}
    where 
    UPPER(${valCol}) like %1${"ORACLE"==(docman.getServerDBMS() as String)?"||":"+"}'%%'

    ${lookUps.sql}
${additionalSQL}
    """, true, true, 500, *lookUps.vals).rows
    }else{

      list = sql.runSQL("""
    select ${keyCol} AMKEY, ${valCol} AMVAL ${additionalInfo}${imageInfo}
    from ${tableName}
    where 
    1 = 1

    ${lookUps.sql}
${additionalSQL}
    """, true, true, 500, *lookUps.vals).rows
    }


    //Transform the result accordignly with your needs
    list = list.collect{ elem->
      [
        id:     elem.AMKEY,
        text:   elem.AMVAL,
        image:  elem.IMMINFO,
        desc:   elem.AINFO
      ]
    }

    json(list)
    return
  }

}

  1. FormBuilder acts as a Model View Controller framework with respect to BWF Widgets 

  2. Paths are relative to the folder /support/ansbwebform/lib 

  3. Paths are relative to the folder /support/ansbwebform/lib/v4, paths are defined in the View Template through Velocity expressions