Commit beff568b authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review

Merge changes I63bbe8e2,Ie96a14e5

* changes:
  Enable Leap2A import/export license info for text boxes
  Update license info when using content from other text boxes
parents e79ffeeb 7cb86d79
......@@ -101,12 +101,21 @@ class PluginBlocktypeTextbox extends PluginBlocktype {
'selectjscallback' => 'updateTextContent',
'getblocks' => true,
'ownerinfo' => true,
'returnfields' => array('id', 'title', 'description', 'safedescription', 'editable'),
'returnfields' => array('id', 'title', 'description', 'license', 'licensor', 'licensorurl', 'safedescription', 'safelicense', 'editable'),
'artefacttypes' => array('html'),
'template' => 'artefact:internal:html-artefactchooser-element.tpl',
);
}
public static function artefactchooser_get_element_data($artefact) {
require_once('license.php');
$artefactobj = artefact_instance_from_id($artefact->id);
$artefact->safelicense = render_license($artefactobj);
return $artefact;
}
public static function get_instance_config_javascript($instance) {
// When an artefact is selected in the artefactchooser, update the
// contents of the wysiwyg editor and the message about the number
......@@ -116,12 +125,24 @@ class PluginBlocktypeTextbox extends PluginBlocktype {
function updateTextContent(a) {
setNodeAttribute('instconf_title', 'value', a.title);
tinyMCE.activeEditor.setContent(a.description);
setNodeAttribute('instconf_license', 'value', a.license);
setNodeAttribute('instconf_licensor', 'value', a.licensor);
setNodeAttribute('instconf_licensorurl', 'value', a.licensorurl);
$('instconf_textreadonly_display').innerHTML = a.safedescription;
$('instconf_licensereadonly_display').innerHTML = a.safelicense;
$('instconf_makecopy').checked = false;
if (a.editable == 1) {
addElementClass('instconf_textreadonly_header', 'hidden');
addElementClass('instconf_textreadonly_container', 'hidden');
addElementClass('instconf_readonlymsg_container', 'hidden');
addElementClass('instconf_licensereadonly_header', 'hidden');
addElementClass('instconf_licensereadonly_container', 'hidden');
removeElementClass('instconf_text_header', 'hidden');
removeElementClass('instconf_text_container', 'hidden');
removeElementClass('instconf_license_header', 'hidden');
removeElementClass('instconf_license_container', 'hidden');
removeElementClass('instconf_license_description', 'hidden');
removeElementClass('instconf_license_advanced_fieldset', 'hidden');
var blockcountmsg = $('instconf_otherblocksmsg_container');
if (blockcountmsg && $('textbox_blockcount')) {
var otherblockcount = 0;
......@@ -142,10 +163,21 @@ function updateTextContent(a) {
}
}
else {
addElementClass('instconf_text_header', 'hidden');
addElementClass('instconf_text_container', 'hidden');
addElementClass('instconf_otherblocksmsg_container', 'hidden');
addElementClass('instconf_license_header', 'hidden');
addElementClass('instconf_license_container', 'hidden');
addElementClass('instconf_license_description', 'hidden');
addElementClass('instconf_license_advanced_fieldset', 'hidden');
removeElementClass('instconf_textreadonly_header', 'hidden');
removeElementClass('instconf_textreadonly_container', 'hidden');
removeElementClass('instconf_readonlymsg_container', 'hidden');
removeElementClass('instconf_licensereadonly_header', 'hidden');
removeElementClass('instconf_licensereadonly_container', 'hidden');
}
if (table = getFirstParentByTagAndClassName($('instconf_text_container'), 'table', 'maharatable')) {
update_width(getFirstParentByTagAndClassName(table, 'div', 'blockinstance'), getElementDimensions(table).w);
}
}
connect('chooseartefactlink', 'onclick', function(e) {
......@@ -162,12 +194,22 @@ forEach(getElementsByTagAndClassName('a', 'copytextboxnote', 'instconf'), functi
}
});
$('instconf_makecopy').checked = true;
addElementClass('instconf_textreadonly_header', 'hidden');
addElementClass('instconf_textreadonly_container', 'hidden');
addElementClass('instconf_readonlymsg_container', 'hidden');
addElementClass('instconf_otherblocksmsg_container', 'hidden');
addElementClass('instconf_licensereadonly_header', 'hidden');
addElementClass('instconf_licensereadonly_container', 'hidden');
removeElementClass('instconf_text_header', 'hidden');
removeElementClass('instconf_text_container', 'hidden');
removeElementClass('instconf_license_header', 'hidden');
removeElementClass('instconf_license_container', 'hidden');
removeElementClass('instconf_license_description', 'hidden');
removeElementClass('instconf_license_advanced_fieldset', 'hidden');
});
});
removeElementClass('instconf_license', 'hidden');
removeElementClass(getFirstElementByTagAndClassName('fieldset', null, 'instconf_license_advanced_fieldset'), 'hidden');
EOF;
}
......@@ -253,9 +295,19 @@ EOF;
'textreadonly' => array(
'type' => 'html',
'class' => $readonly ? '' : 'hidden',
'title' => get_string('blockcontent', 'blocktype.internal/textbox'),
'width' => '100%',
'value' => '<div id="instconf_textreadonly_display">' . $text . '</div>',
),
'license' => license_form_el_basic(isset($artefact) ? $artefact : null),
'license_advanced' => license_form_el_advanced(isset($artefact) ? $artefact : null),
'licensereadonly' => array(
'type' => 'html',
'class' => $readonly ? '' : 'hidden',
'width' => '100%',
'title' => get_string('license'),
'value' => '<div id="instconf_licensereadonly_display">' . (isset($artefact) ? render_license($artefact) : get_string('licensenone')) . '</div>',
),
'makecopy' => array(
'type' => 'checkbox',
'class' => 'hidden',
......@@ -276,17 +328,8 @@ EOF;
),
);
if ($readonly) {
if ($license = render_license(isset($artefact) ? $artefact : null)) {
$elements['license'] = array(
'type' => 'html',
'title' => get_string('license'),
'value' => $license,
);
}
}
else {
$elements['license'] = license_form_el_basic(isset($artefact) ? $artefact : null);
$elements['license_advanced'] = license_form_el_advanced(isset($artefact) ? $artefact : null);
$elements['license']['class'] = 'hidden';
$elements['license_advanced']['class'] = 'hidden';
}
return $elements;
}
......@@ -392,6 +435,9 @@ EOF;
$data = array(
'title' => $biconfig['title'],
'description' => $configdata['text'],
'license' => $configdata['license'],
'licensor' => $configdata['licensor'],
'licensorurl' => $configdata['licensorurl'],
'owner' => $viewconfig['owner'],
);
$artefact = new ArtefactTypeHtml(0, $data);
......@@ -423,13 +469,23 @@ EOF;
$result = array();
$text = '';
$license = '';
$licensor = '';
$licensorurl = '';
if (!empty($configdata['artefactid'])) {
$result['artefactid'] = json_encode(array($configdata['artefactid']));
$text = $bi->get_artefact_instance($configdata['artefactid'])->get('description');
$note = $bi->get_artefact_instance($configdata['artefactid']);
$text = $note->get('description');
$license = $note->get('license');
$licensor = $note->get('licensor');
$licensorurl = $note->get('licensorurl');
}
$result['text'] = json_encode(array($text));
$result['license '] = json_encode(array($license));
$result['licensor'] = json_encode(array($licensor));
$result['licensorurl'] = json_encode(array($licensorurl));
return $result;
}
......
......@@ -53,18 +53,22 @@ function pieform_renderer_maharatable(Pieform $form, $element) {
}
$builtelement = substr($builtelement, 0, -12) . '</table></fieldset>';
$result = "\t<tr>\n\t\t<td colspan=\"2\">";
$result = "\t<tr id=\"{$formname}_{$element['name']}_fieldset\"";
if (isset($element['class'])) {
$result .= ' class="' . Pieform::hsc($element['class']) . '"';
}
$result .= ">\n\t\t<td colspan=\"2\">";
$result .= $builtelement;
$result .= "</td>\n\t</tr>";
return $result;
}
$result = '';
if (isset($element['labelhtml']) && $element['labelhtml'] !== '') {
$result .= "\t<tr";
$result .= ' id="' . $formname . '_' . Pieform::hsc($element['name']) . '_header"';
// Set the class of the enclosing <tr> to match that of the element
if ($element['class']) {
if (isset($element['class'])) {
$result .= ' class="' . Pieform::hsc($element['class']) . '"';
}
$result .= ">\n\t\t";
......@@ -93,8 +97,8 @@ function pieform_renderer_maharatable(Pieform $form, $element) {
// Contextual help
if (!empty($element['help'])) {
$result .= get_help_icon($form->get_property('plugintype'),
$form->get_property('pluginname'),
$result .= get_help_icon($form->get_property('plugintype'),
$form->get_property('pluginname'),
$form->get_name(), $element['name']);
if ($element['type'] == 'wysiwyg') {
$result .= '</td></tr></table>';
......@@ -104,9 +108,13 @@ function pieform_renderer_maharatable(Pieform $form, $element) {
$result .= "</td>\n\t</tr>\n";
// Description - optional description of the element, or other note that should be visible
// on the form itself (without the user having to hover over contextual help
// on the form itself (without the user having to hover over contextual help
if ((!$form->has_errors() || $form->get_property('showdescriptiononerror')) && !empty($element['description'])) {
$result .= "\t<tr>\n\t\t<td class=\"description\">";
$result .= "\t<tr id=\"{$formname}_{$element['name']}_description\"";
if (isset($element['class'])) {
$result .= ' class="' . Pieform::hsc($element['class']) . '"';
}
$result .= ">\n\t\t<td class=\"description\">";
$result .= $element['description'];
$result .= "</td>\n\t</tr>\n";
}
......
......@@ -263,6 +263,9 @@ function license_form_files($prefix, $prefix2=null) {
* Given an artefact object, render the license information.
*/
function render_license($artefact) {
if (!$artefact || !($artefact instanceof ArtefactType)) {
throw new MaharaException('The object ' . $artefact . 'is NOT an artefact');
}
$license = $artefact->get('license');
$licensor = $artefact->get('licensor');
$licensorurl = $artefact->get('licensorurl');
......@@ -270,6 +273,9 @@ function render_license($artefact) {
if ($license) {
$details = get_record('artefact_license', 'name', $license);
}
else {
return get_string('licensenone');
}
if (strpos($license, '://') === FALSE) {
$license = 'http://' . $license;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment