Permalink
Browse files

Merge pull request #23 from FlorianLB/master

ticket #237 - Implementation of jPref
  • Loading branch information...
laurentj committed Feb 15, 2012
2 parents 9d22ecf + b8200cd commit ce7b54dafba1600463ef4696e32a56e100f41417
Showing with 909 additions and 6 deletions.
  1. +20 −0 build/manifests/jelix-admin-modules.mn
  2. +6 −0 build/manifests/jelix-lib.mn
  3. +1 −0 build/manifests/jelix-scripts.mn
  4. +1 −0 build/manifests/jelix-www.mn
  5. +2 −0 build/manifests/testapp.mn
  6. +23 −0 lib/jelix-admin-modules/jpref_admin/classes/jpref_admin.listener.php
  7. +163 −0 lib/jelix-admin-modules/jpref_admin/controllers/prefs.classic.php
  8. +6 −0 lib/jelix-admin-modules/jpref_admin/events.xml
  9. +26 −0 lib/jelix-admin-modules/jpref_admin/forms/pref.form.xml
  10. +21 −0 lib/jelix-admin-modules/jpref_admin/install/install.php
  11. +26 −0 lib/jelix-admin-modules/jpref_admin/locales/en_EN/admin.UTF-8.properties
  12. +26 −0 lib/jelix-admin-modules/jpref_admin/locales/fr_FR/admin.UTF-8.properties
  13. +16 −0 lib/jelix-admin-modules/jpref_admin/module.xml
  14. +6 −0 lib/jelix-admin-modules/jpref_admin/templates/pref_edit.tpl
  15. +80 −0 lib/jelix-admin-modules/jpref_admin/templates/prefs_index.tpl
  16. +14 −0 lib/jelix-admin-modules/jpref_admin/urls.xml
  17. +1 −0 lib/jelix-scripts/commands-single/createapp.cmd.php
  18. +6 −2 lib/jelix-scripts/commands/initadmin.cmd.php
  19. +27 −0 lib/jelix-scripts/templates/var/config/preferences.ini.php.tpl
  20. +5 −0 lib/jelix-scripts/templates/var/config/profiles.ini.php.tpl
  21. BIN lib/jelix-www/design/images/cog.png
  22. +1 −2 lib/jelix/CREDITS
  23. +2 −2 lib/jelix/init.php
  24. +104 −0 lib/jelix/pref/jPref.class.php
  25. +113 −0 lib/jelix/pref/jPrefItem.class.php
  26. +36 −0 lib/jelix/pref/jPrefItemGroup.class.php
  27. +148 −0 lib/jelix/pref/jPrefManager.class.php
  28. +25 −0 testapp/modules/jelix_tests/tests/jpref.main_api.pu.php
  29. +4 −0 testapp/var/config/profiles.ini.php.dist
