Commit 61e07ade authored by Robert Lyon's avatar Robert Lyon
Browse files

Bug 1472467: allowing file browser to default to site/institution tab



When adding journals / journal entries on the site / institution level.

behatnotneeded

Change-Id: Ia32aee512ab8fb7554298acf4bc533c35e04c767
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 32c23e45
......@@ -134,6 +134,7 @@ $form = pieform(array(
'title' => get_string('attachments', 'artefact.blog'),
'folder' => $folder,
'highlight' => $highlight,
'institution' => $institutionname,
'browse' => $browse,
'page' => get_config('wwwroot') . 'artefact/blog/post.php?' . ($blogpost ? ('id=' . $blogpost) : ('blog=' . $blog)) . '&browse=1',
'browsehelp' => 'browsemyfiles',
......
......@@ -78,7 +78,20 @@ tinymce.PluginManager.add('imagebrowser', function(editor) {
} else if (jQuery('input[name="group"]').length) {
group = jQuery('input[name="group"]').val();
}
var pd = {'id': viewid, 'post': postid, 'blogid': blogid, 'blogpostid': blogpostid, 'group': group, 'change': 1};
var institution = 0;
if (jQuery('#newblog_institution').length) {
institution = jQuery('#newblog_institution').val();
}
if (jQuery('#editblog_institution').length) {
institution = jQuery('#editblog_institution').val();
}
var pd = {'id': viewid,
'post': postid,
'blogid': blogid,
'blogpostid': blogpostid,
'group': group,
'institution': institution,
'change': 1};
sendjsonrequest(config['wwwroot'] + 'json/imagebrowser.json.php', pd, 'POST', function(ibdata) {
addImageBrowser(ibdata);
......
......@@ -17,6 +17,8 @@ $change = param_boolean('change', false);
$viewid = param_integer('id', 0);
$forumpostid = param_integer('post', 0);
$groupid = param_integer('group', 0);
$institution = param_alphanum('institution', 0);
$blogid = param_alphanum('blogid', 0);
$changebrowsetab = param_integer('imgbrowserconf_artefactid_changeowner', 0);
// Folder value is 0 when returning to Home folder
$changefolder = param_exists('imgbrowserconf_artefactid_changefolder')? true : false;
......@@ -35,9 +37,18 @@ if ($forumpostid && !$groupid) {
$groupid = get_field_sql($sql, array($forumpostid));
}
if ($blogid) {
safe_require('artefact', 'blog');
$blogobj = new ArtefactTypeBlog($blogid);
$institution = $blogobj->get('institution');
}
// Create new image browser
if ($change) {
$ib = new ImageBrowser(array('view' => $viewid, 'post' => $forumpostid, 'group' => $groupid));
$ib = new ImageBrowser(array('view' => $viewid,
'post' => $forumpostid,
'group' => $groupid,
'institution' => $institution));
try {
$returndata = $ib->render_image_browser();
json_reply(false, array('data' => $returndata));
......@@ -50,6 +61,9 @@ if ($change) {
// If an image browser was already created and updated somehow, rebuild or submit the form now
// TODO why are other values true when submitting form?
if ($changebrowsetab || $changefolder || $uploadimg || $formsubmit || $formcancel) {
$ib = new ImageBrowser(array('view' => $viewid, 'post' => $forumpostid, 'group' => $groupid));
$ib = new ImageBrowser(array('view' => $viewid,
'post' => $forumpostid,
'group' => $groupid,
'institution' => $institution));
$ib->render_image_browser();
}
\ No newline at end of file
......@@ -24,8 +24,14 @@ function pieform_element_filebrowser(Pieform $form, $element) {
$smarty = smarty_core();
$group = $form->get_property('group');
$institution = $form->get_property('institution');
// See if the filebrowser has indicated it's an institution element
if (!empty($element['institution'])) {
$institution = $element['institution'];
}
else {
// otherwise check if the form knows it's in an institution setting
$institution = $form->get_property('institution');
}
$formid = $form->get_name();
$prefix = $formid . '_' . $element['name'];
......@@ -251,27 +257,31 @@ function pieform_element_filebrowser_build_filelist($form, $element, $folder, $h
$userid = null;
if (is_null($institution) && is_null($group) && is_null($user)) {
$group = $form->get_property('group');
// See if the filebrowser has indicated it's an institution element
if (!empty($element['institution'])) {
$institution = $element['institution'];
}
else {
// otherwise check if the form knows it's in an institution setting
$institution = $form->get_property('institution');
}
$userid = ($group || $institution) ? null : $USER->get('id');
}
else if ($user) {
if ($user) {
$userid = $USER->get('id');
$smarty->assign('owner', 'user');
$smarty->assign('ownerid', $userid);
}
else if ($institution) {
$smarty->assign('owner', 'institution');
$smarty->assign('ownerid', $institution);
}
else {
$smarty->assign('owner', 'group');
$smarty->assign('ownerid', $group);
}
if (is_null($institution)) {
$institution = $form->get_property('institution');
}
else {
$smarty->assign('owner', 'institution');
$smarty->assign('ownerid', $institution);
}
if (is_null($userid)) {
$userid = ($group || $institution) ? null : $USER->get('id');
}
$editable = (int) $element['config']['edit'];
$selectable = (int) $element['config']['select'];
$selectfolders = (int) !empty($element['config']['selectfolders']);
......@@ -797,7 +807,7 @@ function pieform_element_filebrowser_upload(Pieform $form, $element, $data) {
global $USER;
$parentfolder = $data['uploadfolder'] ? (int) $data['uploadfolder'] : null;
$institution = $form->get_property('institution');
$institution = !empty($element['institution']) ? $element['institution'] : $form->get_property('institution');
$group = $form->get_property('group');
if (get_config('licensemetadata')) {
$license = $data['license'];
......@@ -822,7 +832,7 @@ function pieform_element_filebrowser_upload(Pieform $form, $element, $data) {
$data = new StdClass;
$data->parent = $parentfolder;
$data->owner = null;
$data->owner = $data->group = $data->institution = null;
if (get_config('licensemetadata')) {
$data->license = $license;
$data->licensor = $licensor;
......@@ -939,7 +949,7 @@ function pieform_element_filebrowser_upload(Pieform $form, $element, $data) {
$result['quota'] = $USER->get('quota');
$result['quotaused'] = $USER->get('quotaused');
}
$result['newlist'] = pieform_element_filebrowser_build_filelist($form, $element, $parentfolder);
$result['newlist'] = pieform_element_filebrowser_build_filelist($form, $element, $parentfolder, null, $data->owner, $data->group, $data->institution);
return $result;
}
catch (UploadException $e) {
......@@ -995,7 +1005,7 @@ function pieform_element_filebrowser_upload(Pieform $form, $element, $data) {
$artefact = artefact_instance_from_id($newid);
$result['artefacttype'] = $artefact->get('artefacttype');
$result['uploaded'] = true;
$result['newlist'] = pieform_element_filebrowser_build_filelist($form, $element, $parentfolder, $newid);
$result['newlist'] = pieform_element_filebrowser_build_filelist($form, $element, $parentfolder, $newid, $data->owner, $data->group, $data->institution);
if (defined('GROUP')) {
$group = group_current_group(false);
$result['quota'] = $group->quota;
......@@ -1030,7 +1040,7 @@ function pieform_element_filebrowser_createfolder(Pieform $form, $element, $data
global $USER;
$parentfolder = $data['folder'] ? (int) $data['folder'] : null;
$institution = $form->get_property('institution');
$institution = !empty($element['institution']) ? $element['institution'] : $form->get_property('institution');
$group = $form->get_property('group');
$result = array();
......@@ -1050,6 +1060,7 @@ function pieform_element_filebrowser_createfolder(Pieform $form, $element, $data
return array('error' => true, 'message' => get_string('cannoteditfoldersubmitted', 'artefact.file'));
}
}
$data->owner = $data->group = $data->institution = null;
if ($institution) {
$data->institution = $institution;
}
......@@ -1080,7 +1091,7 @@ function pieform_element_filebrowser_createfolder(Pieform $form, $element, $data
'error' => false,
'message' => get_string('foldercreated', 'artefact.file'),
'highlight' => $f->get('id'),
'newlist' => pieform_element_filebrowser_build_filelist($form, $element, $parentfolder, $f->get('id')),
'newlist' => pieform_element_filebrowser_build_filelist($form, $element, $parentfolder, $f->get('id'), $data->owner, $data->group, $data->institution),
'foldercreated' => true,
);
}
......
......@@ -21,6 +21,7 @@ class ImageBrowser {
private $view;
private $view_obj;
private $group;
private $institution;
private $post;
private $blocktype;
private $configdata = array();
......@@ -123,6 +124,7 @@ class ImageBrowser {
// use these to determine which space to display to upload files to
$elements['post'] = array('type' => 'hidden', 'value' => $this->post);
$elements['group'] = array('type' => 'hidden', 'value' => $this->group);
$elements['institution'] = array('type' => 'hidden', 'value' => $this->institution);
$elements['view'] = array('type' => 'hidden', 'value' => $this->view);
// tinymce specific elements
......@@ -240,7 +242,7 @@ class ImageBrowser {
'viewgroup' => $this->get_view()->get('group'),
'group' => $this->get('group'),
'viewinstitution' => $this->get_view()->get('institution'),
'institution' => $this->get_view()->get('institution'),
'institution' => $this->get('institution'),
'configdirs' => $configdirs,
'plugintype' => 'blocktype',
'pluginname' => $this->get('blocktype'),
......@@ -288,6 +290,10 @@ class ImageBrowser {
global $USER;
$resizeonuploaduserdefault = $USER->get_account_preference('resizeonuploaduserdefault');
$currenttab = array('type' => 'user', 'id' => $USER->get('id'));
if ($this->institution) {
$currenttab = array('type' => 'institution', 'id' => $this->institution);
}
if ($this->group) {
$currenttab = array('type' => 'group', 'id' => $this->group);
}
......
......@@ -69,6 +69,10 @@ Scenario: Clicking on the journal sub menu headings and adding first journal (Bu
And I set the following fields to these values:
| Title * | Journal entry 2 |
| Entry * | The contents of this entry |
And I click on "Add a file"
And I attach the file "Image1.jpg" to "Upload file"
And I wait "1" seconds
Then I should see "Image1.jpg" in the "table#editpost_filebrowser_filelist" element
And I click on "Save entry"
Then I should see "Journal entry saved"
And I should see "Journal entry 1"
......
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