')
if (l.label) {
bar.append('')
max_label_width = Math.max(getStringWidth(tl(l.label)), max_label_width)
}
if (l.node) {
bar.append(l.node)
} else if (l.widget) {
var widget = l.widget
if (typeof l.widget === 'string') {
widget = BarItems[l.widget]
} else if (typeof l.widget === 'function') {
widget = l.widget()
}
bar.append(widget.getNode())
max_label_width = Math.max(getStringWidth(widget.name), max_label_width)
}
jq_dialog.append(bar)
} else {
jq_dialog.append(l)
}
})
}
if (scope.form) {
for (var form_id in scope.form) {
var data = scope.form[form_id]
if (data === '_') {
jq_dialog.append('')
} else if (data && Condition(data.condition)) {
var bar = $(``)
if (data.label) {
bar.append(``)
max_label_width = Math.max(getStringWidth(tl(data.label)), max_label_width)
}
switch (data.type) {
default:
bar.append(``)
if (data.list) {
let id = `${scope.id}_${form_id}_list`
let list = $(``)
for (let value of data.list) {
list.append(``)
}
bar.append(el)
break;
case 'radio':
var el = $(``)
for (var key in data.options) {
var name = tl(data.options[key])
el.append(`
`)
}
bar.append(el)
break;
case 'text':
data.text = marked(tl(data.text))
bar.append(`
${data.text}
`)
bar.addClass('small_text')
break;
case 'number':
bar.append(``)
break;
case 'color':
if (!data.colorpicker) {
data.colorpicker = new ColorPicker({
id: 'cp_'+form_id,
name: tl(data.label),
label: false,
private: true
})
}
bar.append(data.colorpicker.getNode())
break;
case 'checkbox':
bar.append(``)
break;
case 'file':
case 'folder':
case 'save':
if (data.type == 'folder' && !isApp) break;
var input = $(``);
bar.append(input);
bar.addClass('form_bar_file');
switch (data.type) {
case 'file': bar.append('insert_drive_file'); break;
case 'folder': bar.append('folder'); break;
case 'save': bar.append('save'); break;
}
let remove_button = $('
clear
');
bar.append(remove_button);
remove_button.on('click', e => {
e.stopPropagation();
data.value = '';
input.val('');
})
bar.on('click', e => {
function fileCB(files) {
data.value = files[0].path;
input.val(data.value);
}
switch (data.type) {
case 'file':
Blockbench.import({
extensions: data.extensions,
type: data.filetype,
startpath: data.value
}, fileCB);
break;
case 'folder':
ElecDialogs.showOpenDialog(currentwindow, {
properties: ['openDirectory'],
defaultPath: data.value
}, function(filePaths) {
if (filePaths) fileCB([{ path: filePaths[0] }]);
})
break;
case 'save':
Blockbench.export({
extensions: data.extensions,
type: data.filetype,
startpath: data.value,
custom_writer: () => {},
}, fileCB);
break;
}
})
case 'folder':
}
if (data.readonly) {
bar.find('input').attr('readonly', 'readonly').removeClass('focusable_input')
}
jq_dialog.append(bar)
}
}
}
if (max_label_width) {
document.styleSheets[0].insertRule('.dialog#'+this.id+' .dialog_bar label {width: '+(max_label_width+8)+'px}')
}
if (this.buttons) {
var buttons = []
scope.buttons.forEach(function(b, i) {
var btn = $(' ')
buttons.push(btn)
})
buttons[scope.confirmIndex] && buttons[scope.confirmIndex].addClass('confirm_btn')
buttons[scope.cancelIndex] && buttons[scope.cancelIndex].addClass('cancel_btn')
jq_dialog.append($('').append(buttons))
} else if (this.singleButton) {
jq_dialog.append('
' +
'' +
'
')
} else {
jq_dialog.append(`
`)
}
jq_dialog.append('
clear
')
var confirmFn = function(e) {
var result = {}
if (scope.form) {
for (var form_id in scope.form) {
var data = scope.form[form_id]
if (typeof data === 'object') {
switch (data.type) {
default:
result[form_id] = jq_dialog.find('input#'+form_id).val()
break;
case 'text':
break;
case 'textarea':
result[form_id] = jq_dialog.find('textarea#'+form_id).val()
break;
case 'select':
result[form_id] = jq_dialog.find('select#'+form_id+' > option:selected').attr('id')
break;
case 'radio':
result[form_id] = jq_dialog.find('.form_part_radio#'+form_id+' input:checked').attr('id')
break;
case 'number':
result[form_id] = Math.clamp(parseFloat(jq_dialog.find('input#'+form_id).val())||0, data.min, data.max)
break;
case 'color':
result[form_id] = data.colorpicker.get();
break;
case 'checkbox':
result[form_id] = jq_dialog.find('input#'+form_id).is(':checked')
break;
}
}
}
}
scope.onConfirm(result, e)
}
confirmFn.bind(this)
if (this.confirmEnabled) $(this.object).find('.confirm_btn').click(confirmFn)
if (this.cancelEnabled) $(this.object).find('.cancel_btn').click(() => {this.onCancel()})
//Draggable
if (this.draggable !== false) {
jq_dialog.addClass('draggable')
jq_dialog.draggable({
handle: ".dialog_handle",
containment: '#page_wrapper'
})
var x = Math.clamp(($(window).width()-540)/2, 0, 2000)
jq_dialog.css('left', x+'px')
jq_dialog.css('position', 'absolute')
}
$('#plugin_dialog_wrapper').append(jq_dialog)
$('.dialog').hide(0)
$('#blackout').fadeIn(scope.fadeTime)
jq_dialog.fadeIn(scope.fadeTime)
jq_dialog.css('top', limitNumber($(window).height()/2-jq_dialog.height()/2, 0, 100)+'px')
if (this.width) {
jq_dialog.css('width', this.width+'px')
}
let first_focus = jq_dialog.find('.focusable_input').first()
if (first_focus) first_focus.focus()
open_dialog = scope.id
open_interface = scope
Prop.active_panel = 'dialog'
return this;
}
this.getFormBar = function(form_id) {
var bar = $(scope.object).find(`.form_bar_${form_id}`)
if (bar) return bar;
}
}