@@ -79,4 +79,24 @@ cd lib/jelix-admin-modules/jauthdb_admin/templates
password_change.tpl
user_edit.tpl
user_view.tpl
+
+cd lib/jelix-admin-modules/jpref_admin
+* module.xml
+ events.xml
+ urls.xml
+cd lib/jelix-admin-modules/jpref_admin/classes/
+ jpref_admin.listener.php
+cd lib/jelix-admin-modules/jpref_admin/controllers
+ prefs.classic.php
+cd lib/jelix-admin-modules/jpref_admin/forms
+ pref.form.xml
+cd lib/jelix-admin-modules/jpref_admin/install
+ install.php
+cd lib/jelix-admin-modules/jpref_admin/locales/en_EN
+cch admin.UTF-8.properties(admin.%charset%.properties)
+cd lib/jelix-admin-modules/jpref_admin/locales/fr_FR
+cch admin.UTF-8.properties(admin.%charset%.properties)
+cd lib/jelix-admin-modules/jpref_admin/templates
+ prefs_index.tpl
+ pref_edit.tpl
@@ -368,6 +368,12 @@ cd lib/jelix/kvdb
* jKVDriver.class.php
jKVDb.class.php
+cd lib/jelix/pref
+ jPref.class.php
+ jPrefItem.class.php
+ jPrefItemGroup.class.php
+ jPrefManager.class.php
+
cd lib/jelix/tpl/
* jTpl.class.php
* jTplCompiler.class.php
@@ -84,6 +84,7 @@ cd lib/jelix-scripts/templates/var/config/
jacl2.coord.ini.php.tpl
installer.ini.php.tpl
profiles.ini.php.tpl
+ preferences.ini.php.tpl
urls.xml.tpl
cd lib/jelix-scripts/templates/var/config/index/
config.ini.php.tpl
@@ -30,6 +30,7 @@ cd lib/jelix-www/design/images
group.png
rights.png
user.png
+ cog.png
cd lib/jelix-www/js
c tooltip.js
c jforms_light.js
@@ -208,6 +208,7 @@ cd testapp/modules/jelix_tests/tests/
core.urls_parsing.html_cli.php
daotests.lib.php
events.simple_test.html_cli.php
+ httpcache.pu.php
installer.lib.php
installer.main.html_cli.php
installer.misc.html_cli.php
@@ -263,6 +264,7 @@ cd testapp/modules/jelix_tests/tests/
jkvdb.file.html_cli.php
jkvdb.redis.html_cli.php
jkvdb.lib.php
+ jpref.main_api.pu.php
jtpl.compiler.html_cli.php
jtpl.expressions_parsing.html_cli.php
jtpl.fetch.html_cli.php
@@ -0,0 +1,23 @@
+<?php
+/**
+* @package jelix_admin_modules
+* @subpackage jpref_admin
+* @author Florian Lonqueu-Brochard
+* @copyright 2012 Florian Lonqueu-Brochard
+* @link http://jelix.org
+* @licence http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file
+*/
+
+class jpref_adminListener extends jEventListener{
+
+ /**
+ *
+ */
+ function onmasteradminGetMenuContent ($event) {
+ if (jAcl2::check('auth.users.list')) {
+ $item = new masterAdminMenuItem('pref', jLocale::get('jpref_admin~admin.item.title'), jUrl::get('jpref_admin~prefs:index'), 50, 'system');
+ $item->icon = jApp::config()->urlengine['jelixWWWPath'] . 'design/images/cog.png';
+ $event->add($item);
+ }
+ }
+}
@@ -0,0 +1,163 @@
+<?php
+/**
+* @package jelix_admin_modules
+* @subpackage jpref_admin
+* @author Florian Lonqueu-Brochard
+* @copyright 2012 Florian Lonqueu-Brochard
+* @link http://jelix.org
+* @licence http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file
+*/
+
+class prefsCtrl extends jController {
+
+ public $pluginParams=array(
+ '*' =>array('jacl2.right'=>'jprefs.prefs.list')
+ );
+
+
+ /**
+ *
+ */
+ public function index(){
+ $rep = $this->getResponse('html');
+
+ $tpl = new jTpl();
+ $tpl->assign('prefs',jPrefManager::getAllPreferences());
+ $rep->body->assign('MAIN', $tpl->fetch('prefs_index'));
+
+ return $rep;
+ }
+
+
+ /**
+ *
+ */
+ public function edit(){
+ $rep = $this->getResponse('html');
+ $id = $this->param('id', 0);
+
+
+ $pref = jPrefManager::getPref($id);
+
+ if(!$pref){
+ $rep = $this->getResponse('redirect');
+ $rep->action = 'jpref_admin~prefs:index';
+ return $rep;
+ }
+
+ if(!$pref->isWritable() ){
+ $rep = $this->getResponse('redirect');
+ $rep->action = 'jpref_admin~prefs:index';
+ jMessage::add(jLocale::get('jelix~errors.acl.action.right.needed'), 'error');
+ return $rep;
+ }
+
+ $form = jForms::create('jpref_admin~pref', $id);
+
+ $ctrls = array('integer', 'string', 'boolean', 'decimal');
+ foreach($ctrls as $c){
+ $form->deactivate($c);
+ }
+ $form->deactivate($pref->type, false);
+
+ $label = !empty($pref->locale) ? jLocale::get($pref->locale) : $pref->id;
+ $control = $form->getControl($pref->type);
+ $control->label = $label;
+ if($pref->type != 'boolean')
+ $control->help = jLocale::get('jpref_admin~admin.help.'.$pref->type);
+ if(!empty($pref->value))
+ $form->setData($pref->type, $pref->value);
+
+ $tpl = new jTpl();
+ $tpl->assign('form', $form);
+ $tpl->assign('title', jLocale::get('jpref_admin~admin.pref.edit', array($label)));
+ $tpl->assign('id', $id);
+ $tpl->assign('field', $pref->type);
+ $rep->body->assign('MAIN', $tpl->fetch('pref_edit'));
+
+ return $rep;
+ }
+
+ /**
+ *
+ */
+ public function saveedit(){
+ $rep = $this->getResponse('redirect');
+ $rep->action = 'jpref_admin~prefs:index';
+
+ $id = $this->param('id', 0);
+ $field = $this->param('field');
+
+ $form = jForms::fill('jpref_admin~pref', $id);
+ if(!$form || !$id || !$field){
+ return $rep;
+ }
+
+
+ if(!$form->check()){
+ $form->setErrorOn($field, 'jpref_admin~admin.field.error');
+ $rep->action = 'jpref_admin~prefs:edit';
+ $rep->params = array('id' => $id);
+ return $rep;
+ }
+
+ $data = $form->getData($field);
+ if($field == 'boolean'){
+ if($data == 'false')
+ $data = false;
+ else
+ $data = true;
+ }
+ elseif ($field == 'integer')
+ $data = (int) $data;
+ elseif ($field == 'decimal')
+ $data = (float) $data;
+
+ jPref::set($id, $data);
+
+ jMessage::add(jLocale::get('jpref_admin~admin.message.pref.updated'), 'notice');
+ return $rep;
+ }
+
+
+
+ /**
+ *
+ */
+ public function reset(){
+ $rep = $this->getResponse('redirect');
+ $rep->action = 'jpref_admin~prefs:index';
+
+ $id = $this->param('id', 0);
+
+ $pref = jPrefManager::getPref($id);
+ if(!$id || !$pref || (empty($pref->default_value) && $pref->type != 'boolean')){
+ return $rep;
+ }
+
+ if(!$pref->isWritable() ){
+ jMessage::add(jLocale::get('jelix~errors.acl.action.right.needed'), 'error');
+ return $rep;
+ }
+
+
+ $dvalue = $pref->default_value;
+ if ($pref->type == 'integer')
+ $dvalue = (int) $dvalue;
+ elseif ($pref->type == 'decimal')
+ $dvalue = (float) $dvalue;
+ elseif ($pref->type == 'boolean'){
+ if($dvalue == 'false')
+ $dvalue= false;
+ else if($dvalue == 'true')
+ $dvalue = true;
+ }
+
+ jPref::set($pref->id, $dvalue);
+
+ jMessage::add(jLocale::get('jpref_admin~admin.message.pref.reseted'), 'notice');
+ return $rep;
+
+ }
+}
+
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<events xmlns="http://jelix.org/ns/events/1.0">
+ <listener name="jpref_admin">
+ <event name="masteradminGetMenuContent" />
+ </listener>
+</events>
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<form xmlns="http://jelix.org/ns/forms/1.1">
+
+ <input ref="string">
+ <label>.</label>
+ </input>
+
+ <input ref="integer" type="integer">
+ <label>.</label>
+ </input>
+
+ <input ref="decimal" type="decimal">
+ <label>.</label>
+ </input>
+
+ <radiobuttons ref="boolean">
+ <label>.</label>
+ <item value="true" locale="jelix~ui.buttons.yes"/>
+ <item value="false" locale="jelix~ui.buttons.no"/>
+ </radiobuttons>
+
+ <submit ref="submit">
+ <label>Ok</label>
+ </submit>
+
+</form>
@@ -0,0 +1,21 @@
+<?php
+/**
+* @package jelix_admin_modules
+* @subpackage jpref_admin
+* @author Florian Lonqueu-Brochard
+* @copyright 2011 Florian Lonqueu-Brochard
+* @link http://jelix.org
+* @licence http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file
+*/
+
+
+class jpref_adminModuleInstaller extends jInstallerModule {
+
+ function install() {
+ if ($this->firstExec('acl2')) {
+ jAcl2DbManager::addSubjectGroup('jprefs.prefs.management', 'jPref~admin.acl.grp.prefs.management');
+ jAcl2DbManager::addSubject('jprefs.prefs.list', 'jPref~admin.acl.prefs.list', 'jprefs.prefs.management');
+ jAcl2DbManager::addRight('admins', 'jprefs.prefs.list'); // for admin group
+ }
+ }
+}
@@ -0,0 +1,26 @@
+item.title = Preferences
+
+acl.grp.prefs.management = Preferences management
+acl.prefs.list = Show the preferences list
+
+prefs.list = Preferences list
+pref.edit = Modification of "%s"
+
+group.others = Others
+type.not.allowed = "%s" is a not allowed type for a preference. Allowed types are : "%s"
+no.prefs = There is no preference
+
+ui.pref.name = Name
+ui.pref.value = Value
+ui.pref.edit = Edit
+ui.pref.reset = Reset to
+
+message.cant.edit.pref = You can't edit this preference
+message.pref.updated = The preference has been updated
+message.pref.reseted = The preference has been reseted
+
+help.integer = Integer
+help.decimal = Number with or without comma
+help.string = String
+
+field.error = The field is invalid
@@ -0,0 +1,26 @@
+item.title = Préférences
+
+acl.grp.prefs.management = Gestion des préférences
+acl.prefs.list = Voir la liste des préférences
+
+prefs.list = Liste des préférences
+pref.edit = Modification de "%s"
+
+group.others = Autres
+type.not.allowed = "%s" n'est pas un type autorisé pour une préférence. Les types autorisés sont : "%s"
+no.prefs = Il n'y a aucune préférence
+
+ui.pref.name = Nom
+ui.pref.value = Valeur
+ui.pref.edit = Modifier
+ui.pref.reset = Réinitialiser à
+
+message.cant.edit.pref = Vous ne pouvez pas modifier cette préférence
+message.pref.updated = La préférence a été mise à jour
+message.pref.reseted = La préférence a été réinitialisé
+
+help.integer = Nombre entier
+help.decimal = Nombre avec ou sans virgule
+help.string = Chaîne de caractères
+
+field.error = La saisie est invalide
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module xmlns="http://jelix.org/ns/module/1.0">
+ <info id="jpref_admin@jelix.org" name="jpref_admin" createdate="2012-01-21">
+ <version stability="stable" date="2012-01-21">1.0</version>
+ <label lang="en_EN">jPref</label>
+ <description lang="en_EN" />
+ <license URL="http://www.gnu.org/licenses/lgpl.html">GNU Lesser General Public Licence</license>
+ <copyright>2011 Florian Lonqueu-Brochard</copyright>
+ <creator name="Florian Lonqueu-Brochard" email="dev@florianlb.fr" active="true"/>
+ <!--<contributor name="hisname" email="hisemail@yoursite.undefined" active="true" since="" role=""/>-->
+ <homepageURL>http://jelix.org</homepageURL>
+ </info>
+ <dependencies>
+#expand <jelix minversion="1.4pre.*" maxversion="__LIB_VERSION_MAX__"/>-->
+ </dependencies>
+</module>
@@ -0,0 +1,6 @@
+<h1>{$title}</h1>
+
+{formfull $form, 'jpref_admin~prefs:saveedit', array('id' => $id, 'field' => $field)}
+
+<hr />
+<p><a href="{jurl 'jpref_admin~prefs:index'}" class="crud-link">{@jelix~crud.link.return.to.list@}</a></p>
Oops, something went wrong.

0 comments on commit ce7b54d

Please sign in to comment.