Refactoring Step 2
authorAlex Kellner <alexander.kellner@in2code.de>
Fri, 16 May 2014 14:42:03 +0000 (16:42 +0200)
committerAlex Kellner <alexander.kellner@in2code.de>
Fri, 16 May 2014 14:42:03 +0000 (16:42 +0200)
Classes/Utility/Eid/RequiredFieldsEid.php [new file with mode: 0644]
Resources/Public/Js/PowermailCond.js
ext_localconf.php

diff --git a/Classes/Utility/Eid/RequiredFieldsEid.php b/Classes/Utility/Eid/RequiredFieldsEid.php
new file mode 100644 (file)
index 0000000..6f61bfc
--- /dev/null
@@ -0,0 +1,94 @@
+<?php
+namespace In2code\PowermailCond\Utility\Eid;
+
+use \TYPO3\CMS\Core\Utility\GeneralUtility;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2014 Alex Kellner <alexander.kellner@in2code.de>, in2code.de
+ *
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Remove all fields from session which should be mandatory again
+ *
+ * @author Alex Kellner <alexander.kellner@in2code.de>, in2code.de
+ * @package TYPO3
+ * @subpackage RequiredFieldEid
+ */
+class RequiredFieldsEid {
+
+       /**
+        * Prefix Id
+        *
+        * @var string
+        */
+       public $prefixId = 'tx_powermailcond_pi1';
+
+       /**
+        * @var \In2code\PowermailCond\Utility\Div
+        */
+       protected $div;
+
+       /**
+        * save field in session to be stored for non-mandatory fields
+        *
+        * @return string
+        */
+       public function main() {
+               $piVars = GeneralUtility::_GP($this->prefixId);
+               $formUid = intval($piVars['formUid']);
+               if ($formUid === 0) {
+                       return 'no FormUid given';
+               }
+
+               // removee single value from session
+               $this->div->cleanfullSession($formUid, 'deRequiredFields');
+               return 'ok';
+       }
+
+       /**
+        * Initialize eID
+        */
+       public function __construct($TYPO3_CONF_VARS) {
+               $userObj = \TYPO3\CMS\Frontend\Utility\EidUtility::initFeUser();
+               $GLOBALS['TSFE'] = GeneralUtility::makeInstance(
+                       '\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController',
+                       $TYPO3_CONF_VARS,
+                       32,
+                       0,
+                       TRUE
+               );
+               $GLOBALS['TSFE']->connectToDB();
+               $GLOBALS['TSFE']->fe_user = $userObj;
+               $GLOBALS['TSFE']->id = GeneralUtility::_GET('id');
+               $GLOBALS['TSFE']->determineId();
+               $GLOBALS['TSFE']->getCompressedTCarray();
+               $GLOBALS['TSFE']->initTemplate();
+               $GLOBALS['TSFE']->getConfigArray();
+               $GLOBALS['TSFE']->includeTCA();
+
+               $this->div = GeneralUtility::makeInstance('\In2code\PowermailCond\Utility\Div');
+       }
+}
+
+$eid = GeneralUtility::makeInstance('In2code\PowermailCond\Utility\Eid\RequiredFieldsEid', $GLOBALS['TYPO3_CONF_VARS']);
+echo $eid->main();
\ No newline at end of file
index 1de6e7b..bb6d44a 100644 (file)
@@ -244,27 +244,29 @@ function deRequiredField(uid, disableAjaxRequest) {
  * @return void
  */
 function reRequiredAll() {
-       $('.powermail_field').each(function() {
-               var element = $(this);
-               var uid = element.closest('.powermail_fieldwrap').prop('id').substr(20);
-               var classValue = $(this).prop('class');
-               if (classValue.indexOf('_required_') !== -1) {
-                       // replace validate[_required_] with [required]
-                       classValue = classValue.replace('_required_', 'required');
-                       element.prop('class', classValue);
-
-                       // add required="required"
-                       if (element.prop('type') == 'text') {
-                               element.prop('required', 'required');
-                       }
-
-                       $.ajax({
-                               url: '/index.php',
-                               data: 'eID=' + 'powermailcond_requiredField&tx_powermailcond_pi1[formUid]=' + getFormUid() + '&tx_powermailcond_pi1[fieldUid]=' + uid,
-                               cache: false
-                       });
-               }
+       // Required Fields all
+       $.ajax({
+               url: '/index.php',
+               data: 'eID=' + 'powermailcond_requiredFields&tx_powermailcond_pi1[formUid]=' + getFormUid(),
+               cache: false
        });
+
+       // TODO JS
+//     $('.powermail_field').each(function() {
+//             var element = $(this);
+//             var uid = element.closest('.powermail_fieldwrap').prop('id').substr(20);
+//             var classValue = $(this).prop('class');
+//             if (classValue.indexOf('_required_') !== -1) {
+//                     // replace validate[_required_] with [required]
+//                     classValue = classValue.replace('_required_', 'required');
+//                     element.prop('class', classValue);
+//
+//                     // add required="required"
+//                     if (element.prop('type') == 'text') {
+//                             element.prop('required', 'required');
+//                     }
+//             }
+//     });
 }
 
 /**
index 6b4f40e..bd5bb49 100644 (file)
@@ -43,4 +43,8 @@ $GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include']['powermailcond_requiredField']
 
 // eID to read all session values for debugging (only if logged in into Backend)
 $GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include']['powermailcond_debugSession'] =
-       'EXT:powermail_cond/Classes/Utility/Eid/DebugSessionEid.php';
\ No newline at end of file
+       'EXT:powermail_cond/Classes/Utility/Eid/DebugSessionEid.php';
+
+// eID to clean the deRequired Fields session
+$GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include']['powermailcond_requiredFields'] =
+       'EXT:powermail_cond/Classes/Utility/Eid/RequiredFieldsEid.php';
\ No newline at end of file