Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit a1a7909

Browse files
author
Charles Marion
committed
ENH: Added item copy
1 parent d815afb commit a1a7909

File tree

12 files changed

+297
-55
lines changed

12 files changed

+297
-55
lines changed

core/AppController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public function preDispatch()
6868
'view'=>$this->t('View'),
6969
'preview'=>$this->t('Preview'),
7070
'download'=>$this->t('Download'),
71+
'manage'=>$this->t('Manage'),
7172
'edit'=>$this->t('Edit'),
7273
'delete'=>$this->t('Delete'),
7374
'share'=>$this->t('Share'),

core/controllers/BrowseController.php

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,99 @@ public function indexAction()
5151
$this->view->json['community']['contentCreateLogin']=$this->t('You need to be logged in to be able to create a community.');
5252
}
5353

54+
/** move or copy selected element*/
55+
public function movecopyAction()
56+
{
57+
$copySubmit=$this->_getParam('copyElement');
58+
$moveSubmit=$this->_getParam('moveElement');
59+
if(isset($copySubmit)||isset($moveSubmit))
60+
{
61+
$elements=explode(';',$this->_getParam('elements'));
62+
$destination=$this->_getParam('destination');
63+
$folderIds=explode('-',$elements[0]);
64+
$itemIds=explode('-',$elements[1]);
65+
$folders= $this->Folder->load($folderIds);
66+
$items= $this->Item->load($itemIds);
67+
$destination=$this->Folder->load($destination);
68+
if(empty($folders)&&empty ($items))
69+
{
70+
throw new Zend_Exception("No element selected");
71+
}
72+
if($destination==false)
73+
{
74+
throw new Zend_Exception("Unable to load destination");
75+
}
76+
77+
foreach ($folders as $folder)
78+
{
79+
//TODO
80+
if(isset($copySubmit))
81+
{
82+
83+
}
84+
else
85+
{
86+
87+
}
88+
}
89+
foreach ($items as $item)
90+
{
91+
if(isset($copySubmit))
92+
{
93+
$this->Folder->addItem($destination,$item);
94+
}
95+
else
96+
{
97+
//TODO move
98+
}
99+
}
100+
$this->_redirect ('/folder/'.$destination->getKey());
101+
}
102+
103+
104+
if(!$this->getRequest()->isXmlHttpRequest())
105+
{
106+
throw new Zend_Exception("Why are you here ? Should be ajax.");
107+
}
108+
$this->_helper->layout->disableLayout();
109+
$folderIds=$this->_getParam('folders');
110+
$itemIds=$this->_getParam('items');
111+
$move=$this->_getParam('move');
112+
$this->view->folderIds=$folderIds;
113+
$this->view->itemIds=$itemIds;
114+
$this->view->moveEnabled=true;
115+
if(isset($move))
116+
{
117+
$this->view->moveEnabled=false;
118+
}
119+
$folderIds=explode('-',$folderIds);
120+
$itemIds=explode('-',$itemIds);
121+
$folders= $this->Folder->load($folderIds);
122+
$items= $this->Item->load($itemIds);
123+
if(empty($folders)&&empty ($items))
124+
{
125+
throw new Zend_Exception("No element selected");
126+
}
127+
if(!$this->view->logged)
128+
{
129+
throw new Zend_Exception("Should be logged");
130+
}
131+
$this->view->folders=$folders;
132+
$this->view->items=$items;
133+
134+
$communities=$this->User->getUserCommunities($this->userSession->Dao);
135+
$communities=array_merge($communities, $this->Community->getPublicCommunities());
136+
$this->view->Date=$this->Component->Date;
137+
138+
$this->Component->Sortdao->field='name';
139+
$this->Component->Sortdao->order='asc';
140+
usort($communities, array($this->Component->Sortdao,'sortByName'));
141+
$communities=$this->Component->Sortdao->arrayUniqueDao($communities );
142+
143+
$this->view->user=$this->userSession->Dao;
144+
$this->view->communities=$communities;
145+
}
146+
54147
/** get getfolders content (ajax function for the treetable) */
55148
public function getfolderscontentAction()
56149
{

core/controllers/ItemController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ function viewAction()
7777
$this->view->json['item']=$itemDao->_toArray();
7878
$this->view->json['item']['message']['delete']=$this->t('Delete');
7979
$this->view->json['item']['message']['deleteMessage']=$this->t('Do you really want to delete this item? It cannot be undo.');
80+
$this->view->json['item']['message']['movecopy']=$this->t('Copy Item.');
8081
}//end index
8182

8283

