Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atto: support showing button by capability #356

Open
wants to merge 1 commit into
base: MOODLE_311_DEV
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@
$string['embedbuttontext'] = 'Embed';
$string['browse_and_embed'] = 'Browse and Embed';
$string['privacy:metadata'] = 'The atto_kalturamedia plugin does not store any personal data.';
$string['kalturamedia:view'] = 'Permission to use Embed Kaltura Media atto plugin';
5 changes: 4 additions & 1 deletion lib/editor/atto/plugins/kalturamedia/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ function atto_kalturamedia_params_for_js($elementid, $options, $fpoptions) {
if (!$context) {
$context = context_system::instance();
}


$active = has_capability('atto/kalturamedia:view', $context);

return array(
'active' => $active,
'contextid' => $context->id,
'kafuri' => local_kaltura_get_config()->kaf_uri
);
Expand Down
2 changes: 1 addition & 1 deletion lib/editor/atto/plugins/kalturamedia/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2021051701; // The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2021051702; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = 'Kaltura release 4.3.1';
$plugin->requires = 2018120300; // Requires this Moodle version.
$plugin->component = 'atto_kalturamedia'; // Full name of the plugin (used for diagnostics).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,155 +1,166 @@
YUI.add('moodle-atto_kalturamedia-button', function (Y, NAME) {

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/*
* @package atto_kalturamedia
* @copyright 2Kaltura
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

/**
* @module moodle-atto_kalturamedia-button
*/

/**
* Atto text editor kalturamedia plugin.
*
* @namespace M.atto_kalturamedia
* @class button
* @extends M.editor_atto.EditorPlugin
*/

var COMPONENTNAME = 'atto_kalturamedia',
CSS = {
URLINPUT: 'atto_kalturamedia_urlentry',
NAMEINPUT: 'atto_kalturamedia_nameentry'
},
SELECTORS = {
URLINPUT: '.' + CSS.URLINPUT,
NAMEINPUT: '.' + CSS.NAMEINPUT
};

Y.namespace('M.atto_kalturamedia').Button = Y.Base.create('button', Y.M.editor_atto.EditorPlugin, [], {
_currentSelection: null,
embedWindow: null,

initializer: function() {
this.addButton({
icon: 'icon',
iconComponent: COMPONENTNAME,
callback: this._kalturamedia
});
},
_kalturamedia: function() {
this._currentSelection = this.get('host').getSelection();
if (this._currentSelection === false) {
return;
}

var w = 1200;
var h = 700;
var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left;
var dualScreenTop = window.screenTop != undefined ? window.screenTop : screen.top;

var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;

var left = ((width / 2) - (w / 2)) + dualScreenLeft;
var top = ((height / 2) - (h / 2)) + dualScreenTop;
var newWindow = window.open(this._getIframeURL(), M.util.get_string("browse_and_embed", COMPONENTNAME), 'scrollbars=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);

window.buttonJs = this;

if (window.focus) {
newWindow.focus();
}

this.embedWindow = newWindow;
},

_getIframeURL: function() {

var args = Y.mix({
elementid: this.get('host').get('elementid'),
contextid: this.get('contextid'),
height: '600px',
width: '1112px'
},
this.get('area'));
return M.cfg.wwwroot + '/lib/editor/atto/plugins/kalturamedia/ltibrowse_container.php?' +
Y.QueryString.stringify(args);
},

_getCourseId: function() {
var courseId;
var bodyClasses = document.getElementsByTagName('body')[0].className;
var classes = bodyClasses.split(' ');
for(i in classes)
{
if(classes[i].indexOf('course-') > -1)
{
var parts = classes[i].split('-');
courseId = parts[1];
}
}

return courseId;
},

_removeProtocolFromUrl: function(fullUrl) {
return fullUrl.replace(/^https?:\/\//,'');
},

embedItem: function(what, data) {
var sourceUrl = data.url;
var url = this._removeProtocolFromUrl(sourceUrl);
var parser = document.createElement('a');
parser.href = sourceUrl;
url += parser.search;

var content = '<a href="http://'+url+'">tinymce-kalturamedia-embed||'+data.title+'||'+data.width+'||'+data.height+'</a>';

host = this.get('host');
host.setSelection(this._currentSelection);
host.insertContentAtFocusPoint(content);
this.markUpdated();
this.embedWindow.close();
}

} , {
ATTRS: {
/**
* The contextid to use when generating this preview.
*
* @attribute contextid
* @type String
*/
contextid: {
value: null
},

/**
* The KAF URI, as configured in Kaltura's plugin settings.
*/
kafuri: {
value: null
}
}}
);
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/*
* @package atto_kalturamedia
* @copyright 2Kaltura
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

/**
* @module moodle-atto_kalturamedia-button
*/

/**
* Atto text editor kalturamedia plugin.
*
* @namespace M.atto_kalturamedia
* @class button
* @extends M.editor_atto.EditorPlugin
*/

var COMPONENTNAME = 'atto_kalturamedia',
CSS = {
URLINPUT: 'atto_kalturamedia_urlentry',
NAMEINPUT: 'atto_kalturamedia_nameentry'
},
SELECTORS = {
URLINPUT: '.' + CSS.URLINPUT,
NAMEINPUT: '.' + CSS.NAMEINPUT
};

Y.namespace('M.atto_kalturamedia').Button = Y.Base.create('button', Y.M.editor_atto.EditorPlugin, [], {
_currentSelection: null,
embedWindow: null,

initializer: function() {
if (this.get('active')) {
this.addButton({
icon: 'icon',
iconComponent: COMPONENTNAME,
callback: this._kalturamedia
});
}
},
_kalturamedia: function() {
this._currentSelection = this.get('host').getSelection();
if (this._currentSelection === false) {
return;
}

var w = 1200;
var h = 700;
var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left;
var dualScreenTop = window.screenTop != undefined ? window.screenTop : screen.top;

var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;

var left = ((width / 2) - (w / 2)) + dualScreenLeft;
var top = ((height / 2) - (h / 2)) + dualScreenTop;
var newWindow = window.open(this._getIframeURL(), M.util.get_string("browse_and_embed", COMPONENTNAME), 'scrollbars=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);

window.buttonJs = this;

if (window.focus) {
newWindow.focus();
}

this.embedWindow = newWindow;
},

_getIframeURL: function() {

var args = Y.mix({
elementid: this.get('host').get('elementid'),
contextid: this.get('contextid'),
height: '600px',
width: '1112px'
},
this.get('area'));
return M.cfg.wwwroot + '/lib/editor/atto/plugins/kalturamedia/ltibrowse_container.php?' +
Y.QueryString.stringify(args);
},

_getCourseId: function() {
var courseId;
var bodyClasses = document.getElementsByTagName('body')[0].className;
var classes = bodyClasses.split(' ');
for(i in classes)
{
if(classes[i].indexOf('course-') > -1)
{
var parts = classes[i].split('-');
courseId = parts[1];
}
}

return courseId;
},

_removeProtocolFromUrl: function(fullUrl) {
return fullUrl.replace(/^https?:\/\//,'');
},

embedItem: function(what, data) {
var sourceUrl = data.url;
var url = this._removeProtocolFromUrl(sourceUrl);
var parser = document.createElement('a');
parser.href = sourceUrl;
url += parser.search;

var content = '<a href="http://'+url+'">tinymce-kalturamedia-embed||'+data.title+'||'+data.width+'||'+data.height+'</a>';

host = this.get('host');
host.setSelection(this._currentSelection);
host.insertContentAtFocusPoint(content);
this.markUpdated();
this.embedWindow.close();
}

} , {
ATTRS: {
/**
* Whether the button should be active.
*
* @attribute active
* @type Boolean
*/
active: {
value: false
},
/**
* The contextid to use when generating this preview.
*
* @attribute contextid
* @type String
*/
contextid: {
value: null
},

/**
* The KAF URI, as configured in Kaltura's plugin settings.
*/
kafuri: {
value: null
}
}}
);


}, '@VERSION@', {"requires": ["moodle-editor_atto-plugin"]});

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading