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

Commit

Permalink
ENH: Now we can edit a folder: bug: 9583
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Marion committed May 4, 2011
1 parent a653908 commit 22c7e15
Show file tree
Hide file tree
Showing 12 changed files with 197 additions and 3 deletions.
51 changes: 50 additions & 1 deletion core/controllers/FolderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class FolderController extends AppController
public $_models=array('Folder','Folder','Item','Folderpolicygroup','Folderpolicyuser');
public $_daos=array('Folder','Folder','Item');
public $_components=array('Utility','Date');
public $_forms=array();
public $_forms=array('Folder');

/** Init Controller */
function init()
Expand All @@ -19,6 +19,55 @@ function init()
}
$this->view->activemenu = 'browse'; // set the active menu
} // end init()


/** Edit Folder (ajax) */
function editAction()
{
$this->_helper->layout->disableLayout();
$folder_id=$this->_getParam('folderId');
$folder=$this->Folder->load($folder_id);
if(!isset($folder_id))
{
throw new Zend_Exception("Please set the folderId.");
}
elseif($folder===false)
{
throw new Zend_Exception("The folder doesn t exist.");
}
elseif(!$this->Folder->policyCheck($folder, $this->userSession->Dao, MIDAS_POLICY_WRITE))
{
throw new Zend_Exception("Permissions error.");
}

if($this->_request->isPost())
{
$name=$this->_getParam('name');
$description=$this->_getParam('description');
$teaser=$this->_getParam('teaser');

if(strlen($name)>0)
{
$folder->setName($name);
}
$folder->setDescription($description);
if(strlen($teaser)<251)
{
$folder->setTeaser($teaser);
}

$this->Folder->save($folder);
$this->_redirect('/folder/'.$folder->getKey());
}

$this->view->folderDao=$folder;
$form = $this->Form->Folder->createEditForm();
$formArray = $this->getFormAsArray($form);
$formArray['name']->setValue($folder->getName());
$formArray['description']->setValue($folder->getDescription());
$formArray['teaser']->setValue($folder->getTeaser());
$this->view->form = $formArray;
}

/** View Action*/
public function viewAction()
Expand Down
3 changes: 2 additions & 1 deletion core/controllers/components/NotifyErrorComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public function fatalEror($logger,$mailer)
if(!is_null($e = error_get_last()))
{
$environment = Zend_Registry::get('configGlobal')->environment;

switch ($environment) {
case 'production':
$message .= "It seems you have just encountered an unknown issue.";
Expand All @@ -45,6 +44,7 @@ public function fatalEror($logger,$mailer)
elseif($e['type']==E_WARNING )$e['typeText']='E_WARNING';
elseif($e['type']==E_PARSE) $e['typeText ']='E_PARSE';
elseif($e['type']==E_RECOVERABLE_ERROR) $e['typeText ']='E_RECOVERABLE_ERROR';
elseif($e['type']==E_COMPILE_ERROR) $e['typeText ']='E_COMPILE_ERROR';
else return;
echo $message;
$this->_mailer=$mailer;
Expand All @@ -58,6 +58,7 @@ public function fatalEror($logger,$mailer)
elseif($e['type']==E_WARNING )$e['typeText']='E_WARNING';
elseif($e['type']==E_PARSE) $e['typeText ']='E_PARSE';
elseif($e['type']==E_RECOVERABLE_ERROR) $e['typeText ']='E_RECOVERABLE_ERROR';
elseif($e['type']==E_COMPILE_ERROR) $e['typeText ']='E_COMPILE_ERROR';
else return;
header('content-type: text/plain');
echo $this->getFatalErrorMessage($e);
Expand Down
27 changes: 27 additions & 0 deletions core/controllers/forms/FolderForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
class FolderForm extends AppForm
{
/** create edit folder form */
public function createEditForm()
{
$form = new Zend_Form;

$form->setAction($this->webroot.'/folder/edit')
->setMethod('post');

$name = new Zend_Form_Element_Text('name');
$name ->setRequired(true)
->addValidator('NotEmpty', true);

$description = new Zend_Form_Element_Textarea('description');
$teaser = new Zend_Form_Element_Text('teaser');
$teaser->setAttrib('MAXLENGTH', '250');
$submit = new Zend_Form_Element_Submit('submit');
$submit ->setLabel($this->t("Save"));

$form->addElements(array($name,$description,$submit,$teaser));
return $form;
}

} // end class
?>
27 changes: 27 additions & 0 deletions core/database/upgrade/3.0.4.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

class Upgrade_3_0_4 extends MIDASUpgrade
{
public function preUpgrade()
{

}

public function mysql()
{
$sql = "ALTER TABLE folder ADD COLUMN teaser varchar(250) DEFAULT ''; ";
$this->db->query($sql);
}

public function pgsql()
{
$sql = "ALTER TABLE folder ADD COLUMN teaser varying(250) DEFAULT '', ; ";
$this->db->query($sql);
}

public function postUpgrade()
{

}
}
?>
1 change: 1 addition & 0 deletions core/models/base/FolderModelBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function __construct()
'description' => array('type'=>MIDAS_DATA),
'date' => array('type'=>MIDAS_DATA),
'view' => array('type'=>MIDAS_DATA),
'teaser' => array('type'=>MIDAS_DATA),
'items' => array('type'=>MIDAS_MANY_TO_MANY, 'model'=>'Item', 'table' => 'item2folder', 'parent_column'=> 'folder_id', 'child_column' => 'item_id'),
'folderpolicygroup' => array('type'=>MIDAS_ONE_TO_MANY, 'model' => 'Folderpolicygroup', 'parent_column'=> 'folder_id', 'child_column' => 'folder_id'),
'folderpolicyuser' => array('type'=>MIDAS_ONE_TO_MANY, 'model' => 'Folderpolicyuser', 'parent_column'=> 'folder_id', 'child_column' => 'folder_id'),
Expand Down
5 changes: 5 additions & 0 deletions core/public/css/folder/folder.edit.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
form#editFolderForm input[type="text"], form#editFolderForm input[type="password"] ,form#editFolderForm textarea
{
width: 350px!important;
}

8 changes: 8 additions & 0 deletions core/public/css/folder/folder.view.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
div.defaultSideTrigger{
display:none;
}

div.viewAction{
display:inherit!important;
}

div.viewInfo{
display:inherit!important;
}
20 changes: 19 additions & 1 deletion core/public/js/common/common.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@
});

}


