Commit 4b11122d authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Add javascript to choose template page

parent 9c454fbe
/**
* 'Speeds up' search if the user has javascript enabled in their browser
*
* Copyright: 2006-2008 Catalyst IT Ltd
* This file is licensed under the same terms as Mahara itself
*/
function SearchTable(id) {
var self = this;
this.id = id;
this.init = function () {
self.rewriteQueryButtons();
self.rewritePaging();
self.params = {};
}
this.searchByChildLink = function (element) {
var children = getElementsByTagAndClassName('a', null, element);
if (children.length == 1) {
var href = getNodeAttribute(children[0], 'href');
self.params = parseQueryString(href.substring(href.indexOf('?')+1, href.length));
self.doSearch();
}
}
this.changePage = function(e) {
e.stop();
self.searchByChildLink(this);
}
this.rewritePaging = function() {
forEach(getElementsByTagAndClassName('span', 'pagination', self.id), function(i) {
connect(i, 'onclick', self.changePage);
});
}
this.rewriteQueryButtons = function() {
forEach(getElementsByTagAndClassName('button', 'query-button', self.id), function(i) {
connect(i, 'onclick', self.newQuery);
});
}
this.rewriteOther = function () {} // Override
this.newQuery = function(e) {
self.params = {};
forEach(getElementsByTagAndClassName('input', null, getFirstParentByTagAndClassName(this, 'form')), function(i) {
self.params[i.name] = i.value;
});
self.doSearch();
e.stop();
}
this.doSearch = function() {
sendjsonrequest(self.id + '.json.php', self.params, 'POST', function(data) {
$(self.id + '_table').innerHTML = data.data.table;
$(self.id + '_pagination').innerHTML = data.data.pagination;
if (data.data.count) {
self.rewritePaging();
self.rewriteOther();
}
});
}
addLoadEvent(self.init);
}
//searchTable = new SearchTable();
......@@ -267,5 +267,6 @@ $string['selectaviewtocopy'] = 'Select the View you wish to copy:';
$string['listviews'] = 'List Views';
$string['nocopyableviewsfound'] = 'No Views that you can copy';
$string['noownersfound'] = 'No owners found';
$string['displayingviewsby'] = 'Displaying Views by %s';
?>
......@@ -1980,17 +1980,16 @@ class View {
$smarty->assign_by_ref('results', $results);
$smarty->assign('viewurl', get_config('wwwroot') . 'view/choosetemplate.php?' . $qstring . '&owneroffset=' . $search->offset);
$search->html = $smarty->fetch('view/viewownersearchresults.tpl');
$search->count = $results['count'];
$search->pagination = build_pagination(array(
'id' => 'viewowner_pagination',
'id' => 'viewownersearch_pagination',
'class' => 'center',
'url' => get_config('wwwroot') . 'view/choosetemplate.php?' . $qstring,
'count' => $results['count'],
'limit' => $search->limit,
'offset' => $search->offset,
'offsetname' => 'owneroffset',
'datatable' => 'viewownersearchresults',
'jsonscript' => 'view/viewownersearchresults.php',
'firsttext' => '',
'previoustext' => '',
'nexttext' => '',
......@@ -2016,18 +2015,35 @@ class View {
$smarty = smarty_core();
$smarty->assign_by_ref('results', $results->data);
if ($search->ownedby) {
foreach ($search->ownedby as $k => $v) {
$params[] = 'owntype=' . $k;
$params[] = 'ownid=' . $v;
if ($k == 'user') {
$ownername = display_name($v);
} else if ($k == 'group') {
$ownername = get_field('group', 'name', 'id', $v);
} else if ($k == 'institution') {
if ($v == 'mahara') {
$ownername = get_config('sitename');
} else {
$ownername = get_field('institution', 'displayname', 'name', $v);
}
}
}
$smarty->assign('ownername', get_string('displayingviewsby', 'view', $ownername));
}
$search->html = $smarty->fetch('view/templatesearchresults.tpl');
$search->count = $results->count;
$search->pagination = build_pagination(array(
'id' => 'template_pagination',
'id' => 'templatesearch_pagination',
'class' => 'center',
'url' => get_config('wwwroot') . 'view/choosetemplate.php?' . join('&', $params),
'count' => $results->count,
'limit' => $search->limit,
'offset' => $search->offset,
'offsetname' => 'viewoffset',
'datatable' => 'templatesearchresults',
'jsonscript' => 'view/templatesearchresults.php',
'firsttext' => '',
'previoustext' => '',
'nexttext' => '',
......
......@@ -1566,16 +1566,16 @@ button#dosearch {
width: 100%;
margin-top: 5px;
}
#copyview .views {
#copyview #templatesearch {
float: left;
margin-left: 50px;
width: 40%;
}
#copyview .owners {
#copyview #viewownersearch {
float: left;
width: 40%;
}
#copyview .search {
#copyview form.searchquery {
text-align: center;
margin-top: 10px;
}
......@@ -2549,6 +2549,7 @@ table#initials .initial-letters {
text-decoration: none;
font-weight: bold;
}
.query-button,
#query-button {
background: url(../images/btn_search_off.gif) no-repeat;
border: none;
......
......@@ -3,38 +3,35 @@
{include file="columnfullstart.tpl"}
<h2>{$heading}</h2>
<div id="copyview">
<div class="owners">
<div id="viewownersearch" class="searchlist">
<h3>{str tag="searchviewsbyowner" section="view"}</h3>
<form action="{$WWWROOT}view/choosetemplate.php" method="post">
<div class="search">
<form class="searchquery" action="{$WWWROOT}view/choosetemplate.php" method="post">
<label>{str tag="searchowners" section="view"}:
<input type="text" name="ownerquery" id="ownerquery" value="{$owners->query|escape}">
<input type="text" name="ownerquery" id="ownerquery" class="query" value="{$owners->query|escape}">
</label>
<button id="query-button" type="submit">{str tag="go"}</button>
</div>
<button class="query-button" type="submit">{str tag="go"}</button>
<input type="hidden" name="ownerlimit" value="{$owners->limit|escape}">
<input type="hidden" name="owneroffset" value="0">
</form>
<div>
{$owners->html}
<div id="viewowner_pagination">{$owners->pagination.html}</div>
<!--script type="text/javascript">{$owners->pagination.javascript}</script-->
<div id="viewownersearch_table">{$owners->html}</div>
<div id="viewownersearch_pagination">{$owners->pagination.html}</div>
</div>
</div>
<div class="views">
<div id="templatesearch" class="searchlist">
<h3>{str tag="selectaviewtocopy" section="view"}</h3>
<form action="{$WWWROOT}view/choosetemplate.php" method="post">
<div class="search">
<form class="searchquery" action="{$WWWROOT}view/choosetemplate.php" method="post">
<label>{str tag="searchviews" section="view"}:
<input type="text" name="viewquery" id="viewquery" value="{$views->query|escape}">
<input type="text" name="viewquery" id="viewquery" class="query" value="{$views->query|escape}">
</label>
<button id="query-button" type="submit">{str tag="go"}</button>
</div>
<button class="query-button" type="submit">{str tag="go"}</button>
<input type="hidden" name="viewlimit" value="{$views->limit|escape}">
<input type="hidden" name="viewoffset" value="0">
</form>
<div>
{$views->html}
<div id="viewowner_pagination">{$views->pagination.html}</div>
<!--script type="text/javascript">{$views->pagination.javascript}</script-->
</div>
<div id="templatesearch_table">{$views->html}</div>
<div id="templatesearch_pagination">{$views->pagination.html}</div>
</div>
</div>
{include file="columnfullend.tpl"}
......
<table class="templateresults tablerenderer">
<thead>
{if ($ownername)}<tr><td colspan="3">{$ownername}</td></tr>{/if}
<tr>
<th>{str tag=name}</th>
<th>{str tag=Owner section=view}</th>
<th></th>
</tr>
</thead>
<tbody>
{if !empty($results)}
......
<table class="templateresults tablerenderer">
<thead>
<tr>
<th>{str tag=name}</th>
<th>{str tag=views}</th>
<th></th>
</tr>
</thead>
<tbody>
{if !empty($results.data)}
......@@ -18,7 +20,7 @@
{/if}
</td>
<td style="text-align: center;">{$row->count|escape}</td>
<td><a href="{$viewurl}&amp;owntype={$row->type}&amp;ownid={$row->id}">{str tag=listviews section=view}</a>&nbsp;<img src="{theme_path location='images/icon_fieldset_left.gif'}" alt=""></td>
<td class="selectowner"><a href="{$viewurl}&amp;owntype={$row->type}&amp;ownid={$row->id}">{str tag=listviews section=view}</a>&nbsp;<img src="{theme_path location='images/icon_fieldset_left.gif'}" alt=""></td>
</tr>
{/foreach}
{else}
......
......@@ -55,21 +55,39 @@ $views->ownedby = null;
if ($ownertype = param_alpha('owntype', null)) {
$views->ownedby = (object) array($ownertype => param_alphanum('ownid'));
}
$views->copyableby = (object) array('group' => $group, 'institution' => $institution);
$views->copyableby = (object) array('group' => $group, 'institution' => $institution, 'user' => null);
if (!($group || $institution)) {
$views->copyableby->user = $USER->get('id');
}
View::get_templatesearch_data($views);
$smarty = smarty();
$smarty->assign('heading', TITLE);
if ($template = param_integer('template', 0)) {
$smarty->assign('selectedtemplate', get_field('view', 'title', 'id', $template));
}
$choosetemplate = pieform(create_view_form($group, $institution, $template));
$js = <<<EOF
ownerlist = new SearchTable('viewownersearch');
templatelist = new SearchTable('templatesearch');
addLoadEvent(function() {
ownerlist.rewriteOther = function () {
forEach(getElementsByTagAndClassName('td', 'selectowner', 'viewownersearch'), function(i) {
disconnectAll(i);
connect(i, 'onclick', function (e) {
e.stop();
var children = getElementsByTagAndClassName('a', null, this);
if (children.length == 1) {
var href = getNodeAttribute(children[0], 'href');
templatelist.params = parseQueryString(href.substring(href.indexOf('?')+1, href.length));
templatelist.params.viewlimit = {$views->limit};
templatelist.params.viewoffset = 0;
templatelist.doSearch();
}
});
});
};
ownerlist.rewriteOther();
});
EOF;
$smarty->assign('choosetemplate', $choosetemplate);
$smarty = smarty(array('searchtable'));
$smarty->assign('INLINEJAVASCRIPT', $js);
$smarty->assign('heading', TITLE);
$smarty->assign('owners', $owners);
$smarty->assign('views', $views);
$smarty->display('view/choosetemplate.tpl');
......
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage core
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('JSON', 1);
require(dirname(dirname(__FILE__)) . '/init.php');
require_once(get_config('libroot') . 'view.php');
$group = param_integer('group', null);
$institution = param_alphanum('institution', null);
$views = new StdClass;
$views->query = trim(param_variable('viewquery', ''));
$views->offset = param_integer('viewoffset', 0);
$views->limit = param_integer('viewlimit', 10);
$views->ownedby = null;
if ($ownertype = param_alpha('owntype', null)) {
$views->ownedby = (object) array($ownertype => param_alphanum('ownid'));
}
$views->copyableby = (object) array('group' => $group, 'institution' => $institution);
if (!($group || $institution)) {
$views->copyableby->user = $USER->get('id');
}
View::get_templatesearch_data($views);
json_reply(false, array(
'message' => null,
'data' => array(
'table' => $views->html,
'pagination' => $views->pagination['html'],
'count' => $views->count,
)
));
?>
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage core
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('JSON', 1);
require(dirname(dirname(__FILE__)) . '/init.php');
require_once(get_config('libroot') . 'view.php');
$owners = new StdClass;
$owners->query = trim(param_variable('ownerquery', ''));
$owners->template = null;
$owners->offset = param_integer('owneroffset', 0);
$owners->limit = param_integer('ownerlimit', 10);
View::get_viewownersearch_data($owners);
json_reply(false, array(
'message' => null,
'data' => array(
'table' => $owners->html,
'pagination' => $owners->pagination['html'],
'count' => $owners->count,
)
));
?>
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