Joywork/js/ckeditor2/plugins/variablessob/dialogs/variablessob.js
2026-05-22 21:21:54 +03:00

110 lines
5.7 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
CKEDITOR.dialog.add( 'variablessob', function(editor) {
let validNameRegex = /^\$\{[a-zA-z0-9_.]+\}/;
let value = '';
return {
title: "Собственник",
minHeight: 60,
minWidth: 280,
contents: [
{
id: 'infosob',
label: "Собственник",
title: "Собственник",
elements: [
{
id: 'name',
type: 'select',
style: 'width: 100%;',
className: 'fastselect',
label: "Выберите переменную:",
multiple: true,
items: editor.config.customValues.variablesListSob,
'default': '',
// required: true,
//validate: CKEDITOR.dialog.validate.regex(validNameRegex, "Неверный формат переменной"),
setup: function(widget) {
//console.log(widget.data);
value = '';
this.setValue("${*" + widget.data.name + "*}");
},
onLoad: function(elem) {
value = '';
let select_id = '#' + this._.inputId;
let select = $(select_id).clone();
select.find('option').first().before('<option value="0">Не выбрано</option>');
$(select_id).closest('.cke_dialog_ui_labeled_content').html(select);
$(select_id).closest('.cke_dialog_container').removeClass('cke_reset_all');
$(select_id).closest('.cke_dialog_container').find('label[for="'+this._.inputId+'"]').remove();
$(select_id).fastselect({
placeholder: "Выберите поля собственника",
onItemSelect: function(item, model) {
console.log(item);
console.log(model);
if(value != ''){
value += ' ';
}
value += model.value;
},
});
$(select_id).closest(".fstElement").find(".fstControls input.hidenClass").attr('type', "text");
$(select_id).closest(".fstElement").find(".fstControls input.hidenClass").removeClass('hidenClass');
},
onShow: function(widget) {
value = '';
let select_id = '#' + this._.inputId;
let select = $(select_id).clone();
$(select_id).closest('.cke_dialog_ui_labeled_content').html(select);
$(select_id).closest('.cke_dialog_container').removeClass('cke_reset_all');
$(select_id).closest('.cke_dialog_container').find('label[for="'+this._.inputId+'"]').remove();
$(select_id).fastselect({
placeholder: "Выберите переменную",
onItemSelect: function(item, model) {
console.log(item);
console.log(model);
if(value != ''){
value += ' ';
}
value += model.value;
},
onItemDelete: function(model) {
// console.log('%'+model.value+'%');
value = value.replace(model.value,'');
value = value.replace(' ',' ');
console.log(value);
}
});
$(select_id).closest(".fstElement").find(".fstControls input.hidenClass").attr('type', "text");
$(select_id).closest(".fstElement").find(".fstControls input.hidenClass").removeClass('hidenClass');
},
commit: function(widget) {
let select_id = '#' + this._.inputId;
let vals = $(select_id).val();
//console.log($(select_id));
console.log(value);
/*let variable = '';
for(var i=0; i<vals.length; i++){
if(variable != '') variable +=' ';
variable +=vals[i].replace('${','%%').replace('}','%%');
}*/
//JSON.stringify($(select_id).val());
//variable = variable.replace("[", "");
//variable = variable.replace("]", "");
//console.log(variable);
widget.setData('name', value);
}
},
]
}
]
};
});