new membership and account creation process : modal and form is in a separated page
This commit is contained in:
parent
051455cd71
commit
8909491a12
134
js/materio_user.js
Executable file
134
js/materio_user.js
Executable file
@ -0,0 +1,134 @@
|
||||
// @codekit-prepend "gui.js"
|
||||
// @koala-prepend "gui.js"
|
||||
|
||||
|
||||
(function($) {
|
||||
|
||||
MaterioUser = function(){
|
||||
|
||||
var _isAdhesion = $('body').is('.page-node-11187') || $('body').is('.page-node-11186');
|
||||
|
||||
function init() {
|
||||
//trace('MaterioUser init compile test 3');
|
||||
if(_isAdhesion)
|
||||
initAdhesion();
|
||||
};
|
||||
|
||||
function initAdhesion(){
|
||||
//trace('initAdhesion');
|
||||
$('.get-link a').bind('click', function(event) {
|
||||
|
||||
// do not show the registration form if already logged-in
|
||||
if($('body').is('.logged-in'))
|
||||
return true;
|
||||
|
||||
// else show the ajaxified registration form
|
||||
event.preventDefault();
|
||||
|
||||
var $this = $(this),
|
||||
href = $this.attr("href"),
|
||||
destination = href.match('/\?destination=([^,]+)');
|
||||
|
||||
destination = "/" + destination[1].replace('%23', '#');
|
||||
trace('destination', destination);
|
||||
|
||||
loadRegistrationBlock(destination);
|
||||
return false;
|
||||
});
|
||||
};
|
||||
|
||||
function loadRegistrationBlock(destination){
|
||||
//trace('loadRegistrationBlock :: dest = '+dest);
|
||||
$.getJSON(Drupal.settings.basePath+Drupal.settings.pathPrefix+'materio_user/register',
|
||||
// {'types':types,'current_path':document.location.href, 'keys':keys, 'searchmode':searchmode},
|
||||
function(json){
|
||||
//trace('json', json);
|
||||
|
||||
var $modal = $('<div>').addClass('modal-content').append(json.block);
|
||||
|
||||
// $.event.trigger({
|
||||
// type:"form-loaded",
|
||||
// context:"modal-content"
|
||||
// });
|
||||
|
||||
var id,label, description;
|
||||
$('input.form-text', $modal).each(function(i) {
|
||||
id = $(this).attr('id');
|
||||
label = $('label[for='+id+']').hide().text();
|
||||
description = $(this).parent().find('.description').hide().text();
|
||||
$(this).attr('placeholder', label).attr('title', description);
|
||||
});
|
||||
|
||||
// $('.homepage-textfield', $modal).hide();
|
||||
|
||||
$('body').append($('<div>').addClass('modal-wrapper').append($modal));
|
||||
|
||||
// doesn't work
|
||||
// Drupal.attachBehaviors('bodi>.modal-wrapper');
|
||||
|
||||
$.event.trigger('ajax-register-block-loaded');
|
||||
|
||||
$("#user-register-form #edit-submit--2", $modal).click(function(event){
|
||||
event.preventDefault();
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
dataType:'json',
|
||||
url: Drupal.settings.basePath+Drupal.settings.pathPrefix+"materio_user/register/submit",
|
||||
data: $('#user-register-form', $modal).serialize(),
|
||||
success: function(data) { onUserLoginRegisterSubmit(data, destination);},
|
||||
error: function() {trace('error');}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
$("#user-login #edit-submit", $modal).click(function(event){
|
||||
event.preventDefault();
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
dataType:'json',
|
||||
url: Drupal.settings.basePath+Drupal.settings.pathPrefix+"materio_user/login/submit",
|
||||
data: $('#user-login', $modal).serialize(),
|
||||
success: function(data){ onUserLoginRegisterSubmit(data, destination); },
|
||||
error: function() { trace('error'); }
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
// google analytics
|
||||
// $.event.trigger({
|
||||
// type : "record-stat",
|
||||
// categorie : 'Search',
|
||||
// action : keys,
|
||||
// label : 'filters : '+ stringTypes.join(' ,'),
|
||||
// value : json.count
|
||||
// });
|
||||
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
function onUserLoginRegisterSubmit(data, destination){
|
||||
cleanModalErrors();
|
||||
if(data.errors != null){
|
||||
for(field in data.errors){
|
||||
$('#user-login input[name='+field+']', '.modal-content').addClass('error');
|
||||
$('.modal-content').prepend($('<div>').addClass('message-error').html(data.errors[field]));
|
||||
}
|
||||
}else{
|
||||
window.location.pathname = destination;
|
||||
}
|
||||
};
|
||||
|
||||
function cleanModalErrors() {
|
||||
$('.message-error', '.modal-content').remove();
|
||||
$('input', '.modal-content').removeClass('error');
|
||||
}
|
||||
|
||||
init();
|
||||
};
|
||||
|
||||
$(document).ready(function() {
|
||||
var materiouser = new MaterioUser();
|
||||
});
|
||||
|
||||
})(jQuery);
|
1
js/materio_user.min.js
vendored
Executable file
1
js/materio_user.min.js
vendored
Executable file
@ -0,0 +1 @@
|
||||
!function(t){MaterioUser=function(){function e(){a&&r()}function r(){t(".get-link a").bind("click",function(e){e.preventDefault();var r=t(this),a=r.attr("href").match("/?destination=([^,]+)/");return i(a),!1})}function i(){t.getJSON(Drupal.settings.basePath+Drupal.settings.pathPrefix+"materio_user/register",function(e){var r,i,a,n=t("<div>").addClass("modal-content").append(e.block);t("input.form-text",n).each(function(){r=t(this).attr("id"),i=t("label[for="+r+"]").hide().text(),a=t(this).parent().find(".description").hide().text(),t(this).attr("placeholder",i).attr("title",a)}),t("body").append(t("<div>").addClass("modal-wrapper").append(n)),t.event.trigger("ajax-register-block-loaded"),t("#user-register-form #edit-submit--2").click(function(e){return e.preventDefault(),t.ajax({type:"POST",dataType:"json",url:Drupal.settings.basePath+Drupal.settings.pathPrefix+"materio_user/register/submit",data:t("#user-register-form",n).serialize(),success:function(){},error:function(){}}),!1})})}var a=t("body").is(".page-node-11187")||t("body").is(".page-node-11186");e()},t(document).ready(function(){new MaterioUser})}(jQuery);
|
@ -1,6 +1,14 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_init().
|
||||
*/
|
||||
function materio_user_init() {
|
||||
drupal_add_js(drupal_get_path('module', 'materio_user').'/js/materio_user.js');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_permission().
|
||||
*/
|
||||
@ -13,6 +21,38 @@ function materio_user_permission() {
|
||||
);
|
||||
}
|
||||
|
||||
function materio_user_menu(){
|
||||
$items = array();
|
||||
|
||||
$base = array(
|
||||
'type' => MENU_CALLBACK,
|
||||
'file' => 'materio_user.pages.inc',
|
||||
);
|
||||
|
||||
$items['materio_user/register'] = $base+array(
|
||||
'title' => 'Materio base user ajax',
|
||||
'page callback' => 'materio_user_register',
|
||||
// 'page arguments' => array(),
|
||||
'access callback' => TRUE,
|
||||
);
|
||||
|
||||
$items['materio_user/register/submit'] = $base+array(
|
||||
'title' => 'Materio base user ajax',
|
||||
'page callback' => 'materio_user_register_submit',
|
||||
// 'page arguments' => array(),
|
||||
'access callback' => TRUE,
|
||||
);
|
||||
|
||||
$items['materio_user/login/submit'] = $base+array(
|
||||
'title' => 'Materio base user ajax',
|
||||
'page callback' => 'materio_user_login_submit',
|
||||
// 'page arguments' => array(),
|
||||
'access callback' => TRUE,
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_menu_alter().
|
||||
*/
|
||||
@ -87,7 +127,7 @@ function materio_user_block_view($delta = '') {
|
||||
/**
|
||||
* Implements hook_form_alter().
|
||||
*/
|
||||
function materio_user_form_alter(&$form, &$form_state, $form_id) {
|
||||
function DISABLED_NOT_FINISHED_materio_user_form_alter(&$form, &$form_state, $form_id) {
|
||||
// dsm($form_id);
|
||||
if( $form_id == "user_register_form" && !user_access('administer users') ){
|
||||
// dsm($form);
|
||||
@ -131,60 +171,20 @@ function materio_user_form_alter(&$form, &$form_state, $form_id) {
|
||||
// }
|
||||
}
|
||||
|
||||
// function materio_user_element_info() {
|
||||
// return array(
|
||||
// "new_password_confirm" => array(
|
||||
// '#input' => TRUE,
|
||||
// '#process' => array('materio_user_process_new_password_confirm'),
|
||||
// '#theme_wrappers' => array('form_element'),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
|
||||
/**
|
||||
* Expand a password_confirm field into two text boxes.
|
||||
*/
|
||||
// function materio_user_process_new_password_confirm($element) {
|
||||
// $element['pass1'] = array(
|
||||
// '#type' => 'password',
|
||||
// '#title' => t('New password'),
|
||||
// '#value' => empty($element['#value']) ? NULL : $element['#value']['pass1'],
|
||||
// '#required' => $element['#required'],
|
||||
// '#attributes' => array('class' => array('password-field')),
|
||||
// );
|
||||
// $element['pass2'] = array(
|
||||
// '#type' => 'password',
|
||||
// '#title' => t('Confirm password'),
|
||||
// '#value' => empty($element['#value']) ? NULL : $element['#value']['pass2'],
|
||||
// '#required' => $element['#required'],
|
||||
// '#attributes' => array('class' => array('password-confirm')),
|
||||
// );
|
||||
// $element['#element_validate'] = array('password_confirm_validate');
|
||||
// $element['#tree'] = TRUE;
|
||||
|
||||
// if (isset($element['#size'])) {
|
||||
// $element['pass1']['#size'] = $element['pass2']['#size'] = $element['#size'];
|
||||
// }
|
||||
|
||||
// return $element;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
function materio_user_user_register_form_submit($form, &$form_state){
|
||||
// dsm($form, 'form');
|
||||
// dsm($form_state, 'form_state');
|
||||
// dsm($_REQUEST, '$_REQUEST');
|
||||
// dsm($_GET, '$_GET');
|
||||
|
||||
unset($_REQUEST['destination'], $_REQUEST['edit']['destination']);
|
||||
// unset($_REQUEST['destination'], $_REQUEST['edit']['destination']);
|
||||
|
||||
$form_state['redirect'] = array(
|
||||
'node/11187',
|
||||
array(
|
||||
'fragment' => $_GET['q'] == 'node/11187' ? 'content-bottom' : '', // if we register from the membership page, then go directly to the form
|
||||
)
|
||||
);
|
||||
// $form_state['redirect'] = array(
|
||||
// 'node/11187',
|
||||
// array(
|
||||
// 'fragment' => $_GET['q'] == 'node/11187' ? 'content-bottom' : '', // if we register from the membership page, then go directly to the form
|
||||
// )
|
||||
// );
|
||||
|
||||
// $frontlink = l('continue with basic', '<front>');
|
||||
// // drupal_get_messages('status');
|
||||
@ -206,7 +206,7 @@ function materio_user_webform_client_111186_validate($form, &$form_state){
|
||||
// dsm($form, 'form');
|
||||
// dsm($form_state, 'form_state');
|
||||
$values = $form_state['values']['submitted'];
|
||||
if ($values['membership_options'] == 3) {
|
||||
if ($values['column_left']['membership_options'] == 3) {
|
||||
foreach ($values['collaborators'] as $coll_key => $coll) {
|
||||
foreach ($coll as $field_key => $field_value) {
|
||||
if($field_value == ''){
|
||||
@ -224,7 +224,6 @@ function materio_user_webform_client_111186_validate($form, &$form_state){
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// function materio_user_webform_client_111186_submit($form, &$form_state){
|
||||
|
55
materio_user.pages.inc
Normal file
55
materio_user.pages.inc
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
function materio_user_register(){
|
||||
$return = array();
|
||||
|
||||
// $return['block'] = '<h3>'. t('create your materiO\' account') . '</h3>';
|
||||
// $return['block'] .= drupal_render(drupal_get_form('user_register_form'));
|
||||
|
||||
// $block = module_invoke('materio_user', 'block_view', 'user_register');
|
||||
// $return['block'] = render($block);
|
||||
|
||||
$block = block_load('materio_user','user_register');
|
||||
|
||||
$return['block'] = drupal_render(_block_get_renderable_array(_block_render_blocks(array($block))));
|
||||
|
||||
// dsm($block, '$block');
|
||||
drupal_json_output($return);
|
||||
// return 'hello';
|
||||
}
|
||||
|
||||
function materio_user_register_submit(){
|
||||
$return = array();
|
||||
$return['POST'] = $_POST;
|
||||
|
||||
$form_state = array( "values"=>$_POST);
|
||||
drupal_form_submit($_POST['form_id'], $form_state);
|
||||
|
||||
$return['form_state'] = $form_state;
|
||||
|
||||
$return['errors'] = form_get_errors();
|
||||
if($return['errors'])
|
||||
unset ($_SESSION['messages']['error']);
|
||||
|
||||
// after registration user is automaticly logged in, thank's to login tobogan module
|
||||
|
||||
drupal_json_output($return);
|
||||
}
|
||||
|
||||
function materio_user_login_submit(){
|
||||
$return = array();
|
||||
$return['POST'] = $_POST;
|
||||
|
||||
$form_state = array("values"=>$_POST);
|
||||
drupal_form_submit($_POST['form_id'], $form_state);
|
||||
|
||||
$return['errors'] = form_get_errors();
|
||||
if($return['errors'])
|
||||
unset ($_SESSION['messages']['error']);
|
||||
|
||||
// if user-login form succed we retreive the user uid on $form_state, then we can effectively loggin the user
|
||||
if($uid = $form_state['uid'])
|
||||
user_login_submit(array(), $form_state);
|
||||
|
||||
drupal_json_output($return);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user