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

Commit a64acf8

Browse files
author
Charles Marion
committed
0009694: Add capability to edit an item
1 parent 6336d58 commit a64acf8

File tree

10 files changed

+191
-28
lines changed

10 files changed

+191
-28
lines changed

core/controllers/ItemController.php

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ItemController extends AppController
1616
public $_models = array('Item', 'ItemRevision', 'Bitstream');
1717
public $_daos = array();
1818
public $_components = array('Date', 'Utility', 'Sortdao');
19-
public $_forms = array();
19+
public $_forms = array('Item');
2020

2121
/** Init Controller */
2222
function init()
@@ -135,6 +135,47 @@ function viewAction()
135135
$this->view->json['item']['message']['movecopy'] = $this->t('Copy Item.');
136136
}//end index
137137

138+
/** Edit (ajax) */
139+
function editAction()
140+
{
141+
$this->disableLayout();
142+
$item_id = $this->_getParam('itemId');
143+
$item = $this->Item->load($item_id);
144+
if(!isset($item_id))
145+
{
146+
throw new Zend_Exception("Please set the itemId.");
147+
}
148+
elseif($item === false)
149+
{
150+
throw new Zend_Exception("The item doesn t exist.");
151+
}
152+
elseif(!$this->Item->policyCheck($item, $this->userSession->Dao, MIDAS_POLICY_WRITE))
153+
{
154+
throw new Zend_Exception("Permissions error.");
155+
}
156+
157+
if($this->_request->isPost())
158+
{
159+
$name = $this->_getParam('name');
160+
$description = $this->_getParam('description');
161+
162+
if(strlen($name) > 0)
163+
{
164+
$item->setName($name);
165+
}
166+
$item->setDescription($description);
167+
168+
$this->Item->save($item);
169+
$this->_redirect('/item/'.$item->getKey());
170+
}
171+
172+
$this->view->itemDao = $item;
173+
$form = $this->Form->Item->createEditForm();
174+
$formArray = $this->getFormAsArray($form);
175+
$formArray['name']->setValue($item->getName());
176+
$formArray['description']->setValue($item->getDescription());
177+
$this->view->form = $formArray;
178+
}
138179

139180
/** Delete an item*/
140181
function deleteAction()
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
5+
69328 Lyon, FRANCE.
6+
7+
See Copyright.txt for details.
8+
This software is distributed WITHOUT ANY WARRANTY; without even
9+
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10+
PURPOSE. See the above copyright notices for more information.
11+
=========================================================================*/
12+
13+
/** Folder forms*/
14+
class ItemForm extends AppForm
15+
{
16+
/** create edit folder form */
17+
public function createEditForm()
18+
{
19+
$form = new Zend_Form;
20+
21+
$form->setAction($this->webroot.'/item/edit')
22+
->setMethod('post');
23+
24+
$name = new Zend_Form_Element_Text('name');
25+
$name ->setRequired(true)
26+
->addValidator('NotEmpty', true);
27+
28+
$description = new Zend_Form_Element_Textarea('description');
29+
$submit = new Zend_Form_Element_Submit('submit');
30+
$submit ->setLabel($this->t("Save"));
31+
32+
$form->addElements(array($name, $description, $submit));
33+
return $form;
34+
}
35+
36+
} // end class
37+
?>

core/public/css/item/item.edit.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
form#editItemForm input[type="text"], form#editItemForm input[type="password"] ,form#editItemForm textarea
2+
{
3+
width: 350px!important;
4+
}
5+

core/public/css/item/item.view.css

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,8 @@ div.genericInfo .genericCompany {
2828
}
2929

3030
.itemStats {
31-
clear:both;
32-
position: relative;
3331
float: right;
3432
font-size: 10px;
3533
color: #777777;
36-
top: -32px;
37-
margin: 0px;
38-
width: 130px;
39-
height: 10px;
40-
text-align: right;
34+
margin-right: 10px;
4135
}

core/public/css/layout/main.css

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,51 @@ div#guideRobot{
6666
display:none;
6767
}
6868

69+
div.genericBigButton{
70+
font-size: 12px;
71+
font-weight: normal;
72+
color:black;
73+
cursor:pointer;
74+
display: block;
75+
float: left;
76+
border: #354856 1px solid;
77+
list-style-type: none;
78+
-moz-border-radius: 6px;
79+
-webkit-border-radius: 6px;
80+
-khtml-border-radius: 6px;
81+
border-radius: 6px;
82+
background-color: #ffffff;
83+
background-image: -webkit-gradient(linear, left top, left bottom, from(#ffffff), to(#c4c4c4));
84+
background-image: -moz-linear-gradient(center top, #ffffff 0%, #c4c4c4 100% );
85+
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#c4c4c4');
86+
-webkit-box-shadow: #666 0 0 2px;
87+
box-shadow: #666 0 0 2px;
88+
-moz-box-shadow: 0px 0px 2px #666;
89+
padding: 1px 3px 2px 3px;
90+
}
91+
92+
div.genericBigButton a{
93+
font-size: 12px!important;
94+
font-weight: normal!important;
95+
color:black!important;
96+
}
97+
98+
div.genericBigButton a:hover{
99+
text-decoration: none!important;
100+
}
101+
102+
103+
div.genericBigButton:hover{
104+
background-color: #bddcc9;
105+
background-image: -webkit-gradient(linear, left top, left bottom, from(#bddcc9), to(#8ab79b));
106+
background-image: -moz-linear-gradient(center top, #bddcc9 0%, #8ab79b 100% );
107+
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#bddcc9', endColorstr='#8ab79b');
108+
}
109+
110+
div.genericWrapperTopRight{
111+
float:right;
112+
}
113+
69114
/*-------------------------------------------------
70115
TOP
71116
-------------------------------------------------*/

core/public/js/admin/admin.showlog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function initLogs()
3838

3939
$('table#listLogs tr.logSum').click(function()
4040
{
41-
showDialogWithContent('Log', $(this).next().html(),true);
41+
showBigDialogWithContent('Log', $(this).next().html(),true);
4242
});
4343
}
4444

core/public/js/item/item.edit.js

Whitespace-only changes.

core/public/js/item/item.view.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@
3838
showDialog($(this).html());
3939
});
4040

41-
41+
//edit
42+
$('a.editItemLink').click(function(){
43+
loadDialog("editItem"+json.item.item_id,"/item/edit?itemId="+json.item.item_id);
44+
showDialog(json.browse.edit,false);
45+
});
46+
4247
/** preview */
4348
$('a#itemPreviewLink').click(function(){
4449

core/views/item/edit.phtml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
5+
69328 Lyon, FRANCE.
6+
7+
See Copyright.txt for details.
8+
This software is distributed WITHOUT ANY WARRANTY; without even
9+
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10+
PURPOSE. See the above copyright notices for more information.
11+
=========================================================================*/
12+
13+
echo '<script type="text/javascript" src="' . $this->coreWebroot . '/public/js/item/item.edit.js?'.time().'"></script>';
14+
?>
15+
16+
<link type="text/css" rel="stylesheet" href="<?php echo $this->coreWebroot?>/public/css/item/item.edit.css" />
17+
18+
<form id="editItemForm" class="genericForm" method="<?php echo $this->form['method']?>" action="<?php echo $this->form['action']?>">
19+
<input type="hidden" name="itemId" value="<?php echo $this->itemDao->getKey()?>"/>
20+
<div >
21+
<label for="name"><?php echo $this->t("Name")?></label>
22+
<?php echo $this->form['name']?>
23+
</div>
24+
<div >
25+
<label for="description"><?php echo $this->t("Description")?></label>
26+
<?php echo $this->form['description']?>
27+
</div>
28+
<div>
29+
<?php echo $this->form['submit']?>
30+
</div>
31+
</form>

core/views/item/view.phtml

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,26 @@ $this->headScript()->appendFile($this->coreWebroot . '/public/js/item/item.view.
2424
?>
2525
</div>
2626
<div class="genericInfo">
27+
<div class="genericBigButton genericWrapperTopRight">
28+
<?php
29+
echo "<a href='{$this->webroot}/download/?items={$this->itemDao->getKey()}'>";
30+
if($this->itemIsLink)
31+
{
32+
echo $this->t('View as weblink');
33+
}
34+
else
35+
{
36+
echo $this->t('Download');
37+
}
38+
echo '</a>';
39+
?>
40+
</div>
41+
<div class="itemStats">
42+
<?php echo $this->itemDao->getView()?> <?php echo $this->t('views'); ?>,
43+
<?php echo $this->itemDao->getDownload()?> <?php echo $this->t('downloads');?></div>
2744
<div class="genericName"><?php echo $this->slicename($this->itemDao->getName(),50); ?></div>
2845
<div class="genericCompany"><?php echo $this->itemSize;?></div>
29-
<div class="itemStats"><?php echo $this->itemDao->getView()?> <?php echo $this->t('views'); ?>,
30-
<?php echo $this->itemDao->getDownload()?> <?php echo $this->t('downloads');?></div>
46+
3147
</div>
3248

3349
<table id="browseTable" class="midasTree">
@@ -117,23 +133,9 @@ $this->headScript()->appendFile($this->coreWebroot . '/public/js/item/item.view.
117133
<h1>Actions</h1>
118134
<ul>
119135
<?php
120-
echo
121-
"<li>
122-
<a href='{$this->webroot}/download/?items={$this->itemDao->getKey()}'>";
123-
if($this->itemIsLink)
124-
{
125-
echo $this->t('View as weblink');
126-
}
127-
else
128-
{
129-
echo $this->t('Download lastest revision');
130-
}
131-
echo "</a>
132-
</li>
133-
";
134136
if($this->preview)
135137
{
136-
echo
138+
echo
137139
"<li>
138140
<a id='itemPreviewLink'>{$this->t('Preview')}</a>
139141
</li>
@@ -144,7 +146,10 @@ $this->headScript()->appendFile($this->coreWebroot . '/public/js/item/item.view.
144146
echo
145147
"<li>
146148
<a href='javascript:;' class='moveCopyLink' >{$this->t('Copy')}</a>
147-
</li>
149+
</li>
150+
<li>
151+
<a href='javascript:;' class='editItemLink' >{$this->t('Edit')}</a>
152+
</li>
148153
<li>
149154
<a href='javascript:;' type='item' element='{$this->itemDao->getKey()}' class='sharingLink' >{$this->t('Share')}</a>
150155
</li>

0 commit comments

Comments
 (0)