Skip to content
Browse files

Tweaks

  • Loading branch information...
1 parent 6e690fe commit b1520a969673e05f67253e9914c99d3ad7f1fa38 Jerry Ablan committed Feb 14, 2012
View
31 extensions/pogostick/controllers/CPSController.php
@@ -1063,12 +1063,6 @@ public function setStandardFormOptions( $model, $options = array() )
$model = PS::o( $options, 'model' );
}
- // Set the standard nav options
- if ( false !== PS::o( $options, 'viewNavigation', true ) )
- {
- $this->setViewNavigationOptions( $options );
- }
-
$_formId = PS::o( $options, 'id', 'ps-edit-form' );
// Put a cool flash span on the page
@@ -1095,16 +1089,21 @@ public function setStandardFormOptions( $model, $options = array() )
if ( $_flashText )
{
$_fader = <<<SCRIPT
-notify('default',{title:'{$_flashTitle}',text:'{$_flashText}'});
-//$('#___spanId_').fadeIn('500',function(){
-// $(this).delay(3000).fadeOut(3500);
-//});";
+//notify('default',{title:'{$_flashTitle}',text:'{$_flashText}'});
+$('span.{$_flashClass}').fadeIn('500',function(){
+ $(this).delay(3000).fadeOut(3500);
+});
SCRIPT;
-
PS::_rs( $_formId . '.' . $_spanId . '.fader', $_fader, CClientScript::POS_READY );
}
}
+ // Set the standard nav options
+ if ( false !== PS::o( $options, 'viewNavigation', true ) )
+ {
+ $this->setViewNavigationOptions( $options );
+ }
+
$_formOptions = array(
'id' => $_formId,
'showLegend' => PS::o( $options, 'showLegend', true ),
@@ -1143,7 +1142,7 @@ public function setStandardFormOptions( $model, $options = array() )
{
if ( false !== $_link )
{
- $_trail .= '<li><a>' . $_name . '</a> <span class="divider">/</span></li>';
+ $_trail .= '<li><a href="' . $_link . '">' . $_name . '</a> <span class="divider">/</span></li>';
}
else
{
@@ -1223,6 +1222,8 @@ public function setViewNavigationOptions( &$options = array() )
$_title = PS::o( $options, 'title', null, true );
$_subtitle = PS::o( $options, 'subtitle', null, true );
+ $_flash = PS::_gs( 'psForm-flash-html' );
+
// Do some auto-page-setup...
if ( false !== ( $_header = PS::o( $options, 'header' ) ) )
{
@@ -1235,7 +1236,11 @@ public function setViewNavigationOptions( &$options = array() )
{
if ( null !== ( $_headerIcon = PS::o( $options, 'headerIcon', null, true ) ) )
{
- $_header = PS::tag( 'div', array( 'class' => 'ps-form-header-title' ), PS::tag( 'span', array(), PS::image( $_headerIcon ) ) . $_header );
+ $_header =
+ PS::tag( 'div', array( 'class' => 'ps-form-header-title' ), $_flash .
+ PS::tag( 'span', array(), PS::image( $_headerIcon ) ) . $_header );
+
+ PS::_ss( 'psForm-flash-html', $_flash = null );
}
$options['header'] = PS::tag( 'h1', array( 'class' => 'ui-generated-header' ), $_header );
View
171 extensions/pogostick/helpers/CPSForm.php
@@ -10,12 +10,12 @@
/**
* CPSForm provides form helper functions
*
- * @package psYiiExtensions
- * @subpackage helpers
+ * @package psYiiExtensions
+ * @subpackage helpers
*
- * @author Jerry Ablan <jablan@pogostick.com>
- * @version SVN: $Id: CPSForm.php 404 2010-10-16 00:50:38Z jerryablan@gmail.com $
- * @since v1.0.5
+ * @author Jerry Ablan <jablan@pogostick.com>
+ * @version SVN: $Id: CPSForm.php 404 2010-10-16 00:50:38Z jerryablan@gmail.com $
+ * @since v1.0.5
*
* @filesource
*
@@ -36,25 +36,29 @@ class CPSForm implements IPSBase
protected static $m_sSearchFieldLabelTemplate = '<label class="ps-form-search-label" for="{fieldId}">{title}</label>';
protected static $m_sSearchFieldTemplate = '{label}<span class="ps-form-search-field ui-widget-container">{field}</span>';
+ protected static $lastErrorSummary = null;
//********************************************************************************
//* Public Methods
//********************************************************************************
/**
- * Creates a form from an option array
- *
- * @param array $arOptions
- * @return string
- * @todo document this function
- */
+ * Creates a form from an option array
+ *
+ * @param array $arOptions
+ * @return string
+ * @todo document this function
+ */
public static function create( &$arOptions = array() )
{
+ self::$lastErrorSummary = null;
$_bHaveButtonBar = false;
// Make sure we have some form fields...
- if ( ! $_arFields = PS::o( $arOptions, 'fields', null, true ) )
+ if ( !$_arFields = PS::o( $arOptions, 'fields', null, true ) )
+ {
throw new CPSException( 'You must define form fields to use this method.' );
+ }
// Return as string?
$_bReturnString = PS::o( $arOptions, 'returnString', false, true );
@@ -66,28 +70,35 @@ public static function create( &$arOptions = array() )
$_errorSummaryHeader = PS::o( $_errorSummaryOptions, 'header', null, true );
$_sFormId = PS::o( $arOptions, 'id', 'ps-edit-form' );
$_eUIStyle = PS::o( $arOptions, 'uiStyle', PS::UI_DEFAULT );
+ $_errorSummaryOptions['uiStyle'] = $_eUIStyle;
- if ( ! isset( $arOptions['name'] ) ) $arOptions['name'] = $_sFormId;
+ if ( !isset( $arOptions['name'] ) )
+ {
+ $arOptions['name'] = $_sFormId;
+ }
// Our model?
$_oModel = PS::o( $arOptions, 'formModel', null, true );
+ $_sOut = null;
// Throw in a neato keano flash span
- if ( null === PS::_gs( 'psForm-flash-html' ) && ! PS::o( $arOptions, 'noFlash', false, true ) )
+ if ( null === PS::_gs( 'psForm-flash-html' ) && !PS::o( $arOptions, 'noFlash', false, true ) )
{
$_flashClass = PS::o( $options, 'flashSuccessClass', 'operation-result-success' );
if ( null === ( $_message = PS::_gf( 'success' ) ) )
{
if ( null !== ( $_message = PS::_gf( 'failure' ) ) )
+ {
$_flashClass = PS::o( $options, 'flashFailureClass', 'operation-result-failure' );
+ }
}
$_spanId = PS::o( $options, 'flashSpanId', 'operation-result', true );
PS::_ss( 'psForm-flash-html', PS::tag( 'span', array( 'id' => $_spanId, 'class' => $_flashClass ), $_message ) );
// Register a nice little fader...
- $_fader =<<<SCRIPT
+ $_fader = <<<SCRIPT
$('#{$_spanId}').fadeIn('500',function(){
$(this).delay(3000).fadeOut(3500);
});
@@ -96,12 +107,19 @@ public static function create( &$arOptions = array() )
PS::_rs( $_sFormId . '.' . $_spanId . '.fader', $_fader, CClientScript::POS_READY );
}
- // Let's begin...
- $_sOut = PS::beginFormEx( $arOptions );
-
// Error summary wanted?
if ( $_oModel && $_bErrorSummary )
- $_sOut .= PS::errorSummary( $_oModel, $_errorSummaryHeader, null, $_errorSummaryOptions );
+ {
+ self::$lastErrorSummary = PS::errorSummary( $_oModel, $_errorSummaryHeader, null, $_errorSummaryOptions );
+ }
+
+ // Let's begin...
+ $_sOut .= PS::beginFormEx( $arOptions );
+
+ if ( !PS::o( $arOptions, 'returnErrorSummary', false, true ) )
+ {
+ $_sOut = self::$lastErrorSummary . $_sOut;
+ }
// Now create form fields...
foreach ( $_arFields as $_arValue )
@@ -115,9 +133,14 @@ public static function create( &$arOptions = array() )
if ( $_sCondition = PS::o( $_arValue, 'condition', null, true ) )
{
if ( is_bool( $_sCondition ) )
+ {
$_bPassed = $_sCondition;
+ }
+
else
+ {
$_bPassed = eval( 'return(' . $_sCondition . ');' );
+ }
}
if ( $_bPassed )
@@ -131,7 +154,7 @@ public static function create( &$arOptions = array() )
case 'hidden':
case 'hiddenfield':
$_sType = 'hiddenfield';
- // Intentional drop through...
+ // Intentional drop through...
case 'beginfieldset':
case 'endfieldset':
@@ -142,7 +165,10 @@ public static function create( &$arOptions = array() )
// Fix up the argument array
$_arSubmit = ( is_array( $_arValue ) && count( $_arValue ) == 1 ) ? $_arValue[0] : $_arValue;
$_sLabel = PS::o( $_arSubmit, 'label', $_sType, true );
- if ( PS::UI_JQUERY == $_eUIStyle ) $_arSubmit['jqui'] = true;
+ if ( PS::UI_JQUERY == $_eUIStyle )
+ {
+ $_arSubmit['jqui'] = true;
+ }
$_arValue = array( $_sLabel, $_arSubmit, 'formId' => $_sFormId );
$_sOut .= call_user_func_array( array( 'PS', 'submitButtonBar' ), $_arValue );
$_bHaveButtonBar = true;
@@ -153,11 +179,11 @@ public static function create( &$arOptions = array() )
switch ( $_sType )
{
- case 'label': // No special array manipulation needed.
+ case 'label': // No special array manipulation needed.
$_sMethod = $_sType;
break;
- default: // Format for PS::field() call
+ default: // Format for PS::field() call
// Push model into the front of the array...
array_unshift( $_arValue, $_sType, $_oModel );
$_sMethod = 'field';
@@ -172,7 +198,8 @@ public static function create( &$arOptions = array() )
{
$_sFieldId = PS::getLastFieldId();
$_sFormId = PS::getCurrentFormId();
- $_sScript = "jQuery('#{$_sFormId}').submit(function(e){ jQuery('#{$_sFieldId}').val(CKEDITOR.instances.{$_sFieldId}.getData()); return true; });";
+ $_sScript =
+ "jQuery('#{$_sFormId}').submit(function(e){ jQuery('#{$_sFieldId}').val(CKEDITOR.instances.{$_sFieldId}.getData()); return true; });";
PS::_rs( '#psForm.ckeditor.' . $_sFieldId . '.get_data', $_sScript, CClientScript::POS_READY );
}
break;
@@ -181,8 +208,10 @@ public static function create( &$arOptions = array() )
}
// Does user want dates? Show 'em
- if ( $_bShowDates && $_oModel instanceof CPSModel && ! $_oModel->isNewRecord )
+ if ( $_bShowDates && $_oModel instanceof CPSModel && !$_oModel->isNewRecord )
+ {
$_sOut .= $_oModel->showDates();
+ }
// Add legend
$_requiredLabel = PS::getRequiredLabel();
@@ -196,7 +225,10 @@ public static function create( &$arOptions = array() )
$_sOut .= PS::endForm();
// Does user want data returned?
- if ( $_bReturnString ) return $_sOut;
+ if ( $_bReturnString )
+ {
+ return $_sOut;
+ }
// Guess not, just spit it out...
echo $_sOut;
@@ -242,9 +274,12 @@ public static function formHeaderEx( $sTitle, $arOptions = array() )
$_bIcon = false;
$_sClass = $_sLink = $_sOut = null;
$_sFlash = $bShowFlashDiv ? PS::flashMessage( 'success', true ) : null;
- $_sExtra = null;//'style="margin-bottom:' . ( $_sFlash ? '32px' : '10px' ) . '";"';
+ $_sExtra = null; //'style="margin-bottom:' . ( $_sFlash ? '32px' : '10px' ) . '";"';
- if ( $_sFlashMessage ) $_sFlashMessage = '<div class="ps-subheader-flash">' . $_sFlashMessage . '</div>';
+ if ( $_sFlashMessage )
+ {
+ $_sFlashMessage = '<div class="ps-subheader-flash">' . $_sFlashMessage . '</div>';
+ }
if ( in_array( 'menuButtons', $arOptions ) )
{
@@ -267,10 +302,12 @@ public static function formHeaderEx( $sTitle, $arOptions = array() )
// Can user have this item?
if ( $_sAccess && $_sAccess != Yii::app()->user->accessRole )
+ {
continue;
+ }
$_sLabel = PS::o( $_arItem, 'label', $sTitle, true );
- $_sLink = PS::normalizeUrl( PS::o( $_arItem, 'url', array('#'), true ) );
+ $_sLink = PS::normalizeUrl( PS::o( $_arItem, 'url', array( '#' ), true ) );
$_arItem['formId'] = $_sFormId;
$_sOut .= PS::jquiButton( $_sLabel, $_sLink, $_arItem );
}
@@ -288,23 +325,28 @@ public static function formHeaderEx( $sTitle, $arOptions = array() )
}
/**
- * Makes a nice form header
- * @deprecated Use formHeaderEx
- */
- public static function formHeader( $sTitle, $arMenuItems = array(), $sDivClass = 'ps-form-header', $bShowFlashDiv = true, $_sHtmlInjection = null )
+ * Makes a nice form header
+ * @deprecated Use formHeaderEx
+ */
+ public static function formHeader( $sTitle, $arMenuItems = array(), $sDivClass = 'ps-form-header', $bShowFlashDiv = true,
+ $_sHtmlInjection = null )
{
// Be nice and let people call this instead
- if ( in_array( 'menuItems', $arMenuItems ) ) return self::formHeaderEx( $sTitle, $arMenuItems );
+ if ( in_array( 'menuItems', $arMenuItems ) )
+ {
+ return self::formHeaderEx( $sTitle, $arMenuItems );
+ }
// Otherwise, screw you
- trigger_error( 'CPSForm::formHeader is deprecated. Please use formHeaderEx instead', defined( E_USER_DEPRECATED ) ? E_USER_DEPRECATED : E_USER_WARNING );
+ trigger_error( 'CPSForm::formHeader is deprecated. Please use formHeaderEx instead',
+ defined( E_USER_DEPRECATED ) ? E_USER_DEPRECATED : E_USER_WARNING );
}
/**
- * Output a generic search bar...
- *
- * @param mixed $arOptions
- */
+ * Output a generic search bar...
+ *
+ * @param mixed $arOptions
+ */
public static function searchBar( $arOptions = array() )
{
$_arFields = PS::o( $arOptions, 'fields', array(), true );
@@ -322,9 +364,15 @@ public static function searchBar( $arOptions = array() )
$_arTypeOptions['class'] = trim( $_sClass );
$_arTypeOptions['id'] = PS::o( $_arTypeOptions, 'id', PS::getWidgetId( self::SEARCH_PREFIX ) . '_' . $_eType );
- if ( ! is_numeric( $_eType ) ) $_arTypeOptions['size'] = PS::o( $_arTypeOptions, 'size', '15' );
+ if ( !is_numeric( $_eType ) )
+ {
+ $_arTypeOptions['size'] = PS::o( $_arTypeOptions, 'size', '15' );
+ }
- if ( $_sTitle ) $_sTitle .= ':';
+ if ( $_sTitle )
+ {
+ $_sTitle .= ':';
+ }
$_sField = PS::activefield( $_eType, null, $_sName, $_arTypeOptions, array(), $_arData );
$_sLabel = strtr( self::$m_sSearchFieldLabelTemplate, array( '{fieldId}' => $_arTypeOptions['id'], '{title}' => $_sTitle ) );
@@ -348,64 +396,74 @@ public static function createMenuButtons( $sItemName, $arWhich = array(), $sAdmi
{
$_arOut = array();
- if ( null === $sAdminName ) $sAdminName = ucfirst( $sItemName ) . ' Manager';
- if ( null === $sAdminAction ) $sAdminAction = array( 'admin' );
+ if ( null === $sAdminName )
+ {
+ $sAdminName = ucfirst( $sItemName ) . ' Manager';
+ }
+ if ( null === $sAdminAction )
+ {
+ $sAdminAction = array( 'admin' );
+ }
foreach ( $arWhich as $_sButton => $_arOptions )
{
- if ( is_numeric( $_sButton ) && ! is_array( $_arOptions ) )
+ if ( is_numeric( $_sButton ) && !is_array( $_arOptions ) )
+ {
$_sButton = $_arOptions;
+ }
$_iButton = CPSDataGrid::getMenuButtonType( $_sButton );
switch ( $_iButton )
{
case PS::ACTION_PREVIEW:
- $_arOut[ 'preview' ] = array(
+ $_arOut['preview'] = array(
'label' => 'Preview',
'url' => array( '#' ),
'icon' => 'lightbulb',
'id' => PS::o( $_arOptions, 'id' ),
);
if ( $_sTarget = PS::o( $_arOptions, 'target' ) )
+ {
$_arOut['preview']['onClick'] = '$(\'' . $_sTarget . '\').toggle(); return false;';
+ }
break;
case PS::ACTION_VIEW:
- $_arOut[ 'view' ] = array(
+ $_arOut['view'] = array(
'label' => 'View',
'url' => array( 'show' ),
'icon' => 'check',
);
break;
case PS::ACTION_CREATE:
- $_arOut[ 'new' ] = array(
+ $_arOut['new'] = array(
'label' => 'New ' . $sItemName,
'url' => array( 'create' ),
'icon' => 'pencil',
);
break;
case PS::ACTION_EDIT:
- $_arOut[ 'update' ] = array(
+ $_arOut['update'] = array(
'label' => intval( $_sButton ) == PS::ACTION_EDIT ? 'Edit' : 'Update',
'url' => array( 'update' ),
'icon' => 'pencil',
);
break;
case PS::ACTION_SAVE:
- $_arOut[ 'save' ] = array(
+ $_arOut['save'] = array(
'label' => 'Save',
'url' => '_submit_',
'icon' => 'disk',
);
break;
case PS::ACTION_DELETE:
- $_arOut[ 'delete' ] = array(
+ $_arOut['delete'] = array(
'label' => 'Delete',
'url' => array( 'delete' ),
'confirm' => 'Do you really want to delete this ' . $sItemName . '?',
@@ -415,31 +473,31 @@ public static function createMenuButtons( $sItemName, $arWhich = array(), $sAdmi
case PS::ACTION_RETURN:
case PS::ACTION_CANCEL:
- $_arOut[ 'cancel' ] = array(
+ $_arOut['cancel'] = array(
'label' => 'Cancel',
'url' => $sAdminAction,
'icon' => 'cancel',
);
break;
case PS::ACTION_ADMIN:
- $_arOut[ 'return' ] = array(
+ $_arOut['return'] = array(
'label' => $sAdminName,
'url' => $sAdminAction,
'icon' => 'arrowreturnthick-1-w',
);
break;
case PS::ACTION_LOCK:
- $_arOut[ 'lock' ] = array(
+ $_arOut['lock'] = array(
'label' => 'Lock',
'url' => array( 'lock' ),
'icon' => 'unlocked',
);
break;
case PS::ACTION_UNLOCK:
- $_arOut[ 'unlock' ] = array(
+ $_arOut['unlock'] = array(
'label' => 'Unlock',
'url' => array( 'unlock' ),
'icon' => 'locked',
@@ -452,4 +510,9 @@ public static function createMenuButtons( $sItemName, $arWhich = array(), $sAdmi
return $_arOut;
}
+ public static function getLastErrorSummary()
+ {
+ return self::$lastErrorSummary;
+ }
+
}
View
91 extensions/pogostick/helpers/CPSWidgetHelper.php
@@ -38,7 +38,7 @@ class CPSWidgetHelper extends CPSHelperBase
* A prefix for generated ids
*/
const ID_PREFIX = 'pye';
- const STD_JQUI_FORM_CONTAINER_CLASS = 'ui-edit-container ui-widget';
+ const STD_JQUI_FORM_CONTAINER_CLASS = 'setViewNavigationOptionsui-edit-container ui-widget';
const STD_FORM_CONTAINER_CLASS = 'ps-edit-form';
const STD_BOOTSTRAP_FORM_CONTAINER_CLASS = 'bootstrap-edit-form';
const STD_BOOTSTRAP2_FORM_CONTAINER_CLASS = 'bootstrap2-edit-form';
@@ -595,6 +595,11 @@ public static function field( $inputFieldType, CModel $model, $attributeName, $a
$_arDivOpts['id'] = self::$m_sFormFieldContainerPrefix . '_' . PS::nvl( PS::o( $_arDivOpts, 'id' ), $arOptions['id'] );
$_arDivOpts['class'] = PS::addClass( $_divClass, PS::$m_sFormFieldContainerClass . ' ' . PS::o( $_arDivOpts, 'class' ) );
+
+ if ( self::UI_BOOTSTRAP == self::$_uiStyle && $model->getError( $attributeName ) )
+ {
+ $_arDivOpts['class'] = PS::addClass( $_arDivOpts['class'], 'error' );
+ }
}
}
@@ -1961,7 +1966,16 @@ public static function errorSummary( $model, $sHeader = null, $sFooter = null, $
$_errorListClass = PS::o( $htmlOptions, 'errorListClass', null, true );
$_singleErrorListClass = PS::o( $htmlOptions, 'singleErrorListClass', $_errorListClass, true );
- self::$errorSummaryCss = 'ps-error-summary ui-state-error';
+ if ( self::UI_BOOTSTRAP == PS::o( $htmlOptions, 'uiStyle', self::UI_JQUERY ) )
+ {
+ $_bootstrap = true;
+ self::$errorSummaryCss = 'alert alert-error fade in';
+ }
+ else
+ {
+ $_bootstrap = false;
+ self::$errorSummaryCss = 'ps-error-summary ui-state-error';
+ }
if ( !is_array( $_arModel ) )
{
@@ -1987,43 +2001,58 @@ public static function errorSummary( $model, $sHeader = null, $sFooter = null, $
if ( $_content !== null )
{
- if ( !$_iconClass )
+ if ( $_bootstrap )
{
- $_sIcon = ( !$_bNoIcon )
- ?
- '<span class="ui-icon ui-icon-alert" style="float: left; margin-top: 3px; margin-left: 0.5em; margin-right: 6px;"></span>'
- :
- null;
+ return <<<HTML
+<div class="alert alert-error" style="margin-top: 15px;">
+<a class="close" data-dismiss="alert" href="#">&times;</a>
+<h4 class="alert-heading">Please check for the following errors:</h4>
+<ul>{$_content}</ul>
+</div>
+HTML;
+
}
else
{
- $_sIcon = '<span class="' . $_iconClass . '" style="float: left; margin-top: 0.5em; margin-left: 0.5em; margin-right: 6px;
+ if ( !$_iconClass )
+ {
+ $_sIcon = ( !$_bNoIcon )
+ ?
+ '<span class="ui-icon ui-icon-alert" style="float: left; margin-top: 3px; margin-left: 0.5em; margin-right: 6px;"></span>'
+ :
+ null;
+ }
+ else
+ {
+ $_sIcon = '<span class="' . $_iconClass . '" style="float: left; margin-top: 0.5em; margin-left: 0.5em; margin-right: 6px;
"></span>';
- }
+ }
- if ( null === $sHeader )
- {
- $sHeader = self::tag(
- $_headerTag, array( 'style' => 'font-style: italic; font-weight: bold;' ),
- Yii::t( 'yii', 'Please fix the following input errors:' )
- );
- }
+ if ( null === $sHeader )
+ {
+ $sHeader = self::tag(
+ $_headerTag, array( 'style' => 'font-style: italic; font-weight: bold;' ),
+ Yii::t( 'yii', 'Please fix the following input errors:' )
+ );
+ }
- // Different class for single errors perhaps?
- if ( $_errorCount == 1 )
- {
- $_errorListClass = $_singleErrorListClass;
- }
+ // Different class for single errors perhaps?
+ if ( $_errorCount == 1 )
+ {
+ $_errorListClass = $_singleErrorListClass;
+ }
- $htmlOptions['class'] = PS::o( $htmlOptions, 'class', self::$errorSummaryCss, true );
- return self::tag(
- 'div', $htmlOptions, $_sIcon . $sHeader . self::tag(
- 'ul', array(
- 'class' => $_errorListClass,
- 'style' => 'margin-left:25px; margin-top:5px'
- ), $_content
- )
- ) . $sFooter;
+ $htmlOptions['class'] = PS::o( $htmlOptions, 'class', self::$errorSummaryCss, true );
+
+ return self::tag(
+ 'div', $htmlOptions, $_sIcon . $sHeader . self::tag(
+ 'ul', array(
+ 'class' => $_errorListClass,
+ 'style' => 'margin-left:25px; margin-top:5px'
+ ), $_content
+ )
+ ) . $sFooter;
+ }
}
}

0 comments on commit b1520a9

Please sign in to comment.
Something went wrong with that request. Please try again.