Commit 0d8c1289 authored by Son Nguyen's avatar Son Nguyen Committed by Son Nguyen

Add tagging feature for text box (Bug #1180997)

Change-Id: I3e40bb71d1ac8e8956bee84b833989638756b6e2
parent dc709740
......@@ -101,7 +101,7 @@ class PluginBlocktypeTextbox extends PluginBlocktype {
'selectjscallback' => 'updateTextContent',
'getblocks' => true,
'ownerinfo' => true,
'returnfields' => array('id', 'title', 'description', 'license', 'licensor', 'licensorurl', 'safedescription', 'safelicense', 'editable'),
'returnfields' => array('id', 'title', 'description', 'tags', 'license', 'licensor', 'licensorurl', 'safedescription', 'safetags', 'safelicense', 'editable'),
'artefacttypes' => array('html'),
'template' => 'artefact:internal:html-artefactchooser-element.tpl',
);
......@@ -112,6 +112,8 @@ class PluginBlocktypeTextbox extends PluginBlocktype {
require_once('license.php');
$artefactobj = artefact_instance_from_id($artefact->id);
$artefact->safelicense = render_license($artefactobj);
$artefact->tags = ArtefactType::artefact_get_tags($artefact->id);
$artefact->safetags = is_array($artefact->tags) ? hsc(join(', ', $artefact->tags)) : '';
return $artefact;
}
......@@ -130,6 +132,9 @@ function updateTextContent(a) {
setNodeAttribute('instconf_licensorurl', 'value', a.licensorurl);
$('instconf_textreadonly_display').innerHTML = a.safedescription;
$('instconf_licensereadonly_display').innerHTML = a.safelicense;
setNodeAttribute('instconf_tags', 'value', a.tags);
$('instconf_textreadonly_display').innerHTML = a.safedescription;
$('instconf_tagsreadonly_display').innerHTML = a.safetags;
$('instconf_makecopy').checked = false;
if (a.editable == 1) {
addElementClass('instconf_textreadonly_header', 'hidden');
......@@ -137,12 +142,17 @@ function updateTextContent(a) {
addElementClass('instconf_readonlymsg_container', 'hidden');
addElementClass('instconf_licensereadonly_header', 'hidden');
addElementClass('instconf_licensereadonly_container', 'hidden');
addElementClass('instconf_tagsreadonly_header', 'hidden');
addElementClass('instconf_tagsreadonly_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_tags_header', 'hidden');
removeElementClass('instconf_tags_container', 'hidden');
removeElementClass('instconf_tags_description', 'hidden');
var blockcountmsg = $('instconf_otherblocksmsg_container');
if (blockcountmsg && $('textbox_blockcount')) {
var otherblockcount = 0;
......@@ -170,11 +180,16 @@ function updateTextContent(a) {
addElementClass('instconf_license_container', 'hidden');
addElementClass('instconf_license_description', 'hidden');
addElementClass('instconf_license_advanced_fieldset', 'hidden');
addElementClass('instconf_tags_header', 'hidden');
addElementClass('instconf_tags_container', 'hidden');
addElementClass('instconf_tags_description', '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');
removeElementClass('instconf_tagsreadonly_header', 'hidden');
removeElementClass('instconf_tagsreadonly_container', 'hidden');
}
if (table = getFirstParentByTagAndClassName($('instconf_text_container'), 'table', 'maharatable')) {
update_width(getFirstParentByTagAndClassName(table, 'div', 'blockinstance'), getElementDimensions(table).w);
......@@ -200,14 +215,20 @@ forEach(getElementsByTagAndClassName('a', 'copytextboxnote', 'instconf'), functi
addElementClass('instconf_otherblocksmsg_container', 'hidden');
addElementClass('instconf_licensereadonly_header', 'hidden');
addElementClass('instconf_licensereadonly_container', 'hidden');
addElementClass('instconf_tagsreadonly_header', 'hidden');
addElementClass('instconf_tagsreadonly_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_tags_header', 'hidden');
removeElementClass('instconf_tags_container', 'hidden');
removeElementClass('instconf_tags_description', 'hidden');
});
});
augment_tags_control('instconf_tags');
removeElementClass('instconf_license', 'hidden');
removeElementClass(getFirstElementByTagAndClassName('fieldset', null, 'instconf_license_advanced_fieldset'), 'hidden');
EOF;
......@@ -230,6 +251,7 @@ EOF;
$otherblockcount = 0;
$readonly = false;
$text = '';
$tags = '';
$view = $instance->get_view();
if (!empty($configdata['artefactid'])) {
......@@ -244,6 +266,7 @@ EOF;
|| !$USER->can_edit_artefact($artefact);
$text = $artefact->get('description');
$tags = $artefact->get('tags');
if ($blocks = get_column('view_artefact', 'block', 'artefact', $artefactid)) {
$blocks = array_unique($blocks);
......@@ -292,6 +315,13 @@ EOF;
'defaultvalue' => $text,
'rules' => array('maxlength' => 65536),
),
'tags' => array(
'type' => 'tags',
'class' => $readonly ? 'hidden' : '',
'title' => get_string('tags'),
'description' => get_string('tagsdescprofile'),
'defaultvalue' => $tags,
),
'textreadonly' => array(
'type' => 'html',
'class' => $readonly ? '' : 'hidden',
......@@ -299,6 +329,21 @@ EOF;
'width' => '100%',
'value' => '<div id="instconf_textreadonly_display">' . $text . '</div>',
),
'tags' => array(
'type' => 'tags',
'class' => $readonly ? 'hidden' : '',
'width' => '100%',
'title' => get_string('tags'),
'description' => get_string('tagsdescprofile'),
'defaultvalue' => $tags,
),
'tagsreadonly' => array(
'type' => 'html',
'class' => $readonly ? '' : 'hidden',
'width' => '100%',
'title' => get_string('tags'),
'value' => '<div id="instconf_tagsreadonly_display">' . (is_array($tags) ? hsc(join(', ', $tags)) : '') . '</div>',
),
'license' => license_form_el_basic(isset($artefact) ? $artefact : null),
'license_advanced' => license_form_el_advanced(isset($artefact) ? $artefact : null),
'licensereadonly' => array(
......@@ -364,6 +409,7 @@ EOF;
$artefact->set('licensor', $values['licensor']);
$artefact->set('licensorurl', $values['licensorurl']);
}
$artefact->set('tags', $values['tags']);
}
else {
$artefact = new ArtefactTypeHtml((int)$values['artefactid']);
......@@ -388,6 +434,7 @@ EOF;
$artefact->set('licensor', $values['licensor']);
$artefact->set('licensorurl', $values['licensorurl']);
}
$artefact->set('tags', $values['tags']);
}
}
......@@ -438,6 +485,7 @@ EOF;
'license' => $configdata['license'],
'licensor' => $configdata['licensor'],
'licensorurl' => $configdata['licensorurl'],
'tags' => $configdata['tags'],
'owner' => $viewconfig['owner'],
);
$artefact = new ArtefactTypeHtml(0, $data);
......@@ -472,17 +520,20 @@ EOF;
$license = '';
$licensor = '';
$licensorurl = '';
$tags = '';
if (!empty($configdata['artefactid'])) {
$result['artefactid'] = json_encode(array($configdata['artefactid']));
$note = $bi->get_artefact_instance($configdata['artefactid']);
$text = $note->get('description');
$tags = $note->get('tags');
$license = $note->get('license');
$licensor = $note->get('licensor');
$licensorurl = $note->get('licensorurl');
}
$result['text'] = json_encode(array($text));
$result['tags'] = json_encode(array($tags));
$result['license '] = json_encode(array($license));
$result['licensor'] = json_encode(array($licensor));
$result['licensorurl'] = json_encode(array($licensorurl));
......
......@@ -69,6 +69,12 @@ $form = array(
'cols' => 70,
'defaultvalue' => $artefact->get('description'),
),
'tags' => array(
'type' => 'tags',
'title' => get_string('tags'),
'description' => get_string('tagsdescprofile'),
'defaultvalue' => $artefact->get('tags'),
),
'license' => license_form_el_basic($artefact),
'licensing_advanced' => license_form_el_advanced($artefact),
'allowcomments' => array(
......@@ -105,6 +111,7 @@ function editnote_submit(Pieform $form, array $values) {
global $SESSION, $artefact, $goto;
$artefact->set('title', $values['title']);
$artefact->set('description', $values['description']);
$artefact->set('tags', $values['tags']);
$artefact->set('allowcomments', (int) $values['allowcomments']);
if (isset($values['perms'])) {
$artefact->set('rolepermissions', $values['perms']);
......
......@@ -140,3 +140,4 @@ $string['editnote'] = 'Edit note';
$string['confirmdeletenote'] = 'This note is used in %d blocks and %d pages. If you delete it, all the blocks which currently contain the text will appear empty.';
$string['notedeleted'] = 'Note deleted';
$string['noteupdated'] = 'Note updated';
$string['html'] = 'Note';
......@@ -700,7 +700,8 @@ class ArtefactTypeIndustry extends ArtefactTypeProfileField {}
/* Artefact type for generic html fragments */
class ArtefactTypeHtml extends ArtefactType {
public static function get_icon($options=null) {
global $THEME;
return $THEME->get_url('images/note.gif', false, 'artefact/internal');
}
public static function is_singular() {
......@@ -708,5 +709,8 @@ class ArtefactTypeHtml extends ArtefactType {
}
public static function get_links($id) {
return array(
'_default' => get_config('wwwroot') . 'artefact/internal/editnote.php?id=' . $id,
);
}
}
......@@ -159,6 +159,9 @@ if ($data) {
if (!isset($data[$b->artefact]->blocks[$b->block])) {
$data[$b->artefact]->blocks[$b->block] = $b;
}
if (!isset($data[$b->artefact]->tags)) {
$data[$b->artefact]->tags = ArtefactType::artefact_get_tags($b->artefact);
}
}
}
foreach ($data as $id => $n) {
......@@ -177,7 +180,7 @@ $pagination = build_pagination(array(
$js = '
$j(function() {
$j(".notetitle").click(function(e) {
$j("a.notetitle").click(function(e) {
e.preventDefault();
$j("#" + this.id + "_desc").toggleClass("hidden");
});
......
......@@ -17,6 +17,9 @@
{else}
<h4><a class="notetitle" href="{$WWWROOT}artefact/internal/editnote.php?id={$n->id}" id="n{$n->id}">{$n->title|str_shorten_text:80:true}</a></h4>
{/if}
{if $n->tags}
<div>{str tag=tags}: {list_tags tags=$n->tags owner=$n->owner}</div>
{/if}
<div id="n{$n->id}_desc" class="hidden desc">{$n->description|clean_html|safe}</div>
</td>
<td>
......
......@@ -728,11 +728,11 @@ class LeapExportElement {
$this->smarty->assign('dates', $this->get_dates());
if ($tags = $this->artefact->get('tags')) {
$tags = array_map(create_function('$a',
'return array(
\'term\' => LeapExportElement::normalise_tag($a),
\'label\' => $a
);'), $tags);
$tags = array_map(function ($a) {
return array(
'term' => LeapExportElement::normalise_tag($a),
'label' => $a
);}, $tags);
}
if (!$categories = $this->get_categories()) {
$categories = array();
......
......@@ -41,8 +41,8 @@ function pieform_element_tags(Pieform $form, $element) {
$value = $element['defaultvalue'];
}
if ($form->get_value($element)) {
$value = $form->get_value($element);
if ($tempvalue = $form->get_value($element)) {
$value = $tempvalue;
}
if (isset($element['value']) && is_array($element['value'])) {
......
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