commit 020158f5f6a992936b5d27bc84d1effb3f65dfaf
parent dbde40cf76ee5071a38a1e1c7c6c5e2ab173b494
Author: Felicitus <felicitus@felicitus.org>
Date: Fri, 2 Sep 2011 00:45:08 +0200
Added user preference panel
Diffstat:
4 files changed, 60 insertions(+), 15 deletions(-)
diff --git a/frontend/js/Components/User/UserEditor.js b/frontend/js/Components/User/UserEditor.js
@@ -1,16 +1,42 @@
Ext.define('PartKeepr.UserEditor', {
extend: 'PartKeepr.Editor',
alias: 'widget.UserEditor',
- items: [{
- xtype: 'textfield',
- name: 'username',
- fieldLabel: i18n("User")
- },{
- xtype: 'textfield',
- inputType: "password",
- name: 'password',
- fieldLabel: i18n("Password")
- }],
+
saveText: i18n("Save User"),
- model: 'PartKeepr.User'
+ model: 'PartKeepr.User',
+
+ initComponent: function () {
+ this.gridPanel = Ext.create("PartKeepr.UserPreferenceGrid");
+
+ var container = Ext.create("Ext.form.FieldContainer", {
+ fieldLabel: i18n("User Preferences"),
+ labelWidth: 150,
+ layout: 'fit',
+ height: 200,
+ items: this.gridPanel
+ });
+
+ this.items = [{
+ xtype: 'textfield',
+ name: 'username',
+ fieldLabel: i18n("User")
+ },{
+ xtype: 'textfield',
+ inputType: "password",
+ name: 'password',
+ fieldLabel: i18n("Password")
+ }, container ];
+
+ this.on("startEdit", this.onStartEdit, this);
+ this.callParent();
+ },
+ onStartEdit: function () {
+ this.gridPanel.store.getProxy().extraParams.user_id = this.record.get("id");
+ this.gridPanel.store.load();
+ },
+ onItemSave: function () {
+ this.gridPanel.syncPreferences();
+
+ this.callParent();
+ }
});
diff --git a/frontend/js/Models/UserPreference.js b/frontend/js/Models/UserPreference.js
@@ -2,7 +2,8 @@ Ext.define("PartKeepr.UserPreference", {
extend: "Ext.data.Model",
fields: [
{ name: 'key', type: 'string'},
- { name: 'value'}
+ { name: 'value'},
+ { name: 'user_id', type: 'int'}
],
proxy: PartKeepr.getRESTProxy("UserPreference")
});
\ No newline at end of file
diff --git a/src/de/RaumZeitLabor/PartKeepr/UserPreference/UserPreference.php b/src/de/RaumZeitLabor/PartKeepr/UserPreference/UserPreference.php
@@ -97,7 +97,8 @@ class UserPreference implements Serializable {
public function serialize () {
return array(
"key" => $this->getKey(),
- "value" => $this->getValue()
+ "value" => $this->getValue(),
+ "user_id" => $this->getUser()->getId()
);
}
diff --git a/src/de/RaumZeitLabor/PartKeepr/UserPreference/UserPreferenceService.php b/src/de/RaumZeitLabor/PartKeepr/UserPreference/UserPreferenceService.php
@@ -34,7 +34,18 @@ class UserPreferenceService extends Service implements RestfulService {
$dql = "SELECT up FROM de\RaumZeitLabor\PartKeepr\UserPreference\UserPreference up WHERE up.user = :user";
$query = PartKeepr::getEM()->createQuery($dql);
- $query->setParameter("user", SessionManager::getCurrentSession()->getUser());
+
+ if ($this->hasParameter("user_id") && SessionManager::getCurrentSession()->getUser()->isAdmin()) {
+ if ($this->getParameter("user_id") != 0) {
+ $query->setParameter("user", User::loadById($this->getParameter("user_id")));
+ } else {
+ $query->setParameter("user", 0);
+ }
+
+ } else {
+ $query->setParameter("user", SessionManager::getCurrentSession()->getUser());
+ }
+
foreach ($query->getResult() as $result) {
$aPreferences[] = $result->serialize();
@@ -72,6 +83,12 @@ class UserPreferenceService extends Service implements RestfulService {
* @see de\RaumZeitLabor\PartKeepr\Service.RestfulService::destroy()
*/
public function destroy () {
- UserPreference::deletePreference($this->getUser(), $this->getParameter("key"));
+ if ($this->hasParameter("user_id") && SessionManager::getCurrentSession()->getUser()->isAdmin()) {
+ UserPreference::deletePreference(User::loadById($this->getParameter("user_id")), $this->getParameter("key"));
+ } else {
+ UserPreference::deletePreference($this->getUser(), $this->getParameter("key"));
+ }
+
+
}
}
\ No newline at end of file