improve modale registration and login forms
This commit is contained in:
parent
ca6c5bd4fa
commit
7aa6dfe191
@ -30,89 +30,93 @@ MaterioUser = function(){
|
||||
destination = href.match('/\?destination=([^,]+)');
|
||||
|
||||
destination = "/" + destination[1].replace('%23', '#');
|
||||
trace('destination', destination);
|
||||
destination = destination.replace('//', '/');
|
||||
// trace('destination', destination);
|
||||
|
||||
loadRegistrationBlock(destination);
|
||||
if($this.parents('.gratos').size()){
|
||||
loadRegisterBlock(destination);
|
||||
}else{
|
||||
loadLoginAndRegisterBlock(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));
|
||||
|
||||
$('.modal-wrapper').bind('click', function(event) {
|
||||
$(this).remove();
|
||||
});
|
||||
|
||||
$('.modal-content').bind('click', function(event) {
|
||||
event.stopPropagation();
|
||||
});
|
||||
|
||||
// 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($('#user-register-form'), 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($('#user-login'), 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 loadRegisterBlock (destination) {
|
||||
trace("loadRegisterBlock :: dest = "+destination);
|
||||
$.getJSON(Drupal.settings.basePath+Drupal.settings.pathPrefix+'materio_user/registerblock', formLoaded);
|
||||
}
|
||||
|
||||
function loadLoginAndRegisterBlock(destination){
|
||||
//trace('loadRegistrationBlock :: dest = '+destination);
|
||||
$.getJSON(Drupal.settings.basePath+Drupal.settings.pathPrefix+'materio_user/loginandregisterblock', function(json){formLoaded(json, destination);});
|
||||
};
|
||||
|
||||
function formLoaded(json, destination){
|
||||
//trace('formLoaded | json', json);
|
||||
var $modal = $('<div>').addClass('modal-content').append(json.block);
|
||||
|
||||
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));
|
||||
|
||||
$('.modal-wrapper').bind('click', function(event) {
|
||||
$(this).remove();
|
||||
});
|
||||
|
||||
$('.modal-content').bind('click', function(event) {
|
||||
event.stopPropagation();
|
||||
});
|
||||
|
||||
// doesn't work
|
||||
// Drupal.attachBehaviors('bodi>.modal-wrapper');
|
||||
|
||||
$.event.trigger('ajax-register-block-loaded');
|
||||
|
||||
$("#user-register-form #edit-submit, #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($('#user-register-form'), 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($('#user-login'), 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($form, data, destination){
|
||||
|
@ -29,9 +29,16 @@ function materio_user_menu(){
|
||||
'file' => 'materio_user.pages.inc',
|
||||
);
|
||||
|
||||
$items['materio_user/register'] = $base+array(
|
||||
$items['materio_user/registerblock'] = $base+array(
|
||||
'title' => 'Materio base user ajax',
|
||||
'page callback' => 'materio_user_register',
|
||||
'page callback' => 'materio_user_registerblock',
|
||||
// 'page arguments' => array(),
|
||||
'access callback' => TRUE,
|
||||
);
|
||||
|
||||
$items['materio_user/loginandregisterblock'] = $base+array(
|
||||
'title' => 'Materio base user ajax',
|
||||
'page callback' => 'materio_user_loginandregisterblock',
|
||||
// 'page arguments' => array(),
|
||||
'access callback' => TRUE,
|
||||
);
|
||||
@ -65,6 +72,10 @@ function materio_user_menu_alter(&$items) {
|
||||
* Implements hook_block_info().
|
||||
*/
|
||||
function materio_user_block_info() {
|
||||
$blocks['user_createaccount'] = array(
|
||||
'info' => t('Create an account block'),
|
||||
'cache' => DRUPAL_NO_CACHE
|
||||
);
|
||||
$blocks['user_register'] = array(
|
||||
'info' => t('Register block'),
|
||||
'cache' => DRUPAL_NO_CACHE
|
||||
@ -88,6 +99,18 @@ function materio_user_block_view($delta = '') {
|
||||
global $user, $language;
|
||||
$block = array();
|
||||
switch ($delta) {
|
||||
case 'user_createaccount':
|
||||
if(isset($user->roles[1])){
|
||||
$block['subject'] = '';
|
||||
if (drupal_is_front_page()) {
|
||||
$block['content'] .= '<h3>'. t('Create your materiO\' account') . '</h3>';
|
||||
$block['content'] .= l(t('Join us'), 'node/11187', array("attributes"=>array("class"=>array("join"))));
|
||||
}else{
|
||||
$block['content'] .= '<h3>'. t('Create your materiO\' account') . '</h3>';
|
||||
$block['content'] .= drupal_render(drupal_get_form('user_register_form'));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'user_register':
|
||||
if(isset($user->roles[1])){
|
||||
$block['subject'] = '';//drupal_is_front_page() ? t('Your projects will born from here') : t('Create your materiO\' account');
|
||||
@ -127,7 +150,7 @@ function materio_user_block_view($delta = '') {
|
||||
/**
|
||||
* Implements hook_form_alter().
|
||||
*/
|
||||
function DISABLED_NOT_FINISHED_materio_user_form_alter(&$form, &$form_state, $form_id) {
|
||||
function materio_user_form_alter(&$form, &$form_state, $form_id) {
|
||||
// dsm($form_id);
|
||||
if( $form_id == "user_register_form" && !user_access('administer users') ){
|
||||
// dsm($form);
|
||||
@ -143,7 +166,7 @@ function DISABLED_NOT_FINISHED_materio_user_form_alter(&$form, &$form_state, $fo
|
||||
// '#required' => true,
|
||||
// );
|
||||
|
||||
$form['#submit'][] = "materio_user_user_register_form_submit";
|
||||
// $form['#submit'][] = "materio_user_user_register_form_submit";
|
||||
|
||||
}
|
||||
if($form_id == "user_login" ){
|
||||
@ -152,17 +175,17 @@ function DISABLED_NOT_FINISHED_materio_user_form_alter(&$form, &$form_state, $fo
|
||||
$form['actions']['#type'] = "container";
|
||||
// $form['actions']['submit']['#value'] = t('Join');
|
||||
|
||||
if( $_GET['q'] == 'node/11187' ){
|
||||
$form['#submit'][] = "materio_user_user_login_form_submit";
|
||||
}
|
||||
// if( $_GET['q'] == 'node/11187' ){
|
||||
// $form['#submit'][] = "materio_user_user_login_form_submit";
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
if( $form_id == "webform_client_form_11186" ){
|
||||
// if( $form_id == "webform_client_form_11186" ){
|
||||
// dsm($form, '$form');
|
||||
$form['#validate'][] = "materio_user_webform_client_111186_validate";
|
||||
// $form['#validate'][] = "materio_user_webform_client_111186_validate";
|
||||
// $form['#submit'][] = "materio_user_webform_client_111186_submit";
|
||||
}
|
||||
// }
|
||||
|
||||
|
||||
// if( $form_id == "user_profile_form" ){
|
||||
@ -171,7 +194,7 @@ function DISABLED_NOT_FINISHED_materio_user_form_alter(&$form, &$form_state, $fo
|
||||
// }
|
||||
}
|
||||
|
||||
function materio_user_user_register_form_submit($form, &$form_state){
|
||||
// function materio_user_user_register_form_submit($form, &$form_state){
|
||||
// dsm($form, 'form');
|
||||
// dsm($form_state, 'form_state');
|
||||
// dsm($_REQUEST, '$_REQUEST');
|
||||
@ -189,18 +212,18 @@ function materio_user_user_register_form_submit($form, &$form_state){
|
||||
// $frontlink = l('continue with basic', '<front>');
|
||||
// // drupal_get_messages('status');
|
||||
// drupal_set_message(t('Welcome, you just join materiO\'! now you can choose the membership that\'s right for you, or !link', array('!link'=>$frontlink)));
|
||||
}
|
||||
// }
|
||||
|
||||
function materio_user_user_login_form_submit($form, &$form_state){
|
||||
unset($_REQUEST['destination'], $_REQUEST['edit']['destination']);
|
||||
// function materio_user_user_login_form_submit($form, &$form_state){
|
||||
// unset($_REQUEST['destination'], $_REQUEST['edit']['destination']);
|
||||
|
||||
$form_state['redirect'] = array(
|
||||
'node/11187',
|
||||
array(
|
||||
'fragment' => 'content-bottom', // if we login from the membership page, then go directly to the form
|
||||
)
|
||||
);
|
||||
}
|
||||
// $form_state['redirect'] = array(
|
||||
// 'node/11187',
|
||||
// array(
|
||||
// 'fragment' => 'content-bottom', // if we login from the membership page, then go directly to the form
|
||||
// )
|
||||
// );
|
||||
// }
|
||||
|
||||
function materio_user_webform_client_111186_validate($form, &$form_state){
|
||||
// dsm($form, 'form');
|
||||
|
@ -1,21 +1,17 @@
|
||||
<?php
|
||||
|
||||
function materio_user_register(){
|
||||
function materio_user_registerblock(){
|
||||
$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');
|
||||
|
||||
$block = block_load('materio_user','user_createaccount');
|
||||
$return['block'] = drupal_render(_block_get_renderable_array(_block_render_blocks(array($block))));
|
||||
drupal_json_output($return);
|
||||
}
|
||||
|
||||
function materio_user_loginandregisterblock(){
|
||||
$return = array();
|
||||
$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(){
|
||||
|
Loading…
x
Reference in New Issue
Block a user