@@ -289,7 +289,6 @@ define([
289
289
290
290
// open option popup
291
291
$ ( document ) . on ( 'click' , this . wrapSelector ( '.vp-ins-opt-button:not(.disabled)' ) , function ( event ) {
292
- // TODO: pdIdt_head to general
293
292
if ( that . optionPopup ) {
294
293
that . optionPopup . open ( ) ;
295
294
}
@@ -322,9 +321,80 @@ define([
322
321
this . isFirstPage = false ;
323
322
this . renderPage ( ) ;
324
323
}
324
+ var splitList = [ ] ;
325
+ if ( variable != '' ) {
326
+ splitList = variable . split ( '.' ) ;
327
+ }
328
+ var hasOption = false ;
329
+ // get parameter
330
+ if ( splitList && splitList . length > 0 ) {
331
+ var lastSplit = splitList [ splitList . length - 1 ] ;
332
+ // get target code
333
+ var methodName = lastSplit . match ( / [ a - z A - Z _ ] + / i) [ 0 ] ;
334
+ var targetCode = splitList . slice ( 0 , splitList . length - 1 ) . join ( '.' ) ;
335
+ if ( ( prevVarType in instanceLibrary . INSTANCE_MATCHING_LIBRARY ) && ( methodName in instanceLibrary . INSTANCE_MATCHING_LIBRARY [ prevVarType ] ) ) {
336
+ // get target library
337
+ var targetLib = instanceLibrary . INSTANCE_MATCHING_LIBRARY [ prevVarType ] [ methodName ] ;
338
+ var targetId = targetLib . target ;
339
+ var popupState = {
340
+ config : {
341
+ name : methodName , category : 'Instance' ,
342
+ id : targetLib . id ,
343
+ saveOnly : true ,
344
+ noOutput : true
345
+ }
346
+ }
347
+ // add targetid as state if exists
348
+ if ( targetId ) {
349
+ popupState [ targetId ] = targetCode ;
350
+ }
351
+ that . optionPopup = new LibraryComponent ( popupState ,
352
+ {
353
+ pageThis : that ,
354
+ useInputVariable : true ,
355
+ targetSelector : that . pageThis . wrapSelector ( '#' + that . targetId ) ,
325
356
326
- var code = com_util . formatString ( '_vp_print(_vp_load_instance("{0}"))' , variable ) ;
357
+ finish : function ( code ) {
358
+ // set parameter
359
+ let lastSplit = code ?. split ( '.' ) ?. pop ( ) ;
360
+ // if bracket is at the end of code
361
+ let matchList = lastSplit . match ( / \( .* ?\) $ / gi) ;
362
+ if ( matchList != null && matchList . length > 0 ) {
363
+ let lastBracket = matchList [ matchList . length - 1 ] ;
364
+ // remove first/last brackets
365
+ let parameter = lastBracket . substr ( 1 , lastBracket . length - 2 ) ;
366
+ $ ( that . wrapSelector ( '.' + VP_INS_PARAMETER ) ) . val ( parameter ) ;
367
+ }
368
+
369
+ $ ( that . pageThis . wrapSelector ( '#' + that . targetId ) ) . trigger ( {
370
+ type : "instance_editor_replaced" ,
371
+ originCode : that . state . code ,
372
+ newCode : code
373
+ } ) ;
374
+ }
375
+ }
376
+ ) ;
377
+ hasOption = true ;
378
+ } else {
379
+ that . optionPopup = null ;
380
+ }
327
381
382
+ if ( hasOption ) {
383
+ if ( $ ( that . wrapSelector ( '.vp-ins-opt-button' ) ) . hasClass ( 'disabled' ) ) {
384
+ $ ( that . wrapSelector ( '.vp-ins-opt-button' ) ) . removeClass ( 'disabled' ) ;
385
+ }
386
+ } else {
387
+ if ( ! $ ( that . wrapSelector ( '.vp-ins-opt-button' ) ) . hasClass ( 'disabled' ) ) {
388
+ $ ( that . wrapSelector ( '.vp-ins-opt-button' ) ) . addClass ( 'disabled' ) ;
389
+ }
390
+ }
391
+ } else {
392
+ if ( ! $ ( that . wrapSelector ( '.vp-ins-opt-button' ) ) . hasClass ( 'disabled' ) ) {
393
+ $ ( that . wrapSelector ( '.vp-ins-opt-button' ) ) . addClass ( 'disabled' ) ;
394
+ }
395
+ }
396
+
397
+ var code = com_util . formatString ( '_vp_print(_vp_load_instance("{0}"))' , variable ) ;
328
398
vpKernel . execute ( code ) . then ( function ( resultObj ) {
329
399
let { result } = resultObj ;
330
400
var varObj = {
@@ -434,50 +504,8 @@ define([
434
504
} ) ;
435
505
436
506
// get parameter
437
- var splitList = variable . split ( '.' ) ;
438
- // var hasOption = false;
439
-
440
507
if ( splitList && splitList . length > 0 ) {
441
508
var lastSplit = splitList [ splitList . length - 1 ] ;
442
- // // get target code
443
- // var methodName = lastSplit.match(/[a-zA-Z_]+/i)[0];
444
- // var targetCode = splitList.slice(0, splitList.length - 1).join('.');
445
- // if ((prevVarType in instanceLibrary.INSTANCE_MATCHING_LIBRARY) && (methodName in instanceLibrary.INSTANCE_MATCHING_LIBRARY[prevVarType])) {
446
- // // get target library
447
- // var targetLib = instanceLibrary.INSTANCE_MATCHING_LIBRARY[prevVarType][methodName];
448
- // var targetId = targetLib.target;
449
- // var popupState = {
450
- // config: {
451
- // name: methodName, category: 'Instance',
452
- // id: targetLib.id,
453
- // saveOnly: true,
454
- // noOutput: true
455
- // }
456
- // }
457
- // // add targetid as state if exists
458
- // if (targetId) {
459
- // popupState[targetId] = targetCode;
460
- // }
461
- // that.optionPopup = new LibraryComponent(popupState,
462
- // {
463
- // pageThis: that,
464
- // useInputVariable: true,
465
- // targetSelector: that.pageThis.wrapSelector('#' + that.targetId),
466
-
467
- // finish: function(code) {
468
- // // TODO: save state
469
-
470
- // $(that.pageThis.wrapSelector('#' + that.targetId)).trigger({
471
- // type: "instance_editor_replaced",
472
- // originCode: that.state.code,
473
- // newCode: code
474
- // });
475
- // }
476
- // });
477
- // hasOption = true;
478
- // } else {
479
- // that.optionPopup = null;
480
- // }
481
509
482
510
// if bracket is at the end of code
483
511
var matchList = lastSplit . match ( / \( .* ?\) $ / gi) ;
@@ -487,110 +515,25 @@ define([
487
515
var parameter = lastBracket . substr ( 1 , lastBracket . length - 2 ) ;
488
516
$ ( that . wrapSelector ( '.' + VP_INS_PARAMETER ) ) . val ( parameter ) ;
489
517
$ ( that . wrapSelector ( '.' + VP_INS_PARAMETER ) ) . prop ( 'disabled' , false ) ;
490
- // if (hasOption) {
491
- // if ($(that.wrapSelector('.vp-ins-opt-button')).hasClass('disabled')) {
492
- // $(that.wrapSelector('.vp-ins-opt-button')).removeClass('disabled');
493
- // }
494
- // } else {
495
- // if (!$(that.wrapSelector('.vp-ins-opt-button')).hasClass('disabled')) {
496
- // $(that.wrapSelector('.vp-ins-opt-button')).addClass('disabled');
497
- // }
498
- // }
499
518
} else {
500
519
$ ( that . wrapSelector ( '.' + VP_INS_PARAMETER ) ) . val ( '' ) ;
501
520
$ ( that . wrapSelector ( '.' + VP_INS_PARAMETER ) ) . prop ( 'disabled' , true ) ;
502
- // if (!$(that.wrapSelector('.vp-ins-opt-button')).hasClass('disabled')) {
503
- // $(that.wrapSelector('.vp-ins-opt-button')).addClass('disabled');
504
- // }
505
521
}
506
522
} else {
507
523
$ ( that . wrapSelector ( '.' + VP_INS_PARAMETER ) ) . prop ( 'disabled' , true ) ;
508
- // if (!$(that.wrapSelector('.vp-ins-opt-button')).hasClass('disabled')) {
509
- // $(that.wrapSelector('.vp-ins-opt-button')).addClass('disabled');
510
- // }
511
524
}
512
525
}
513
-
514
- // callback
515
- if ( callback ) {
516
- callback ( varObj ) ;
517
- }
518
526
} ) . catch ( function ( resultObj ) {
519
527
let { result } = resultObj ;
520
528
// show alert if this is visible
521
529
if ( that . pageThis . isHidden ( ) == false && that . config . showAlert == true ) {
522
530
com_util . renderAlertModal ( result . ename + ': ' + result . evalue ) ;
523
531
}
524
- // hide
525
- if ( ! $ ( that . wrapSelector ( '.vp-ins-opt-button' ) ) . hasClass ( 'disabled' ) ) {
526
- $ ( that . wrapSelector ( '.vp-ins-opt-button' ) ) . addClass ( 'disabled' ) ;
527
- }
532
+ } ) . finally ( function ( ) {
528
533
// callback
529
534
if ( callback ) {
530
535
callback ( '' ) ;
531
536
}
532
- } ) . finally ( function ( ) {
533
-
534
- // get parameter
535
- var splitList = variable . split ( '.' ) ;
536
- var hasOption = false ;
537
-
538
- if ( splitList && splitList . length > 0 ) {
539
- var lastSplit = splitList [ splitList . length - 1 ] ;
540
- // get target code
541
- var methodName = lastSplit . match ( / [ a - z A - Z _ ] + / i) [ 0 ] ;
542
- var targetCode = splitList . slice ( 0 , splitList . length - 1 ) . join ( '.' ) ;
543
- if ( ( prevVarType in instanceLibrary . INSTANCE_MATCHING_LIBRARY ) && ( methodName in instanceLibrary . INSTANCE_MATCHING_LIBRARY [ prevVarType ] ) ) {
544
- // get target library
545
- var targetLib = instanceLibrary . INSTANCE_MATCHING_LIBRARY [ prevVarType ] [ methodName ] ;
546
- var targetId = targetLib . target ;
547
- var popupState = {
548
- config : {
549
- name : methodName , category : 'Instance' ,
550
- id : targetLib . id ,
551
- saveOnly : true ,
552
- noOutput : true
553
- }
554
- }
555
- // add targetid as state if exists
556
- if ( targetId ) {
557
- popupState [ targetId ] = targetCode ;
558
- }
559
- that . optionPopup = new LibraryComponent ( popupState ,
560
- {
561
- pageThis : that ,
562
- useInputVariable : true ,
563
- targetSelector : that . pageThis . wrapSelector ( '#' + that . targetId ) ,
564
-
565
- finish : function ( code ) {
566
- // TODO: save state
567
-
568
- $ ( that . pageThis . wrapSelector ( '#' + that . targetId ) ) . trigger ( {
569
- type : "instance_editor_replaced" ,
570
- originCode : that . state . code ,
571
- newCode : code
572
- } ) ;
573
- }
574
- } ) ;
575
- hasOption = true ;
576
- } else {
577
- that . optionPopup = null ;
578
- }
579
-
580
- if ( hasOption ) {
581
- if ( $ ( that . wrapSelector ( '.vp-ins-opt-button' ) ) . hasClass ( 'disabled' ) ) {
582
- $ ( that . wrapSelector ( '.vp-ins-opt-button' ) ) . removeClass ( 'disabled' ) ;
583
- }
584
- } else {
585
- if ( ! $ ( that . wrapSelector ( '.vp-ins-opt-button' ) ) . hasClass ( 'disabled' ) ) {
586
- $ ( that . wrapSelector ( '.vp-ins-opt-button' ) ) . addClass ( 'disabled' ) ;
587
- }
588
- }
589
- } else {
590
- if ( ! $ ( that . wrapSelector ( '.vp-ins-opt-button' ) ) . hasClass ( 'disabled' ) ) {
591
- $ ( that . wrapSelector ( '.vp-ins-opt-button' ) ) . addClass ( 'disabled' ) ;
592
- }
593
- }
594
537
} ) ;
595
538
596
539
0 commit comments