Skip to content

Commit

Permalink
Merge branch 'release-30.21.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Sep 2, 2024
2 parents 8b7f908 + 76f7844 commit 43aa7fd
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 43 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"oat-sa/oatbox-extension-installer": "~1.1||dev-master",
"naneau/semver": "~0.0.7",
"oat-sa/generis": ">=15.36.4",
"oat-sa/tao-core": ">=54.14.7",
"oat-sa/tao-core": ">=54.22.0",
"oat-sa/extension-tao-item": ">=12.0.0",
"oat-sa/extension-tao-test": ">=16.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion views/js/loader/taoQtiItem.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion views/js/loader/taoQtiItem.min.js.map

Large diffs are not rendered by default.

83 changes: 45 additions & 38 deletions views/js/qtiCreator/editor/styleEditor/styleSheetToggler.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,20 @@
*/
define([
'jquery',
'taoQtiItem/qtiCreator/editor/styleEditor/styleEditor',
'i18n',
'lodash',
'i18n',
'taoQtiItem/qtiCreator/editor/styleEditor/styleEditor',
'taoQtiItem/qtiCreator/model/Stylesheet',
'tpl!taoQtiItem/qtiCreator/tpl/notifications/genericFeedbackPopup',
'ui/dialog/confirm',
'ui/resourcemgr'
], function ($, styleEditor, __, _, Stylesheet, genericFeedbackPopup) {
], function ($, _, __, styleEditor, Stylesheet, genericFeedbackPopup, confirmDialog) {
'use strict';

var $doc = $(document);

var styleSheetToggler = (function () {

var init = function (itemConfig) {

const _createInfoBox = function (data) {
var $messageBox = $(genericFeedbackPopup(data)),
closeTrigger = $messageBox.find('.close-trigger');
Expand Down Expand Up @@ -75,13 +74,10 @@ define([
};
};



/**
* Upload custom stylesheets
*/
uploader.on('click', function () {

uploader.resourcemgr({
className: 'stylesheets',
appendContainer: '#mediaManager',
Expand All @@ -99,56 +95,70 @@ define([
},
pathParam: 'path',
select(e, files) {
var i, l = files.length;
for (i = 0; i < l; i++) {
const l = files.length;
for (let i = 0; i < l; i++) {
styleEditor.addStylesheet(files[i].file);
}
},
close() {
$('#mediaManager').off('filedelete.resourcemgr');
}
});

// watch for file deletion inside the media manager that are related to a linked stylesheet
$('#mediaManager').on('filedelete.resourcemgr', (e, file) => {
const filePath = [file]
if (file.startsWith('/')) {
filePath.push(file.substring(1));
}

const $style = cssToggler.find(filePath.map(path => `[data-css-res="${path}"]`).join(', '));
if ($style.length) {
deleteStylesheet($style);
hooks: {
deleteFile(file) {
const filePath = [file];
if (file.startsWith('/')) {
filePath.push(file.substring(1));
}

const $style = cssToggler.find(filePath.map(path => `[data-css-res="${path}"]`).join(', '));
if ($style.length) {
return new Promise((resolve, reject) => {
confirmDialog(
__(
'As this stylesheet is attached to the item, the item will be automatically saved after the deletion, continue?'
),
() => {
$('#mediaManager').one('filedelete.resourcemgr', () => {
deleteStylesheet($style);

$('#item-editor-panel')
.trigger('beforesave.qti-creator')
.trigger('save.qti-creator');
});
resolve();
},
reject
);
});
}
}
}
});
});


/**
* Confirm to save the item
* @param {Object} trigger
*/
const deleteStylesheet = function(trigger) {
const deleteStylesheet = function (trigger) {
var context = getContext(trigger),
attr = context.isDisabled ? 'disabled-href' : 'href',
cssLinks = $('head link');


styleEditor.getItem().removeStyleSheet(context.stylesheetObj);

cssLinks.filter(`[${attr}*="${context.cssUri}"]`).remove();
context.li.remove();

$('.feedback-info').hide();
_createInfoBox({
message: __('Style Sheet <b>%s</b> removed<br> Click <i>Add Style Sheet</i> to re-apply.').replace('%s', context.label),
message: __('Style Sheet <b>%s</b> removed<br> Click <i>Add Style Sheet</i> to re-apply.').replace(
'%s',
context.label
),
type: 'info'
});

$doc.trigger('customcssloaded.styleeditor', [styleEditor.getStyle()]);
};


/**
* Modify stylesheet title (enable)
* @param {Object} trigger
Expand All @@ -164,7 +174,7 @@ define([
*
* @param {Object} trigger
*/
const downloadStylesheet = function(trigger) {
const downloadStylesheet = function (trigger) {
styleEditor.download(getContext(trigger).cssUri);
};

Expand Down Expand Up @@ -205,7 +215,9 @@ define([
}
} else {
// all other styles are handled via their link element
const linkDom = Object.values(document.styleSheets).find(sheet => typeof sheet.href === 'string' && sheet.href.includes(context.label));
const linkDom = Object.values(document.styleSheets).find(
sheet => typeof sheet.href === 'string' && sheet.href.includes(context.label)
);
if (context.isDisabled) {
linkDom.disabled = false;
} else {
Expand All @@ -231,12 +243,11 @@ define([
initLabelEditor(e.target);
} else if (className.indexOf('icon-preview') > -1) {
handleAvailability(e.target);
} else if(className.indexOf('icon-download') > -1) {
} else if (className.indexOf('icon-download') > -1) {
downloadStylesheet(e.target);
}
});


/**
* Handle renaming on enter
*/
Expand All @@ -252,16 +263,12 @@ define([
cssToggler.on('blur', 'input', function (e) {
saveLabel(e.target);
});


};

return {
init: init
};

})();

return styleSheetToggler;
});

9 changes: 7 additions & 2 deletions views/js/qtiCreator/itemCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,12 @@ define([
.then(() => styleEditor.save())
.then(() => itemWidget.save())
.then(() => {
if (!silent){
if (!silent) {
self.trigger('success', __('Your item has been saved'));
}
self.trigger('saved');
}).catch(err => {
})
.catch(err => {
self.trigger('error', err);
});
});
Expand Down Expand Up @@ -351,6 +352,9 @@ define([
// pass an context reference to the renderer
config.qtiCreatorContext = qtiCreatorContext;

// listen to save requests from the DOM components (like the style editor)
areaBroker.getContentCreatorPanelArea().on('save.qti-creator', () => this.trigger('save'));

creatorRenderer
.get(true, config, areaBroker)
.setOptions(config.properties)
Expand Down Expand Up @@ -404,6 +408,7 @@ define([
pluginRun('destroy')
.then(() => qtiCreatorContext.destroy())
.then(() => {
areaBroker.getContentCreatorPanelArea().off('.qti-creator');
this.trigger('destroy');
})
.catch(err => {
Expand Down

0 comments on commit 43aa7fd

Please sign in to comment.