diff --git a/code/GridFieldBulkEditingHelper.php b/code/GridFieldBulkEditingHelper.php new file mode 100644 index 0000000..cdb07be --- /dev/null +++ b/code/GridFieldBulkEditingHelper.php @@ -0,0 +1,130 @@ +getCMSFields(); + $cmsDataFields = $cmsFields->dataFields(); + $cmsDataFields = GridFieldBulkEditingHelper::filterNonEditableRecordsFields($config, $cmsDataFields); + + return $cmsDataFields; + } + + + public static function filterNonEditableRecordsFields ( $config, $dataFields ) + { + if ( isset($config['editableFields']) ) + { + if ( $config['editableFields'] != null ) + { + foreach ($dataFields as $name => $field) + { + if ( !in_array($name, $config['editableFields']) ) + { + unset( $dataFields[$name] ); + } + } + } + } + + return $dataFields; + } + + /** + * Filters out all unwanted fields from the config settings + * + * @param array $config + * @param array $dataFields + * @return array + */ + public static function getModelFilteredDataFields ( $config, $dataFields ) + { + //remove the image field - for bulk image upload + if ( isset($config['imageFieldName']) ) + { + if ( $config['imageFieldName'] != null ) + { + //@TODO: this wont work if the fieldname has ID in it: i.e. TheIDImageID -> remove last 2 char only + unset( $dataFields[str_ireplace('ID', '', $config['imageFieldName']) ] ); + } + } + + //if class blacklist filter + if ( count($config['fieldsClassBlacklist']) > 0 ) + { + foreach ($dataFields as $fieldName => $field) + { + //@TODO find PHP function that return the classname + if ( in_array($field->ClassName, $config['fieldsClassBlacklist']) ) + { + array_push($config['fieldsNameBlacklist'], $fieldName); + } + } + } + + //if name blacklist filter + if ( count($config['fieldsNameBlacklist']) > 0 ) + { + foreach ( $config['fieldsNameBlacklist'] as $badFieldName ) + { + unset( $dataFields[ $badFieldName ] ); + } + } + + return $dataFields; + } + + public static function filterDatafieldsByClass ( $config, $dataFields ) + { + //@todo + } + + public static function filterDataFieldsByName ( $config, $dataFields ) + { + //@todo + } + + public static function dataFieldsToHTML ( $dataFields ) + { + $fieldsHTML = array(); + + foreach ( $dataFields as $key => $field ) + { + //@TODO: FieldHolder() does not seem to exist on UploadField + $fieldsHTML[$key] = $field->FieldHolder(); + } + + return $fieldsHTML; + } + + public static function escapeFormFieldsHTML ( $formFieldsHTML, $unique ) + { + $prefix = 'record_'.$unique.'_'; + + foreach ( $formFieldsHTML as $name => $html ) + { + $formFieldsHTML[$name] = str_ireplace ( array('id="', 'for="', 'name="'), + array('id="'.$prefix, 'for="'.$prefix, 'name="'.$prefix), + $html); + } + + return $formFieldsHTML; + } + + public static function unescapeFormFieldsPOSTData ( $requestVars ) + { + //@todo + } + + + + +} \ No newline at end of file diff --git a/code/GridFieldBulkEditingTools.php b/code/GridFieldBulkEditingTools.php index 066cf2c..4ac2d04 100644 --- a/code/GridFieldBulkEditingTools.php +++ b/code/GridFieldBulkEditingTools.php @@ -1,130 +1,19 @@ getCMSFields(); - $cmsDataFields = $cmsFields->dataFields(); - $cmsDataFields = GridFieldBulkEditingTools::filterNonEditableRecordsFields($config, $cmsDataFields); - - return $cmsDataFields; - } - - - public static function filterNonEditableRecordsFields ( $config, $dataFields ) - { - if ( isset($config['editableFields']) ) - { - if ( $config['editableFields'] != null ) - { - foreach ($dataFields as $name => $field) - { - if ( !in_array($name, $config['editableFields']) ) - { - unset( $dataFields[$name] ); - } - } - } - } - - return $dataFields; - } - - /** - * Filters out all unwanted fields from the config settings - * - * @param array $config - * @param array $dataFields - * @return array - */ - public static function getModelFilteredDataFields ( $config, $dataFields ) - { - //remove the image field - for bulk image upload - if ( isset($config['imageFieldName']) ) - { - if ( $config['imageFieldName'] != null ) - { - //@TODO: this wont work if the fieldname has ID in it: i.e. TheIDImageID -> remove last 2 char only - unset( $dataFields[str_ireplace('ID', '', $config['imageFieldName']) ] ); - } - } - - //if class blacklist filter - if ( count($config['fieldsClassBlacklist']) > 0 ) - { - foreach ($dataFields as $fieldName => $field) - { - //@TODO find PHP function that return the classname - if ( in_array($field->ClassName, $config['fieldsClassBlacklist']) ) - { - array_push($config['fieldsNameBlacklist'], $fieldName); - } - } - } - - //if name blacklist filter - if ( count($config['fieldsNameBlacklist']) > 0 ) - { - foreach ( $config['fieldsNameBlacklist'] as $badFieldName ) - { - unset( $dataFields[ $badFieldName ] ); - } - } - - return $dataFields; - } - - public static function filterDatafieldsByClass ( $config, $dataFields ) - { - //@todo - } - - public static function filterDataFieldsByName ( $config, $dataFields ) - { - //@todo - } - - public static function dataFieldsToHTML ( $dataFields ) - { - $fieldsHTML = array(); - - foreach ( $dataFields as $key => $field ) - { - //@TODO: FieldHolder() does not seem to exist on UploadField - $fieldsHTML[$key] = $field->FieldHolder(); - } - - return $fieldsHTML; - } - - public static function escapeFormFieldsHTML ( $formFieldsHTML, $unique ) - { - $prefix = 'record_'.$unique.'_'; - - foreach ( $formFieldsHTML as $name => $html ) - { - $formFieldsHTML[$name] = str_ireplace ( array('id="', 'for="', 'name="'), - array('id="'.$prefix, 'for="'.$prefix, 'name="'.$prefix), - $html); - } - - return $formFieldsHTML; - } - - public static function unescapeFormFieldsPOSTData ( $requestVars ) - { - //@todo - } - - - - +class GridFieldBulkEditingTools implements GridField_HTMLProvider +{ + public function getHTMLFragments($gridField) + { + Requirements::css('GridFieldBulkImageUpload/css/GridFieldBulkEditingTools.css'); + + return array( + //"footer" => '\$DefineFragment(bulk-edit-tools)' + "after" => "
\$DefineFragment(bulk-edit-tools)
" + ); + } } \ No newline at end of file diff --git a/code/GridFieldBulkImageUpload.php b/code/GridFieldBulkImageUpload.php index 35d13dc..71d027d 100644 --- a/code/GridFieldBulkImageUpload.php +++ b/code/GridFieldBulkImageUpload.php @@ -1,6 +1,9 @@ setConfig ( 'imageFieldName', $imageField ); if ( $editableFields != null ) $this->setConfig ( 'editableFields', $editableFields ); } @@ -121,14 +124,13 @@ class GridFieldBulkImageUpload implements GridField_HTMLProvider, GridField_URLH * @return array */ public function getHTMLFragments($gridField) { - $data = new ArrayData(array( 'NewLink' => $gridField->Link('bulkimageupload'), 'ButtonName' => 'Bulk Upload' )); return array( - 'toolbar-header-right' => $data->renderWith('GridFieldAddNewbutton') + 'bulk-edit-tools' => $data->renderWith('GridFieldAddNewbutton') ); } diff --git a/code/GridFieldBulkImageUpload_Request.php b/code/GridFieldBulkImageUpload_Request.php index b3918f3..4ff8dac 100644 --- a/code/GridFieldBulkImageUpload_Request.php +++ b/code/GridFieldBulkImageUpload_Request.php @@ -6,6 +6,9 @@ * * Form creation * * file upload * * editing and cancelling records + * + * @author colymba + * @package GridFieldBulkEditingTools */ class GridFieldBulkImageUpload_Request extends RequestHandler { @@ -168,19 +171,19 @@ class GridFieldBulkImageUpload_Request extends RequestHandler { function getRecordHTMLFormFields( $recordID = 0 ) { $config = $this->component->getConfig(); - $recordCMSDataFields = GridFieldBulkEditingTools::getModelCMSDataFields( $config, $this->gridField->list->dataClass ); + $recordCMSDataFields = GridFieldBulkEditingHelper::getModelCMSDataFields( $config, $this->gridField->list->dataClass ); //@TODO: if editableFields given use them with filterNonEditableRecordsFields() // otherwise go through getModelFilteredDataFields - $recordCMSDataFields = GridFieldBulkEditingTools::filterNonEditableRecordsFields($config, $recordCMSDataFields); + $recordCMSDataFields = GridFieldBulkEditingHelper::filterNonEditableRecordsFields($config, $recordCMSDataFields); if ( $config['imageFieldName'] == null ) $config['imageFieldName'] = $this->getDefaultRecordImageField(); - $recordCMSDataFields = GridFieldBulkEditingTools::getModelFilteredDataFields($config, $recordCMSDataFields); - $formFieldsHTML = GridFieldBulkEditingTools::dataFieldsToHTML($recordCMSDataFields); - $formFieldsHTML = GridFieldBulkEditingTools::escapeFormFieldsHTML($formFieldsHTML, $recordID); + $recordCMSDataFields = GridFieldBulkEditingHelper::getModelFilteredDataFields($config, $recordCMSDataFields); + $formFieldsHTML = GridFieldBulkEditingHelper::dataFieldsToHTML($recordCMSDataFields); + $formFieldsHTML = GridFieldBulkEditingHelper::escapeFormFieldsHTML($formFieldsHTML, $recordID); return $formFieldsHTML; } diff --git a/css/GridFieldBulkEditingTools.css b/css/GridFieldBulkEditingTools.css new file mode 100644 index 0000000..6fe5e28 --- /dev/null +++ b/css/GridFieldBulkEditingTools.css @@ -0,0 +1,5 @@ +div#bulkEditTools +{ + margin: 0; + text-align: right; +} \ No newline at end of file