core/views/browse/movecopy.phtml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
2+
3+
<?php
4+
echo '<script type="text/javascript" src="' . $this->webroot . '/public/js/common/common.browser.js"></script>';
5+
echo '<script type="text/javascript" src="' . $this->webroot . '/public/js/browse/browse.movecopy.js"></script>';
6+
?>
7+
8+
<link type="text/css" rel="stylesheet" href="<?php echo $this->webroot?>/public/css/common/common.browser.css" />
9+
<link type="text/css" rel="stylesheet" href="<?php echo $this->webroot?>/public/css/browse/browse.movecopy.css" />
10+
11+
<h4><?php echo $this->t('Please select a folder.')?></h4>
12+
<img class="tableLoading" alt="" src="<?php echo $this->webroot?>/public/images/icons/loading.gif"/>
13+
<table id="moveTable" class="midasTree">
14+
<thead>
15+
<?php
16+
if(!empty($this->communities))
17+
{ ?>
18+
<tr>
19+
<th class="thData"><?php echo $this->t('Name');?></th>
20+
</tr>
21+
<?php
22+
}
23+
?>
24+
</thead>
25+
<tbody>
26+
<?php
27+
$node=1;
28+
foreach($this->communities as $community)
29+
{
30+
$folder=$community->getFolder();
31+
echo "<tr id='node--$node' class='parent' type='community' element='{$community->getCommunityId()}' ajax='{$folder->getFolderId()}'>";
32+
echo " <td class='treeBrowseElement'><span class='community'>{$community->getName()}</span></td>";
33+
echo "</tr>";
34+
$node++;
35+
}
36+
37+
$folder=$this->user->getFolder();
38+
echo "<tr id='node--$node' class='parent' type='folder' element='-1' ajax='{$folder->getFolderId()}'>";
39+
echo " <td class='treeBrowseElement'><span class='folder'>{$this->t('My Files')} ({$this->user->getFullName()})</span></td>";
40+
echo "</tr>";
41+
$node++;
42+
?>
43+
</tbody>
44+
</table>
45+
<br/> <br/>
46+
<form class="genericForm" type='post' action="<?php echo $this->webroot?>/browse/movecopy">
47+
<input type='hidden' name='elements' value='<?php echo $this->folderIds?>;<?php echo $this->itemIds?>' />
48+
<input type='hidden' id="selectedDestinationHidden" name='destination' />
49+
Destination: <span id="selectedDestination" > <?php echo $this->t('Please select a folder.') ?> </span> <br/>
50+
<?php
51+
if($this->moveEnabled)
52+
{?>
53+
<input type="submit" disabled name='moveElements' id='moveElements' value="<?php echo $this->t('Move')?>"/>
54+
<?php
55+
}
56+
?>
57+
<input type="submit" disabled id='copyElement' name='copyElement' value="<?php echo $this->t('Copy')?>"/>
58+
</form>
59+
60+
<?php
61+
if(empty($this->communities))
62+
{
63+
echo "<h4>{$this->t("No community available")}.</h4>";
64+
}
65+
?>

