- var imglist = modal.find('.modal-body');
- $.each(self.doc.galleryImages, (i, imgItem) => {
- img = $("<img>").attr("src", imgItem.thumb).attr('title', imgItem.url).data('url', imgItem.url).on('click', function() {
- imglist.find('img').removeClass('active');
- $(this).addClass('active');
+ let body = modal.find('.modal-body');
+ body.html('');
+
+ let add_options = function(cnt, options, value) {
+ $.each(options, (i, item) => {
+ let elem = $('<div class="form-check"><label class="form-check-label"><input class="form-check-input" type="radio" name="metachoose"><div class="value"></div><div class="name"></div><div class="description"></div></label></div>');
+ if (!item.usable) {
+ $('input', elem).remove();
+ }
+ if (item.hidden) {
+ $('input', elem).prop('disabled', 'disabled');
+ }
+ $('input', elem).val(item.value);
+ $('input', elem).val(item.value);
+ $('.value', elem).text(item.value);
+ $('.name', elem).append(item.name);
+ $('.description', elem).append(item.description);
+ let valueMatch = value && value.startsWith(item.value);
+ if (valueMatch) {
+ $('label', elem).addClass('text-primary')
+ if (value == item.value) {
+ $('input', elem).prop('checked', true);
+ }
+ }
+ if (item.sub) {
+ let subT = $('<div class="meta-chooser_toggle">+</div>');
+ let sub = $('<div>');
+ elem.append(subT);
+ elem.append(sub);
+ subT.on('click', () => {
+ sub.toggle()
+ });
+ add_options(sub, item.sub, valueMatch ? value : null);
+ }
+ elem.appendTo(cnt);