Преглед на файлове

N°873 Portal: Picture/Preferences/Password forms can now be disabled in the user profile

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@4752 a333f486-631f-4898-b8df-5754b55c2be0
glajarige преди 8 години
родител
ревизия
00c6fef0da

+ 75 - 4
datamodels/2.x/itop-portal-base/portal/src/entities/userprofilebrick.class.inc.php

@@ -1,5 +1,5 @@
 <?php
-// Copyright (C) 2010-2015 Combodo SARL
+// Copyright (C) 2010-2017 Combodo SARL
 //
 //   This file is part of iTop.
 //
@@ -36,9 +36,15 @@ class UserProfileBrick extends PortalBrick
 	const DEFAUT_TITLE = 'Brick:Portal:UserProfile:Title';
 	const DEFAULT_HOME_ICON_CLASS = 'glyphicon glyphicon-user';
 	const DEFAULT_NAVIGATION_MENU_ICON_CLASS = 'glyphicon glyphicon-user';
+    const DEFAULT_SHOW_PICTURE_FORM = true;
+    const DEFAULT_SHOW_PREFERENCES_FORM = true;
+    const DEFAULT_SHOW_PASSWORD_FORM = true;
 
 	static $sRouteName = 'p_user_profile_brick';
 	protected $aForm;
+	protected $bShowPictureForm;
+	protected $bShowPreferencesForm;
+	protected $bShowPasswordForm;
 
 	public function __construct()
 	{
@@ -50,6 +56,9 @@ class UserProfileBrick extends PortalBrick
 			'fields' => 'details',
 			'layout' => null
 		);