core/views/community/view.phtml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,16 @@ $this->headScript()->appendFile($this->webroot.'/public/js/common/common.browser
109109
if($this->isModerator)
110110
{
111111
echo "
112-
<li><a href=''>{$this->t('Manage Groups and Members')}</a></li>
113-
<li><a >{$this->t('Manage Files')}</a></li>
112+
<li><a href=''>{$this->t('Manage')}</a></li>
114113
";
115114
}
116115
if($this->isAdmin)
117116
{
118117
echo "
119-
<li><a href=''>{$this->t('Edit')}</a></li>
120118
<li><a href='javascript:;' id='communityDeleteLink'>{$this->t('Delete')}</a></li>
121119
";
122120
}
123-
if($this->isMember)
121+
if($this->isMember&&!$this->isAdmin)
124122
{
125123
echo "
126124
<li><a href=''>{$this->t('Leave the community')}</a></li>

core/views/item/view.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ $this->headScript()->appendFile($this->webroot . '/public/js/item/item.view.js')
5454
{
5555
echo
5656
"<li>
57-
<a >{$this->t('Copy')}</a>
57+
<a href='javascript:;' class='moveCopyLink' >{$this->t('Copy')}</a>
5858
</li>
5959
";
6060
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
table#moveTable{
2+
width: 420px !important;
3+
}
4+
5+
table#moveTable th.thData {
6+
width: auto!important;
7+
border-right: none!important;
8+
}
9+
10+
table#moveTable{
11+
display: none;
12+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
$("#moveTable").treeTable();
2+
$("img.tableLoading").hide();
3+
$("table#moveTable").show();
4+
5+
6+
//dependance: common/browser.js
7+
var ajaxSelectRequest='';
8+
function callbackSelect(node)
9+
{
10+
$('#selectedDestinationHidden').val(node.attr('element'));
11+
$('#selectedDestination').html(node.find('span:last').html());
12+
$('#copyElement').removeAttr('disabled');
13+
$('#moveElements').removeAttr('disabled');
14+
}
15+
16+
17+
$('img.infoLoading').show();
18+
$('div.ajaxInfoElement').html('');
19+
if(ajaxSelectRequest!='')
20+
{
21+
ajaxSelectRequest.abort();
22+
}
23+
createAction(node);
24+
ajaxSelectRequest = $.ajax({
25+
type: "POST",
26+
url: json.global.webroot+'/browse/getelementinfo',
27+
data: {type: node.attr('type'), id: node.attr('element')},
28+
success: function(jsonContent){
29+
createInfo(jsonContent);
30+
$('img.infoLoading').hide();
31+
32+
}
33+
});
34+
35+
function callbackDblClick(node)
36+
{
37+
// genericCallbackDblClick(node);
38+
}
39+
40+
function callbackCheckboxes(node)
41+
{
42+
// genericCallbackCheckboxes(node);
43+
}
44+
45+
function customElements(node,elements,first)
46+
{
47+
var i = 1;
48+
var id=node.attr('id');
49+
elements['folders'] = jQuery.makeArray(elements['folders']);
50+
51+
var padding=parseInt(node.find('td:first').css('padding-left').slice(0,-2));
52+
var html='';
53+
$.each(elements['folders'], function(index, value) {
54+
html+= "<tr id='"+id+"-"+i+"' class='parent child-of-"+id+"' ajax='"+value['folder_id']+"'type='folder' policy='"+value['policy']+"' element='"+value['folder_id']+"'>";
55+
html+= " <td><span class='folder'>"+trimName(value['name'],padding)+"</span></td>";
56+
html+= "</tr>";
57+
i++;
58+
});
59+
return html;
60+
}
61+
62+
63+
function trimName(name,padding)
64+
{
65+
if(name.length*7+padding>350)
66+
{
67+
toremove=(name.length*7+padding-350)/8;
68+
if(toremove<13)
69+
{
70+
return 'error';
71+
}
72+
name=name.substring(0,10)+'...'+name.substring(name.length+13-toremove);
73+
return name;
74+
}
75+
return name;
76+
}

public/js/common/common.browser.js

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -88,27 +88,15 @@
8888
var html='';
8989
if(type=='community')
9090
{
91-
html+='<li><a href="'+json.global.webroot+'/community/'+element+'">'+json.browse.view+'</a></li>';
92-
if(policy==2)
93-
{
94-
html+='<li><a>'+json.browse.edit+'</a></li>';
95-
}
96-
if(policy>=1)
97-
{
98-
html+='<li><a>'+json.browse.community.invit+'</a></li>';
99-
html+='<li><a>'+json.browse.community.advanced+'</a></li>';
100-
}
91+
html+='<li><a href="'+json.global.webroot+'/community/'+element+'">'+json.browse.view+'</a></li>';
10192
}
10293
if(type=='folder')
10394
{
10495
html+='<li><a href="'+json.global.webroot+'/folder/'+element+'">'+json.browse.view+'</a></li>';
10596
html+='<li><a href="'+json.global.webroot+'/download?folders='+element+'">'+json.browse.download+'</a></li>';
10697
if(policy==2)
10798
{
108-
html+='<li><a>'+json.browse.edit+'</a></li>';
109-
html+='<li><a>'+json.browse['delete']+'</a></li>';
110-
html+='<li><a>'+json.browse.move+'</a></li>';
111-
html+='<li><a>'+json.browse.copy+'</a></li>';
99+
html+='<li><a>'+json.browse.manage+'</a></li>';
112100
}
113101
if(policy>=1)
114102
{
@@ -119,13 +107,6 @@
119107
{
120108
html+='<li><a href="'+json.global.webroot+'/item/'+element+'">'+json.browse.view+'</a></li>';
121109
html+='<li><a href="'+json.global.webroot+'/download?items='+element+'">'+json.browse.download+'</a></li>';
122-
if(policy==2)
123-
{
124-
html+='<li><a>'+json.browse.edit+'</a></li>';
125-
html+='<li><a>'+json.browse['delete']+'</a></li>';
126-
html+='<li><a>'+json.browse.move+'</a></li>';
127-
html+='<li><a>'+json.browse.copy+'</a></li>';
128-
}
129110
if(policy>=1)
130111
{
131112
html+='<li><a>'+json.browse.share+'</a></li>';

public/js/item/item.view.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
$(document).ready(function() {
2-
2+
$('a.moveCopyLink').click(function()
3+
{
4+
loadDialog("movecopy","/browse/movecopy/?move=false&items="+json.item.item_id);
5+
showDialog(json.item.message.movecopy);
6+
});
37

48
$('a#itemDeleteLink').click(function()
59
{

0 commit comments

Comments
 (0)