-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
basic implementation of jQuery based tree for 1.4 (still to be improved
to make it nicer)
- Loading branch information
Showing
5 changed files
with
276 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
186 changes: 186 additions & 0 deletions
186
...ator/src/org/zikula/modulestudio/generator/cartridges/zclassic/view/plugin/TreeData.xtend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
package org.zikula.modulestudio.generator.cartridges.zclassic.view.plugin | ||
|
||
import com.google.inject.Inject | ||
import de.guite.modulestudio.metamodel.modulestudio.Application | ||
import org.eclipse.xtext.generator.IFileSystemAccess | ||
import org.zikula.modulestudio.generator.cartridges.zclassic.smallstuff.FileHelper | ||
import org.zikula.modulestudio.generator.extensions.ControllerExtensions | ||
import org.zikula.modulestudio.generator.extensions.FormattingExtensions | ||
import org.zikula.modulestudio.generator.extensions.ModelExtensions | ||
import org.zikula.modulestudio.generator.extensions.NamingExtensions | ||
import org.zikula.modulestudio.generator.extensions.Utils | ||
|
||
class TreeData { | ||
@Inject extension ControllerExtensions = new ControllerExtensions | ||
@Inject extension ModelExtensions = new ModelExtensions | ||
@Inject extension FormattingExtensions = new FormattingExtensions | ||
@Inject extension NamingExtensions = new NamingExtensions | ||
@Inject extension Utils = new Utils | ||
|
||
def generate(Application it, IFileSystemAccess fsa) { | ||
val pluginFilePath = viewPluginFilePath('function', 'TreeJS') | ||
if (!shouldBeSkipped(pluginFilePath)) { | ||
fsa.generateFile(pluginFilePath, new FileHelper().phpFileContent(it, treeDataImpl)) | ||
} | ||
} | ||
|
||
def private treeDataImpl(Application it) ''' | ||
/** | ||
* The «appName.formatForDB»TreeData plugin delivers the html output for a JS tree | ||
* based on given tree entities. | ||
* | ||
* Available parameters: | ||
* - objectType: Name of treated object type. | ||
* - tree: Object collection with tree items. | ||
* - controller: Optional name of controller, defaults to 'user'. | ||
* - root: Optional id of root node, defaults to 1. | ||
«IF targets('1.3.5')» | ||
«' '»* - sortable: Whether tree nodes should be sortable or not, defaults to true. | ||
«ENDIF» | ||
* - assign: If set, the results are assigned to the corresponding variable instead of printed out. | ||
* | ||
* @param array $params All attributes passed to this function from the template. | ||
* @param Zikula_View $view Reference to the view object. | ||
* | ||
* @return string The output of the plugin. | ||
*/ | ||
function smarty_function_«appName.formatForDB»TreeData($params, $view) | ||
{ | ||
if (!isset($params['objectType']) || empty($params['objectType'])) { | ||
$view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('«appName.formatForDB»TreeJS', 'objectType'))); | ||
|
||
return false; | ||
} | ||
|
||
if (!isset($params['tree']) || empty($params['tree'])) { | ||
$view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('«appName.formatForDB»TreeJS', 'tree'))); | ||
|
||
return false; | ||
} | ||
|
||
if (!isset($params['controller']) || empty($params['controller'])) { | ||
$params['controller'] = 'user'; | ||
} | ||
«IF !targets('1.3.5')» | ||
|
||
$params['lct'] = $params['controller']; | ||
$params['controller'] = $params['objectType']; | ||
«ENDIF» | ||
|
||
if (!isset($params['root']) || empty($params['root'])) { | ||
$params['root'] = 1; | ||
} | ||
|
||
// check whether an edit action is available | ||
$controllerHasEditAction = false; | ||
switch ($params['controller']) { | ||
«controllerEditActionFlags» | ||
} | ||
|
||
«IF targets('1.3.5')» | ||
$entityClass = '«appName»_Entity_' . ucwords($params['objectType']); | ||
«ENDIF» | ||
$serviceManager = ServiceUtil::getManager(); | ||
«IF targets('1.3.5')» | ||
$entityManager = $serviceManager->get«IF targets('1.3.5')»Service«ENDIF»('doctrine.entitymanager'); | ||
$repository = $entityManager->getRepository($entityClass); | ||
«ELSE» | ||
$repository = $serviceManager->get('«appName.formatForDB».«name.formatForCode»_factory')->getRepository(); | ||
«ENDIF» | ||
$descriptionFieldName = $repository->getDescriptionFieldName(); | ||
|
||
$result = ''; | ||
«IF targets('1.3.5')» | ||
$treeData = array(); | ||
|
||
foreach ($params['tree'] as $item) { | ||
$url = $controllerHasEditAction ? ModUtil::url('«appName»', $params['controller'], 'edit', $item->createUrlArgs()) : ''; | ||
|
||
$treeData[] = array('id' => $item->createCompositeIdentifier(), | ||
'parent_id' => $item->getParent()->createCompositeIdentifier(), | ||
'name' => $item->getTitleFromDisplayPattern(), | ||
'title' => (($descriptionFieldName != '') ? strip_tags($item[$descriptionFieldName]) : ''), | ||
//'icon' => '', | ||
//'class' => '', | ||
'active' => true, | ||
//'expanded' => null, | ||
'href' => $url); | ||
} | ||
|
||
// instantiate and initialise the output tree object | ||
$tree = new Zikula_Tree(); | ||
$tree->setOption('id', 'itemTree' . $params['root']); | ||
$tree->setOption('treeClass', 'z-nestedsetlist'); | ||
$tree->setOption('nodePrefix', 'tree' . $params['root'] . 'node_'); | ||
$tree->setOption('sortable', ((isset($params['sortable']) && $params['sortable']) ? true : false)); | ||
$tree->setOption('withWraper', true); | ||
|
||
// disable drag and drop for root category | ||
$tree->setOption('disabled', array(1)); | ||
|
||
// put data into output tree | ||
$tree->loadArrayData($treeData); | ||
|
||
// get output result | ||
$result = $tree->getHTML(); | ||
«ELSE» | ||
foreach ($params['tree'] as $item) { | ||
$result .= processTreeItemWithChildren($item, $rootId, $descriptionFieldName, $controllerHasEditAction); | ||
} | ||
«ENDIF» | ||
|
||
if (array_key_exists('assign', $params)) { | ||
$view->assign($params['assign'], $result); | ||
|
||
return; | ||
} | ||
|
||
return $result; | ||
} | ||
«IF !targets('1.3.5')» | ||
|
||
function processTreeItemWithChildren($node, $rootId, $descriptionFieldName, $controllerHasEditAction) | ||
{ | ||
$output = ''; | ||
$title = (($descriptionFieldName != '') ? strip_tags($item[$descriptionFieldName]) : ''); | ||
$liTag = '<li id="tree' . $rootId . 'node_' . $item->createCompositeIdentifier() . '" title="' . str_replace('"', '', $title) . '" class="lvl' . $item->getLvl() . '">'; | ||
|
||
$liContent = $item->getTitleFromDisplayPattern(); | ||
if ($controllerHasEditAction) { | ||
$urlArgs = $item->createUrlArgs(); | ||
$urlArgs['lct'] = $params['lct']; | ||
$url = $serviceManager->get('router')->generate('«appName.formatForDB»_' . $params['objectType'] . '_edit', $urlArgs); | ||
|
||
$liContent = '<a href="' . $url . '" title="' . str_replace('"', '', $title) . '">' . $liContent . '</a>'; | ||
} | ||
|
||
$treeItem = $liTag . $liContent; | ||
|
||
if (count($item->getChildren()) > 0) { | ||
$treeItem .= '<ul>'; | ||
foreach ($item->getChildren() as $childNode) { | ||
$treeItem .= processTreeItemWithChildren($childNode, $rootId, $descriptionFieldName, $controllerHasEditAction); | ||
} | ||
$treeItem .= '</ul>'; | ||
} | ||
|
||
$treeItem .= '</li>'; | ||
|
||
$output .= $treeItem; | ||
|
||
return $output; | ||
} | ||
«ENDIF» | ||
''' | ||
def private controllerEditActionFlags(Application it) ''' | ||
«FOR controller : getAllControllers.filter[hasActions('edit')]» | ||
case '«controller.formattedName»': $controllerHasEditAction = true; break; | ||
«ENDFOR» | ||
«IF !targets('1.3.5')» | ||
«FOR entity : getAllEntities.filter[hasActions('edit')]» | ||
case '«entity.name.formatForCode»': $controllerHasEditAction = true; break; | ||
«ENDFOR» | ||
«ENDIF» | ||
''' | ||
} |
Oops, something went wrong.