Commit f54a5bc0 authored by Martyn Smith's avatar Martyn Smith Committed by Martyn Smith

Added view tagging, enhanced the pieform tag element to have a tag list

parent e2f1835a
......@@ -366,6 +366,8 @@ abstract class ArtefactType {
activity_occurred('watchlist', (object) array('artefact' => $this->id,
'subject' => get_string('artefactmodified')));
handle_event('saveartefact', $this);
if (!empty($this->parentdirty)) {
if (!empty($this->parent) && !record_exists('artefact_parent_cache', 'artefact', $this->id)) {
$apc = new StdClass;
......@@ -414,6 +416,8 @@ abstract class ArtefactType {
// Delete the record itself.
delete_records('artefact', 'id', $this->id);
handle_event('deleteartefact', $this);
// Set flags.
$this->dirty = false;
$this->parentdirty = true;
......
......@@ -180,6 +180,7 @@ if (defined('JSON')) {
global $USER;
if ($sesskey === null || $USER->get('sesskey') != $sesskey) {
$USER->logout();
json_reply('global', get_string('invalidsesskey'));
}
}
......
......@@ -132,6 +132,7 @@ function processingStop() {
// Function to post a data object to a json script.
function sendjsonrequest(script, data, rtype, successcallback, errorcallback, quiet) {
log('sendjsonrequest(script=', script, ', data=', data, ', rtype=', rtype, ', success=', successcallback, ', error=', errorcallback, ', quiet=', quiet, ')');
donothing = function () { return; };
if (typeof(successcallback) != 'function') {
successcallback = donothing;
......@@ -161,6 +162,7 @@ function sendjsonrequest(script, data, rtype, successcallback, errorcallback, qu
errtype = 'error';
}
else {
logWarn('invoking globalErrorHandler(', data, ')');
globalErrorHandler(data);
}
if (errtype) {
......@@ -425,6 +427,7 @@ function keepElementInViewport(element) {
}
}
// this function creates a pre-augmented tags control
function create_tags_control(name, value, options) {
var elements = [];
......@@ -446,6 +449,45 @@ function create_tags_control(name, value, options) {
return elements;
}
// this function takes an existing input element and augments it
function augment_tags_control(elem) {
elem = getElement(elem);
log('augment_tags_control(', elem, ')');
var tagContainer = DIV();
setElementDimensions(tagContainer, {'w': getElementDimensions(elem).w});
var showLink = A({'href':''},get_string('showtags'));
appendChildNodes(tagContainer, showLink);
connect(showLink, 'onclick', function (e) {
e.stop();
replaceChildNodes(tagContainer, get_string('loading') + ' ', IMG({'src':get_themeurl('images/loading.gif')}));
sendjsonrequest(config.wwwroot + 'json/taglist.php', {}, 'GET', function (data) {
replaceChildNodes(tagContainer);
forEach(data, function(tag) {
var tagLink = A({'href':''}, tag.tag);
connect(tagLink, 'onclick', function(e) {
e.stop();
if (some(elem.value.split(/ *, */), function(t) { return t == tag.tag; })) {
return;
}
if (elem.value.match(/^ *$/) || elem.value.match(/, *$/)) {
elem.value += tag.tag;
}
else {
elem.value += ', ' + tag.tag;
}
});
appendChildNodes(tagContainer, tagLink, '\u00A0(', tag.count, '), ');
});
});
});
insertSiblingNodesBefore(elem, tagContainer);
};
function quotaUpdate(quotaused, quota) {
if (! $('quota_percentage') ) {
return;
......
<?php
/**
* This program is part of Pieforms
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package pieform
* @subpackage element
* @author Nigel McNie <nigel@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz
*
*/
/**
* Provides a tag input field
*
* @param Pieform $form The form to render the element for
* @param array $element The element to render
* @return string The HTML for the element
*/
function pieform_element_tags(Pieform $form, $element) {
$smarty = smarty();
$value = array();
if (isset($element['defaultvalue']) && is_array($element['defaultvalue'])) {
$value = $element['defaultvalue'];
}
if ($form->get_value($element)) {
$value = $form->get_value($element);
}
if (isset($element['value']) && is_array($element['value'])) {
$value = $element['value'];
}
if (!is_array($value)) {
$value = array();
}
if (!isset($element['size'])) {
$element['size'] = 70;
}
$smarty->assign('name', $element['name']);
$smarty->assign('size', $element['size']);
$smarty->assign('id', $form->get_name() . '_' . $element['id']);
$smarty->assign('value', join(', ', $value));
$smarty->left_delimiter = '{{';
$smarty->right_delimiter = '}}';
return $smarty->fetch('form/tags.tpl');
}
function pieform_element_tags_get_value(Pieform $form, $element) {
$name = $element['name'];
$global = ($form->get_property('method') == 'get') ? $_GET : $_POST;
if (!isset($global[$name])) {
return null;
}
$value = preg_split("/\s*,\s*/", trim($global[$name]));
return $value;
}
?>
<script type="text/javascript">addLoadEvent(partial(augment_tags_control,'{{$id|escape}}'))</script>
<input type="text" size="{{$size|escape}}" id="{{$id|escape}}" name="{{$name|escape}}" value="{{$value|escape}}">
{include file="header.tpl"}
<div id="column-right">
{include file="adminmenu.tpl"}
</div>
{include file="columnleftstart.tpl"}
{include file="columnfullstart.tpl"}
<h2>{str tag="createviewstep2" section="view"}</h2>
<div id="createview2">
{literal}
......@@ -25,6 +22,6 @@
<button type="button" onclick="document.location='./';" id="createview2_cancel">{str tag="cancel"}</button>
</div>
{include file="columnleftend.tpl"}
{include file="columnfullend.tpl"}
{include file="footer.tpl"}
......@@ -108,6 +108,12 @@ $createview1 = pieform(array(
'cols' => 70,
'defaultvalue' => isset($data['description']) ? $data['description'] : null,
),
'tags' => array(
'type' => 'tags',
'title' => get_string('tags'),
'description' => get_string('tagsdesc'),
'defaultvalue' => isset($data['tags']) ? $data['tags'] : null,
),
'ownerformat' => array(
'type' => 'select',
'title' => get_string('ownerformat','view'),
......@@ -143,6 +149,7 @@ function createview1_submit(Pieform $form, $values) {
$data['title'] = $values['title'];
$data['description'] = $values['description'];
$data['tags'] = $values['tags'];
$data['startdate'] = $values['startdate'];
$data['stopdate'] = $values['stopdate'];
$data['ownerformat'] = $values['ownerformat'];
......
......@@ -95,6 +95,10 @@ function createview4_submit(Pieform $form, $values) {
$view->ctime = $view->mtime = $view->atime = $time;
$viewid = insert_record('view', $view, 'id', true);
foreach ($data['tags'] as $tag) {
insert_record('view_tag', (object)array('view' => $viewid, 'tag' => $tag));
}
foreach ($data['artefacts'] as $block => $blockdata) {
if ($blockdata['type'] == 'label') {
$viewcontent = new StdClass;
......
......@@ -108,6 +108,12 @@ $createview1 = pieform(array(
'cols' => 70,
'defaultvalue' => $data->description,
),
'tags' => array(
'type' => 'tags',
'title' => get_string('tags'),
'description' => get_string('tagsdesc'),
'defaultvalue' => get_column('view_tag', 'tag', 'view', $view_id),
),
'ownerformat' => array(
'type' => 'select',
'title' => get_string('ownerformat','view'),
......@@ -139,7 +145,14 @@ function createview1_submit(Pieform $form, $values) {
$data->ownerformat = $values['ownerformat'];
$data->mtime = db_format_timestamp(time());
db_begin();
update_record('view', $data, (object)array( 'id' => $view_id ));
delete_records('view_tag', 'view', $view_id);
foreach ($values['tags'] as $tag) {
insert_record('view_tag', (object)array( 'view' => $view_id, 'tag' => $tag));
}
db_commit();
$SESSION->add_ok_msg(get_string('viewinformationsaved', 'view'));
redirect('/view/');
......
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