function editFolder(id)
{
loadDialog("editFolder"+id,"/folder/edit?folderId="+id);
showDialog(json.browse.edit,false);
}

function removeItem(id)
{
var html='';
Expand Down Expand Up @@ -209,9 +217,10 @@
{
html+='<li><a onclick="createNewFolder('+element+');">'+json.browse.createFolder+'</a></li>';
html+='<li><a rel="'+json.global.webroot+'/upload/simpleupload/?parent='+element+'" class="uploadInFolder">'+json.browse.uploadIn+'</a></li>';
html+='<li><a onclick="editFolder('+element+');">'+json.browse.edit+'</a></li>';
if(node.attr('deletable')!=undefined && node.attr('deletable')=='true')
{
html+='<li><a type="folder" element="'+element+'" class="sharingLink">'+json.browse.share+'</a></li>';
html+='<li><a type="folder" element="'+element+'" class="sharingLink">'+json.browse.share+'</a></li>';
html+='<li><a onclick="deleteFolder('+element+');">'+json.browse['delete']+'</a></li>';
}
}
Expand Down Expand Up @@ -310,6 +319,15 @@
html+=' </tr>';

}

if(arrayElement['type']=='folder')
{
html+=' <tr>';
html+=' <td colspan="2">';
html+=arrayElement['teaser'];
html+= '</td>';
html+=' </tr>';
}
html+='</table>';
if(arrayElement['type']=='community'&&arrayElement['privacy']==2)
{
Expand Down
Empty file.
2 changes: 2 additions & 0 deletions core/public/js/folder/folder.view.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
$("table#browseTable").show();
genericCallbackSelect($('div.defaultSideTrigger'));

$( "#tabsGeneric" ).tabs();
$("#tabsGeneric").show();
});

//dependance: common/browser.js
Expand Down
25 changes: 25 additions & 0 deletions core/views/folder/edit.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/** AJAX Action !!!! */
echo '<script type="text/javascript" src="' . $this->coreWebroot . '/public/js/folder/folder.edit.js?'.time().'"></script>';
?>

<link type="text/css" rel="stylesheet" href="<?php echo $this->coreWebroot?>/public/css/folder/folder.edit.css" />

<form id="editFolderForm" class="genericForm" method="<?php echo $this->form['method']?>" action="<?php echo $this->form['action']?>">
<input type="hidden" name="folderId" value="<?php echo $this->folderDao->getKey()?>"/>
<div >
<label for="name"><?php echo $this->t("Name")?></label>
<?php echo $this->form['name']?>
</div>
<div >
<label for="description"><?php echo $this->t("Description")?></label>
<?php echo $this->form['description']?>
</div>
<div >
<label for="teaser"><?php echo $this->t("Teaser")?></label>
<?php echo $this->form['teaser']?>
</div>
<div>
<?php echo $this->form['submit']?>
</div>
</form>
31 changes: 31 additions & 0 deletions core/views/folder/view.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,26 @@
$this->headScript()->appendFile($this->coreWebroot.'/public/js/folder/folder.view.js');
$this->headScript()->appendFile($this->coreWebroot.'/public/js/common/common.browser.js');
?>
<link type="text/css" rel="stylesheet" href="<?php echo $this->coreWebroot?>/public/css/common/common.genericPage.css" />
<link type="text/css" rel="stylesheet" href="<?php echo $this->coreWebroot?>/public/css/common/common.browser.css" />
<link type="text/css" rel="stylesheet" href="<?php echo $this->coreWebroot?>/public/css/folder/folder.view.css" />

<div class="viewMain">

<?php
$descriptionMainFolder=$this->mainFolder->getDescription();
if(!empty($descriptionMainFolder))
{
?>
<div class="tabs" id='tabsGeneric'>
<ul>
<li><a href="#tabs-1"><?php echo $this->t("Data")?></a></li>
<li><a href="#tabs-2"><?php echo $this->t('Info');?></a></li>
</ul>
<div id="tabs-1">
<?php
}
?>
<img class="tableLoading" alt="" src="<?php echo $this->coreWebroot?>/public/images/icons/loading.gif"/>
<table id="browseTable" class="midasTree">
<thead>
Expand Down Expand Up @@ -52,7 +69,21 @@
echo "<h4>{$this->t("This folder is empty")}.</h4>";
}
?>
<?php

if(!empty($descriptionMainFolder))
{
?>
</div>
<div id="tabs-2">
<?php echo $descriptionMainFolder?>
</div>
</div>
<?php
}
?>
</div>

<div class="viewSideBar">
<?php
if(empty($this->folders)&&empty($this->items))
Expand Down

0 comments on commit 22c7e15

Please sign in to comment.