+		$this->bShowPictureForm = static::DEFAULT_SHOW_PICTURE_FORM;
+		$this->bShowPreferencesForm = static::DEFAULT_SHOW_PREFERENCES_FORM;
+		$this->bShowPasswordForm = static::DEFAULT_SHOW_PASSWORD_FORM;
 	}
 
 	/**
@@ -72,6 +81,60 @@ class UserProfileBrick extends PortalBrick
 		return $this;
 	}
 
+    /**
+     * @return bool
+     */
+    public function GetShowPictureForm()
+    {
+        return $this->bShowPictureForm;
+    }
+
+    /**
+     * @param $bShowPictureForm
+     * @return \Combodo\iTop\Portal\Brick\UserProfileBrick
+     */
+    public function SetShowPictureForm($bShowPictureForm)
+    {
+        $this->bShowPictureForm = $bShowPictureForm;
+        return $this;
+    }
+
+    /**
+     * @return bool
+     */
+    public function GetShowPreferencesForm()
+    {
+        return $this->bShowPreferencesForm;
+    }
+
+    /**
+     * @param $bShowPreferencesForm
+     * @return \Combodo\iTop\Portal\Brick\UserProfileBrick
+     */
+    public function SetShowPreferencesForm($bShowPreferencesForm)
+    {
+        $this->bShowPreferencesForm = $bShowPreferencesForm;
+        return $this;
+    }
+
+    /**
+     * @return bool
+     */
+    public function GetShowPasswordForm()
+    {
+        return $this->bShowPasswordForm;
+    }
+
+    /**
+     * @param $bShowPasswordForm
+     * @return \Combodo\iTop\Portal\Brick\UserProfileBrick
+     */
+    public function SetShowPasswordForm($bShowPasswordForm)
+    {
+        $this->bShowPasswordForm = $bShowPasswordForm;
+        return $this;
+    }
+
 	/**
 	 * Load the brick's data from the xml passed as a ModuleDesignElement.
 	 * This is used to set all the brick attributes at once.
@@ -121,7 +184,7 @@ class UserProfileBrick extends PortalBrick
 							}
 							else
 							{
-								throw new DOMFormatException('Field tag must have an id attribute', null, null, $oFormNode);
+								throw new DOMFormatException('Field tag must have an id attribute', null, null, $oFieldNode);
 							}
 						}
 					}
@@ -140,6 +203,16 @@ class UserProfileBrick extends PortalBrick
 						);
 					}
 					break;
+
+                case 'show_picture_form':
+                case 'show_preferences_form':
+                case 'show_password_form':
+                    $sConstName = 'DEFAULT_'.strtoupper($oBrickSubNode->nodeName);
+                    $sSetterName = 'Set'.str_replace('_', '', ucwords($oBrickSubNode->nodeName, '_'));
+
+                    $bNodeValue = ($oBrickSubNode->GetText(constant('static::'.$sConstName)) === 'true') ? true : false;
+                    $this->$sSetterName($bNodeValue);
+                    break;
 			}
 		}
 
@@ -147,5 +220,3 @@ class UserProfileBrick extends PortalBrick
 	}
 
 }
-
-?>

+ 69 - 63
datamodels/2.x/itop-portal-base/portal/src/views/bricks/user-profile/layout.html.twig

@@ -44,85 +44,91 @@
 					</div>
 				</div>
 				<div class="col-sm-6">
-					{% block pUserProfilePictureFormContainer %}
-						<div class="panel panel-default user_profile_picture">
-							<div class="panel-heading">
-								<h3 class="panel-title">{{ 'Brick:Portal:UserProfile:Photo:Title'|dict_s }}</h3>
-							</div>
-							<div class="panel-body" style="position: relative;">
-								<div class="form_alerts">
-									<div class="alert alert-success" role="alert" style="display: none;"></div>
-									<div class="alert alert-warning" role="alert" style="display: none;"></div>
-									<div class="alert alert-error alert-danger" role="alert" style="display: none;"></div>
+					{% if oBrick.GetShowPictureForm() %}
+						{% block pUserProfilePictureFormContainer %}
+							<div class="panel panel-default user_profile_picture">
+								<div class="panel-heading">
+									<h3 class="panel-title">{{ 'Brick:Portal:UserProfile:Photo:Title'|dict_s }}</h3>
 								</div>
-								<form id="picture-form" method="POST" action="{{ app['url_generator'].generate('p_user_profile_brick') }}">
-									<input type="hidden" name="current_values[form_type]" value="{{ constant('\\Combodo\\iTop\\Portal\\Controller\\UserProfileBrickController::ENUM_FORM_TYPE_PICTURE') }}" />
-									<input type="hidden" name="operation" value="submit" />
-									<div class="text-center">
-										<span class="preview">
-											<img src="{{ sUserPhotoUrl }}"/>
-										</span>
-										<span class="actions">
-											<span type="button" class="btn btn-default btn_edit">
-												<span class="fa fa-pencil fa-fw"></span>
-												<input id="picture" type="file" name="picture" />
-											</span>
-											{#<button type="button" class="btn btn-default btn_undo" title="{{ 'UI:Button:ResetImage'|dict_s }}" disabled>
-												<span class="fa fa-undo fa-fw"></span>
-											</button>
-											<button type="button" class="btn btn-default btn_reset" title="{{ 'UI:Button:RemoveImage'|dict_s }}">
-												<span class="fa fa-trash-o fa-fw"></span>
-											</button>#}
-										</span>
-									</div>
-								</form>
-							</div>
-						</div>
-					{% endblock %}
-
-					{% block pUserProfilePreferencesFormContainer %}
-						<div class="panel panel-default">
-							<div class="panel-heading">
-								<h3 class="panel-title">{{ 'Class:appUserPreferences/Attribute:preferences'|dict_s }}</h3>
-							</div>
-							<div class="panel-body">
-								<form id="{{ oPreferencesForm.id }}" class="" method="POST" action="{{ oPreferencesForm.renderer.GetEndpoint()|raw }}">
+								<div class="panel-body" style="position: relative;">
 									<div class="form_alerts">
 										<div class="alert alert-success" role="alert" style="display: none;"></div>
 										<div class="alert alert-warning" role="alert" style="display: none;"></div>
 										<div class="alert alert-error alert-danger" role="alert" style="display: none;"></div>
 									</div>
-									<div class="form_fields">
-										{{ oPreferencesForm.renderer.GetBaseLayout()|raw }}
-									</div>
-								</form>
-							</div>
-						</div>
-					{% endblock %}
-
-					{% block pUserProfilePasswordFormContainer %}
-						<div class="panel panel-default">
-							<div class="panel-heading">
-								<h3 class="panel-title">{{ 'Brick:Portal:UserProfile:Password:Title'|dict_s }}</h3>
+									<form id="picture-form" method="POST" action="{{ app['url_generator'].generate('p_user_profile_brick') }}">
+										<input type="hidden" name="current_values[form_type]" value="{{ constant('\\Combodo\\iTop\\Portal\\Controller\\UserProfileBrickController::ENUM_FORM_TYPE_PICTURE') }}" />
+										<input type="hidden" name="operation" value="submit" />
+										<div class="text-center">
+											<span class="preview">
+												<img src="{{ sUserPhotoUrl }}"/>
+											</span>
+											<span class="actions">
+												<span type="button" class="btn btn-default btn_edit">
+													<span class="fa fa-pencil fa-fw"></span>
+													<input id="picture" type="file" name="picture" />
+												</span>
+												{#<button type="button" class="btn btn-default btn_undo" title="{{ 'UI:Button:ResetImage'|dict_s }}" disabled>
+													<span class="fa fa-undo fa-fw"></span>
+												</button>
+												<button type="button" class="btn btn-default btn_reset" title="{{ 'UI:Button:RemoveImage'|dict_s }}">
+													<span class="fa fa-trash-o fa-fw"></span>
+												</button>#}
+											</span>
+										</div>
+									</form>
+								</div>
 							</div>
-							<div class="panel-body">
-								{% if oPasswordForm is not null %}
-									<form id="{{ oPasswordForm.id }}" class="" method="POST" action="{{ oPasswordForm.renderer.GetEndpoint()|raw }}" autocomplete="off">
+						{% endblock %}
+					{% endif %}
+
+            		{% if oBrick.GetShowPreferencesForm() %}
+						{% block pUserProfilePreferencesFormContainer %}
+							<div class="panel panel-default">
+								<div class="panel-heading">
+									<h3 class="panel-title">{{ 'Class:appUserPreferences/Attribute:preferences'|dict_s }}</h3>
+								</div>
+								<div class="panel-body">
+									<form id="{{ oPreferencesForm.id }}" class="" method="POST" action="{{ oPreferencesForm.renderer.GetEndpoint()|raw }}">
 										<div class="form_alerts">
 											<div class="alert alert-success" role="alert" style="display: none;"></div>
 											<div class="alert alert-warning" role="alert" style="display: none;"></div>
 											<div class="alert alert-error alert-danger" role="alert" style="display: none;"></div>
 										</div>
 										<div class="form_fields">
-											{{ oPasswordForm.renderer.GetBaseLayout()|raw }}
+											{{ oPreferencesForm.renderer.GetBaseLayout()|raw }}
 										</div>
 									</form>
-								{% else %}
-									{{ 'Brick:Portal:UserProfile:Password:CantChangeContactAdministrator'|dict_s }}
-								{% endif %}
+								</div>
 							</div>
-						</div>
-					{% endblock %}
+						{% endblock %}
+					{% endif %}
+
+					{% if oBrick.GetShowPasswordForm() %}
+						{% block pUserProfilePasswordFormContainer %}
+							<div class="panel panel-default">
+								<div class="panel-heading">
+									<h3 class="panel-title">{{ 'Brick:Portal:UserProfile:Password:Title'|dict_s }}</h3>
+								</div>
+								<div class="panel-body">
+									{% if oPasswordForm is not null %}
+										<form id="{{ oPasswordForm.id }}" class="" method="POST" action="{{ oPasswordForm.renderer.GetEndpoint()|raw }}" autocomplete="off">
+											<div class="form_alerts">
+												<div class="alert alert-success" role="alert" style="display: none;"></div>
+												<div class="alert alert-warning" role="alert" style="display: none;"></div>
+												<div class="alert alert-error alert-danger" role="alert" style="display: none;"></div>
+											</div>
+											<div class="form_fields">
+												{{ oPasswordForm.renderer.GetBaseLayout()|raw }}
+											</div>
+										</form>
+									{% else %}
+										{{ 'Brick:Portal:UserProfile:Password:CantChangeContactAdministrator'|dict_s }}
+									{% endif %}
+								</div>
+							</div>
+						{% endblock %}
+					{% endif %}
 				</div>
 			</div>
 			<div class="form_buttons">

+ 4 - 0
datamodels/2.x/itop-tickets/datamodel.itop-tickets.xml

@@ -1013,6 +1013,10 @@
 					<decoration_class>
 						<default>fa fa-user fa-2x</default>
 					</decoration_class>
+					<!-- Show / hide some of the user profile forms by setting the tag value to true|false -->
+					<!--<show_picture_form>true</show_picture_form>-->
+					<!--<show_preferences_form>true</show_preferences_form>-->
+					<!--<show_password_form>true</show_password_form>-->
 					<form>
 						<!-- Optionnal tag to list the fields. If empty only fields from <twig> tag will be displayed, if ommited fields from zlist details will. -->
 						<fields />