Explorar o código

N°635 Portal: Parameter to show submit ("Update") button in forms only when there is no transition available.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@4724 a333f486-631f-4898-b8df-5754b55c2be0
glajarige %!s(int64=8) %!d(string=hai) anos
pai
achega
b7d1f21748

+ 17 - 2
datamodels/2.x/itop-portal-base/portal/src/controllers/objectcontroller.class.inc.php

@@ -471,14 +471,18 @@ class ObjectController extends AbstractController
 				$oObject = MetaModel::GetObject($sObjectClass, $sObjectId, true, $oApp['scope_validator']->IsAllDataAllowedForScope(UserRights::ListProfiles(), $sObjectClass));
 			}
 
-			// Preparing transitions only if we are currently going through one
+			// Preparing buttons
 			$aFormData['buttons'] = array(
 				'transitions' => array(),
                 'actions' => array(),
                 'links' => array(),
+                'submit' => array(
+                    'label' => Dict::S('Portal:Button:Submit'),
+                ),
 			);
 			if ($sMode !== 'apply_stimulus')
 			{
+			    // Add transition buttons
 				$oSetToCheckRights = DBObjectSet::FromObject($oObject);
 				$aStimuli = Metamodel::EnumStimuli($sObjectClass);
 				foreach ($oObject->EnumTransitions() as $sStimulusCode => $aTransitionDef)
@@ -491,7 +495,7 @@ class ObjectController extends AbstractController
 					}
 				}
 
-                // Add plugins buttons
+                // Add plugin buttons
                 foreach (MetaModel::EnumPlugins('iPopupMenuExtension') as $oExtensionInstance)
                 {
                     foreach($oExtensionInstance->EnumItems(iPopupMenuExtension::PORTAL_OBJDETAILS_ACTIONS, array('portal_id' => $oApp['combodo.portal.instance.id'], 'object' => $oObject)) as $oMenuItem)
@@ -509,7 +513,18 @@ class ObjectController extends AbstractController
                         }
                     }
                 }
+
+                // Hiding submit button or changing its label if necessary
+                if($aFormProperties['properties']['always_show_submit'] === false)
+                {
+                    unset($aFormData['buttons']['submit']);
+                }
+                elseif($sMode === static::ENUM_MODE_EDIT)
+                {
+                    $aFormData['buttons']['submit']['label'] = Dict::S('Portal:Button:Apply');
+                }
 			}
+
 			// Preparing callback urls
 			$aCallbackUrls = $oApp['context_manipulator']->GetCallbackUrls($oApp, $aActionRules, $oObject, $bModal);
 			$aFormData['submit_callback'] = $aCallbackUrls['submit'];

+ 19 - 1
datamodels/2.x/itop-portal-base/portal/src/helpers/applicationhelper.class.inc.php

@@ -848,8 +848,25 @@ class ApplicationHelper
 				// Parsing form object class
 				if ($oFormNode->GetUniqueElement('class')->GetText() !== null)
 				{
+				    // Parsing class
 					$sFormClass = $oFormNode->GetUniqueElement('class')->GetText();
 
+                    // Parsing properties
+                    $aFormProperties = array(
+                        'always_show_submit' => false,
+                    );
+                    if($oFormNode->GetOptionalElement('properties') !== null)
+                    {
+                        foreach($oFormNode->GetOptionalElement('properties')->childNodes as $oPropertyNode)
+                        {
+                            switch($oPropertyNode->nodeName)
+                            {
+                                case 'always_show_submit':
+                                    $aFormProperties['always_show_submit'] = ($oPropertyNode->GetText('false') === 'true') ? true : false;
+                            }
+                        }
+                    }
+
 					// Parsing availables modes for that form (view, edit, create)
 					if (($oFormNode->GetOptionalElement('modes') !== null) && ($oFormNode->GetOptionalElement('modes')->GetNodes('mode')->length > 0))
 					{
@@ -875,6 +892,7 @@ class ApplicationHelper
 					$aFields = array(
 						'id' => $oFormNode->getAttribute('id'),
 						'type' => null,
+                        'properties' => $aFormProperties,
 						'fields' => null,
 						'layout' => null
 					);
@@ -955,7 +973,7 @@ class ApplicationHelper
 							throw new DOMFormatException('There is already a form for the class "' . $sFormClass . '" in "' . $sMode . '"', null, null, $oFormNode);
 						}
 					}
-				}
+                }
 				else
 				{
 					throw new DOMFormatException('Class tag must be defined', null, null, $oFormNode);

+ 6 - 4
datamodels/2.x/itop-portal-base/portal/src/views/bricks/object/mode_create.html.twig

@@ -42,10 +42,12 @@
 						<span class="glyphicon glyphicon-remove"></span>
 						{{ 'Portal:Button:Cancel'|dict_s }}
 					</button>
-					<button class="btn btn-primary form_btn_submit" type="submit" value="submit" title="{{ 'Portal:Button:Submit'|dict_s }}">
-						<span class="glyphicon glyphicon-ok"></span>
-						{{ 'Portal:Button:Submit'|dict_s }}
-					</button>
+					{% if form.buttons.submit is defined %}
+						<button class="btn btn-primary form_btn_submit" type="submit" value="submit" title="{{ form.buttons.submit.label }}">
+							<span class="glyphicon glyphicon-ok"></span>
+							{{ form.buttons.submit.label }}
+						</button>
+					{% endif %}
 				{% else %}
 					{# Modal mode #}
 					{% if tIsModal %}

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

@@ -1321,6 +1321,10 @@
 				</form>
 				<form id="ticket-edit">
 					<class>Ticket</class>
+					<properties>
+						<!-- When set to false, submit button is hidden when transitions are available on the object (in edit mode only). Default is false. -->
+						<!--<always_show_submit>false</always_show_submit>-->
+					</properties>
 					<fields></fields>
 					<twig>
 						<div class="row">