Skip to content

Commit 2607504

Browse files
author
minjk-bl
committed
Add radio and load state module
1 parent 6181e4d commit 2607504

File tree

1 file changed

+45
-5
lines changed

1 file changed

+45
-5
lines changed

visualpython/js/com/component/PopupComponent.js

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ define([
314314
});
315315
// Toggle operation (minimize)
316316
$(this.wrapSelector('.vp-popup-toggle')).on('click', function(evt) {
317+
evt.stopPropagation();
317318
$(that.eventTarget).trigger({
318319
type: 'close_option_page',
319320
component: that
@@ -711,7 +712,37 @@ define([
711712
}
712713

713714
loadState() {
714-
/** Implementation needed */
715+
vpLog.display(VP_LOG_TYPE.DEVELOP, this.state);
716+
717+
let that = this;
718+
Object.keys(this.state).forEach(key => {
719+
if (key && key !== '' && key !== 'config') {
720+
let tag = $(that.wrapSelector('#' + key) + ', ' + that.wrapSelector('input[name="' + key + '"]'));
721+
let tagName = $(tag).prop('tagName');
722+
let savedValue = that.state[key];
723+
switch(tagName) {
724+
case 'INPUT':
725+
let inputType = $(tag).prop('type');
726+
if (inputType === 'text' || inputType === 'number' || inputType === 'hidden') {
727+
$(tag).val(savedValue);
728+
break;
729+
}
730+
if (inputType === 'checkbox') {
731+
$(tag).prop('checked', savedValue);
732+
break;
733+
}
734+
if (inputType === 'radio') {
735+
$(tag).filter(`[value="${savedValue}"]`).prop('checked', true);
736+
}
737+
break;
738+
case 'TEXTAREA':
739+
case 'SELECT':
740+
default:
741+
$(tag).val(savedValue);
742+
break;
743+
}
744+
}
745+
});
715746
}
716747

717748
saveState() {
@@ -733,6 +764,15 @@ define([
733764
let inputType = $(tag).prop('type');
734765
if (inputType == 'checkbox') {
735766
newValue = $(tag).prop('checked');
767+
} else if (inputType == 'radio') {
768+
let radioGroup = $(tag).prop('name');
769+
let checked = $(tag).prop('checked');
770+
if (checked === true) {
771+
id = radioGroup;
772+
newValue = $(tag).val();
773+
} else {
774+
return ;
775+
}
736776
} else {
737777
// inputType == 'text' || inputType == 'number' || inputType == 'hidden' || inputType == 'color' || inputType == 'range'
738778
newValue = $(tag).val();
@@ -787,7 +827,7 @@ define([
787827
*/
788828
checkRequiredOption() {
789829
let requiredFilled = true;
790-
let requiredTags = $(this.wrapSelector('input[required=true]') + ',' + this.wrapSelector('input[required=required]'));
830+
let requiredTags = $(this.wrapSelector('input[required=true]:visible') + ',' + this.wrapSelector('input[required=required]:visible'));
791831

792832
vpLog.display(VP_LOG_TYPE.DEVELOP, 'checkRequiredOption', this, requiredTags);
793833

@@ -819,9 +859,9 @@ define([
819859
let checkedList = JSON.parse(result);
820860
let executeList = [];
821861
checkedList && checkedList.forEach((mod, idx) => {
822-
if (mod == false) {
862+
if (mod === false) {
823863
let modInfo = vpConfig.getModuleCode(checkModules[idx]);
824-
if (modInfo) {
864+
if (modInfo && modInfo?.code !== '') {
825865
executeList.push(modInfo.code);
826866
}
827867
}
@@ -915,7 +955,7 @@ define([
915955
save() {
916956
if (this.prop.finish && typeof this.prop.finish == 'function') {
917957
var code = this.generateCode();
918-
this.prop.finish(code);
958+
this.prop.finish(code, this.state);
919959
}
920960
$(this.eventTarget).trigger({
921961
type: 'apply_option_page',

0 commit comments

Comments
 (0)