Skip to content

Commit

Permalink
Merge pull request #4 from torque-foxes/feature/form-overview
Browse files Browse the repository at this point in the history
Add Form Start/Overview pages
  • Loading branch information
lhalaa authored Sep 10, 2019
2 parents 5b3860f + f159582 commit 6529453
Show file tree
Hide file tree
Showing 11 changed files with 505 additions and 77 deletions.
1 change: 0 additions & 1 deletion _config/routes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ SilverStripe\Control\Director:
rules:
'partialuserform//$Action/$ID/$OtherID': Firesphere\PartialUserForms\Controllers\PartialSubmissionController
'partial/$Key/$Token': Firesphere\PartialUserForms\Controllers\PartialUserFormController
'verify': Firesphere\PartialUserForms\Controllers\PartialUserFormVerifyController
258 changes: 257 additions & 1 deletion client/dist/main.js
Original file line number Diff line number Diff line change
@@ -1 +1,257 @@
!function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="/",r(r.s=0)}([function(e,t,r){e.exports=r(1)},function(e,t,r){"use strict";function n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}r.r(t);var o=document.baseURI,u=document.body.querySelector("form.userform"),c=[],a=function(){var e=new FormData;Array.from(u.querySelectorAll("[aria-hidden=false] [name]:not([type=hidden]):not([type=submit])")).forEach(function(t){var r=t.getAttribute("name"),o=function(e,t){var r=e.value;if("select"===e.getAttribute("type"))return e[e.selectedIndex].value;if("radio"===e.getAttribute("type")){var n="[name=".concat(t,"]:checked"),o=document.body.querySelector(n);return null!==o?o.value:""}if("checkbox"===e.getAttribute("type")){var u='[name="'.concat(t,'"]:checked'),c=Array.from(document.body.querySelectorAll(u)),a=[];return c.length>0?(c.forEach(function(e){a.push(e.value)}),a):""}return"file"===e.getAttribute("type")&&e.files.length>0?e.files[0]:r}(t,r);e.has(r)||("object"===n(o)&&"file"===t.getAttribute("type")?e.append(r,o):"object"===n(o)?o.forEach(function(t){e.append(r,t)}):e.append(r,o))});var t=u.querySelector("[name=PartialID]");t&&e.append("PartialID",t.value);var r=new XMLHttpRequest;c.push(r),r.open("POST","".concat(o).concat("partialuserform/save"),!0),r.send(e)},i=function(e){e.addEventListener("click",a)};Array.from(u.querySelectorAll("ul li.step-button-wrapper button")).forEach(i),null!==u&&(u._submit=u.submit,u.submit=function(){confirm("Are you sure you want to submit this form?")&&(c.length&&c.forEach(function(e){e.abort()}),u._submit())})}]);
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "/";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 0);
/******/ })
/************************************************************************/
/******/ ({

/***/ "./client/src/js/main.js":
/*!*******************************!*\
!*** ./client/src/js/main.js ***!
\*******************************/
/*! no exports provided */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _partialuserforms_partialsubmission__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./partialuserforms/partialsubmission */ "./client/src/js/partialuserforms/partialsubmission.js");
/* harmony import */ var _partialuserforms_partialstorage__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./partialuserforms/partialstorage */ "./client/src/js/partialuserforms/partialstorage.js");


Object(_partialuserforms_partialsubmission__WEBPACK_IMPORTED_MODULE_0__["default"])();
Object(_partialuserforms_partialstorage__WEBPACK_IMPORTED_MODULE_1__["default"])();

/***/ }),

/***/ "./client/src/js/partialuserforms/partialstorage.js":
/*!**********************************************************!*\
!*** ./client/src/js/partialuserforms/partialstorage.js ***!
\**********************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony default export */ __webpack_exports__["default"] = (function () {// @todo, add the option to prefill
});

/***/ }),

/***/ "./client/src/js/partialuserforms/partialsubmission.js":
/*!*************************************************************!*\
!*** ./client/src/js/partialuserforms/partialsubmission.js ***!
\*************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

var baseDomain = document.baseURI;
var submitURL = 'partialuserform/save';
var form = document.body.querySelector('form.userform');

var buttons = function buttons() {
return Array.from(form.querySelectorAll('ul li.step-button-wrapper button'));
}; // Just get the form elements from the current step


var formElements = function formElements() {
return Array.from(form.querySelectorAll('[aria-hidden=false] [name]:not([type=hidden]):not([type=submit])'));
};

var requests = [];

var getElementValue = function getElementValue(element, fieldName) {
var value = element.value;

if (element.getAttribute('type') === 'select') {
return element[element.selectedIndex].value;
}

if (element.getAttribute('type') === 'radio') {
var name = "[name=".concat(fieldName, "]:checked");
var checkedElement = document.body.querySelector(name);
return checkedElement !== null ? checkedElement.value : "";
}

if (element.getAttribute('type') === 'checkbox') {
var _name = "[name=\"".concat(fieldName, "\"]:checked");

var checkedElements = Array.from(document.body.querySelectorAll(_name));
var valueArray = [];

if (checkedElements.length > 0) {
checkedElements.forEach(function (element) {
valueArray.push(element.value);
});
return valueArray;
}

return "";
}

if (element.getAttribute('type') === 'file' && element.files.length > 0) {
return element.files[0];
}

return value;
};

var submitPartial = function submitPartial() {
var data = new FormData();
formElements().forEach(function (element) {
var fieldName = element.getAttribute('name');
var value = getElementValue(element, fieldName);

if (!data.has(fieldName)) {
if (_typeof(value) === 'object' && element.getAttribute('type') === 'file') {
data.append(fieldName, value);
} else if (_typeof(value) === 'object') {
value.forEach(function (arrayValue) {
data.append(fieldName, arrayValue);
});
} else {
data.append(fieldName, value);
}
}
}); // Pass partial params if available

var partialID = form.querySelector('[name=PartialID]');

if (partialID) {
data.append('PartialID', partialID.value);
}
/** global: XMLHttpRequest */


var httpRequest = new XMLHttpRequest();
requests.push(httpRequest);
httpRequest.open('POST', "".concat(baseDomain).concat(submitURL), true);
httpRequest.send(data);
};

var attachSubmitPartial = function attachSubmitPartial(button) {
button.addEventListener('click', submitPartial);
};

var abortPendingSubmissions = function abortPendingSubmissions() {
// Clear all pending partial submissions on submit
if (form !== null) {
form._submit = form.submit; // Save reference

form.submit = function () {
// Abort all requests
if (requests.length) {
requests.forEach(function (xhr) {
xhr.abort();
});
}

form._submit();
};
}
};

/* harmony default export */ __webpack_exports__["default"] = (function () {
buttons().forEach(attachSubmitPartial);
abortPendingSubmissions();
});

/***/ }),

/***/ 0:
/*!*************************************!*\
!*** multi ./client/src/js/main.js ***!
\*************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

module.exports = __webpack_require__(/*! /Users/scotthutchinson/sites/mbie/vendor/firesphere/partialuserforms/client/src/js/main.js */"./client/src/js/main.js");


/***/ })

/******/ });
4 changes: 0 additions & 4 deletions client/src/js/partialuserforms/partialsubmission.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ const abortPendingSubmissions = () => {
if (form !== null) {
form._submit = form.submit; // Save reference
form.submit = () => {
if (!confirm("Are you sure you want to submit this form?")) {
return;
}

// Abort all requests
if (requests.length) {
requests.forEach(xhr => {
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/PartialUserFormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function partial(HTTPRequest $request)
if ($controller->PasswordProtected &&
$request->getSession()->get(PasswordForm::PASSWORD_SESSION_KEY) !== $partial->ID
) {
return $this->redirect('verify');
return $this->redirect($record->link('verify'));
}

// Lock form
Expand Down
14 changes: 6 additions & 8 deletions src/controllers/PartialUserFormVerifyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@

namespace Firesphere\PartialUserforms\Controllers;

use Exception;
use Firesphere\PartialUserforms\Forms\PasswordForm;
use Firesphere\PartialUserforms\Models\PartialFormSubmission;
use Page;
use Exception;
use PageController;
use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Control\HTTPResponse_Exception;
use SilverStripe\UserForms\Model\UserDefinedForm;
use Firesphere\PartialUserforms\Forms\PasswordForm;
use Firesphere\PartialUserforms\Models\PartialFormSubmission;

/**
* Class \Firesphere\PartialUserforms\Controllers\PartialUserFormVerifyController
Expand Down Expand Up @@ -54,9 +56,6 @@ public function init()
$partial = PartialFormSubmission::get()->byID($sessionID);

$this->setPartialFormSubmission($partial);
// Set data record and load the form
/** @var UserDefinedForm dataRecord */
$this->dataRecord = Page::create();
}

/**
Expand All @@ -67,7 +66,6 @@ public function getForm()
return PasswordForm::create($this, __FUNCTION__);
}


/**
* @param array $data
* @param PasswordForm $form
Expand Down Expand Up @@ -97,7 +95,7 @@ public function doValidate($data, $form)
$request->getSession()->set(PasswordForm::PASSWORD_SESSION_KEY, $partial->ID);
$request->getSession()->set(self::PASSWORD_KEY, $data['Password']);

return $this->redirect($partial->getPartialLink());
return $this->redirect($partial->Parent()->Link('overview'));
}

/**
Expand Down
Loading

0 comments on commit 6529453

Please sign in to comment.