début de modal sans ctools
Signed-off-by: bachy <git@g-u-i.net>
This commit is contained in:
parent
df2c715315
commit
1d11663ec4
File diff suppressed because one or more lines are too long
@ -11,6 +11,8 @@ MaterioFlag = function(){
|
|||||||
function init(){
|
function init(){
|
||||||
trace('init MaterioFlag');
|
trace('init MaterioFlag');
|
||||||
$(document).bind('flagGlobalAfterLinkUpdate', onFlaging);
|
$(document).bind('flagGlobalAfterLinkUpdate', onFlaging);
|
||||||
|
$(document).bind('resultscompleted', onResultsUpdated);
|
||||||
|
ajaxifyLinks();
|
||||||
};
|
};
|
||||||
|
|
||||||
function onFlaging(event){
|
function onFlaging(event){
|
||||||
@ -37,6 +39,60 @@ MaterioFlag = function(){
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function onResultsUpdated(event){
|
||||||
|
trace('onResultsUpdated', event);
|
||||||
|
|
||||||
|
ajaxifyLinks(event.container);
|
||||||
|
};
|
||||||
|
|
||||||
|
function ajaxifyLinks(cont){
|
||||||
|
trace('ajaxifyLinks');
|
||||||
|
var container = cont || 'body';
|
||||||
|
$('a.flag-lists-create:not(.ajax)', container)
|
||||||
|
.bind('click', onClickCreatLink)
|
||||||
|
.addClass('ajax');
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
function onClickCreatLink(event){
|
||||||
|
event.preventDefault();
|
||||||
|
var $link = $(event.currentTarget);
|
||||||
|
var type = $link.attr('href').match(/[^\/]*$/);
|
||||||
|
// trace('type', type);
|
||||||
|
var url = 'materioflag/createlist/form/'+type[0];
|
||||||
|
|
||||||
|
$.getJSON(url, function(json){
|
||||||
|
trace('json', json);
|
||||||
|
showCreateListForm(json);
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function showCreateListForm(json){
|
||||||
|
var $modal = $('<div id="modal"/>').appendTo('body');
|
||||||
|
$modal
|
||||||
|
.css({
|
||||||
|
position:'absolute',
|
||||||
|
top:'40%', left:'50%',
|
||||||
|
marginLeft:'-200px', width:'400px',
|
||||||
|
zIndex:"99999"
|
||||||
|
})
|
||||||
|
.append(json.return);
|
||||||
|
// .find('#flag-lists-form').bind('submit', function(event) {
|
||||||
|
// trace('submit',event);
|
||||||
|
// var title = $(this).find('input[name*="title"]').val();
|
||||||
|
// createList(title);
|
||||||
|
// return false;
|
||||||
|
// });
|
||||||
|
};
|
||||||
|
|
||||||
|
function createList(title){
|
||||||
|
var url = 'materioflag/createlist/'+title;
|
||||||
|
$.getJSON(url, function(json){
|
||||||
|
trace('json', json);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,13 +50,18 @@ function materio_flag_menu() {
|
|||||||
'page arguments' => array(3),
|
'page arguments' => array(3),
|
||||||
);
|
);
|
||||||
|
|
||||||
$items['materioflag/createlist/%/%/%ctools_js'] = $base+array(
|
$items['materioflag/createlist/form/%'] = $base+array(
|
||||||
|
'access arguments' => array('create flag lists'),
|
||||||
|
'access callback' => 'user_access',
|
||||||
|
'page callback' => 'materio_flag_createlist_form',
|
||||||
|
'page arguments' => array(3),
|
||||||
|
);
|
||||||
|
|
||||||
|
$items['materioflag/createlist/%'] = $base+array(
|
||||||
'access arguments' => array('create flag lists'),
|
'access arguments' => array('create flag lists'),
|
||||||
'access callback' => 'user_access',
|
'access callback' => 'user_access',
|
||||||
'page callback' => 'materio_flag_createlist',
|
'page callback' => 'materio_flag_createlist',
|
||||||
'page arguments' => array(2,3,4),
|
'page arguments' => array(2, 3),
|
||||||
'delivery callback' => 'ajax_deliver',
|
|
||||||
'theme callback' => 'ajax_base_page_theme',
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return $items;
|
return $items;
|
||||||
@ -241,35 +246,25 @@ function materio_flag_entity_view($entity, $type, $view_mode, $langcode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#create new list
|
#create new list
|
||||||
// $link = l(
|
$link = l(
|
||||||
// t('New @name', array('@name' => variable_get('flag_lists_name', t('list')))),
|
t('New @name', array('@name' => variable_get('flag_lists_name', t('list')))),
|
||||||
// 'flag-lists/add/' . $entity->type,// . '/js',
|
'flag-lists/add/' . $entity->type,
|
||||||
// array(
|
array(
|
||||||
// 'query' => drupal_get_destination(),
|
// 'query' => drupal_get_destination(),
|
||||||
// 'attributes' => array(
|
'attributes' => array(
|
||||||
// 'class' => array('flag-lists-create'),
|
'class' => array('flag-lists-create'),
|
||||||
// 'title' => t('create a new @name and use it.', array('@name'=>variable_get('flag_lists_name', t('list'))))
|
'title' => t('create a new @name and use it.', array('@name'=>variable_get('flag_lists_name', t('list'))))
|
||||||
// )
|
)
|
||||||
// )
|
)
|
||||||
// );
|
|
||||||
|
|
||||||
_materio_flag_include_modal();
|
|
||||||
|
|
||||||
$linktext = t('New @name', array('@name' => variable_get('flag_lists_name', t('list'))));
|
|
||||||
$link = ctools_modal_text_button(
|
|
||||||
$linktext,
|
|
||||||
'materioflag/createlist/'.$entity->type.'/'.$entity->nid.'/nojs',
|
|
||||||
t('Create a new @name and use it.', array('@name'=>variable_get('flag_lists_name', t('list')))),
|
|
||||||
'ctools-modal-ctools-materio-flag-style'
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$create = array(
|
$create = array(
|
||||||
'data' => $link,// . '<i class="icon-plus"></i>',
|
'data' => $link,// . '<i class="icon-plus"></i>',
|
||||||
'class' => array('flag-lists-create'),
|
'class' => array('flag-lists-create'),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( (!isset($items) || !count($items)) && !isset($create))
|
if( (!isset($items) || !count($items)) && !isset($create))
|
||||||
@ -283,86 +278,16 @@ function materio_flag_entity_view($entity, $type, $view_mode, $langcode) {
|
|||||||
if(isset($create))
|
if(isset($create))
|
||||||
$ops['create'] = $create;
|
$ops['create'] = $create;
|
||||||
|
|
||||||
|
drupal_add_js(drupal_get_path('module', 'materio_flag').'/js/materio_flag-ck.js');
|
||||||
|
|
||||||
$flaglists_links = theme('materio_flag_mylists_entity_links', $ops);
|
$flaglists_links = theme('materio_flag_mylists_entity_links', $ops);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$entity->content['links']['flaglistslinks'] = array('#markup' => $flaglists_links,"#html"=>true);
|
$entity->content['links']['flaglistslinks'] = array('#markup' => $flaglists_links,"#html"=>true);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Add css and javascript for modal dialog.
|
|
||||||
*/
|
|
||||||
function _materio_flag_include_modal() {
|
|
||||||
static $added = FALSE;
|
|
||||||
if ($added == FALSE) {
|
|
||||||
|
|
||||||
// Do not add css and scripts again.
|
|
||||||
$added = TRUE;
|
|
||||||
|
|
||||||
// Include the CTools tools that we need.
|
|
||||||
ctools_include('modal');
|
|
||||||
ctools_include('ajax');
|
|
||||||
ctools_modal_add_js();
|
|
||||||
|
|
||||||
// Create our own javascript that will be used to theme a modal.
|
|
||||||
$materio_flag_style = array(
|
|
||||||
'ctools-materio-flag-style' => array(
|
|
||||||
'modalSize' => array(
|
|
||||||
'type' => 'fixed',
|
|
||||||
'width' => 400,
|
|
||||||
'height' => 160,
|
|
||||||
'contentRight' => 30,
|
|
||||||
'contentBottom' => 0,
|
|
||||||
),
|
|
||||||
'modalOptions' => array(
|
|
||||||
'opacity' => 0.8,
|
|
||||||
'background-color' => '#FFF',
|
|
||||||
),
|
|
||||||
'closeText' => '',
|
|
||||||
'throbber' => theme('image', array('path' => ctools_image_path('ajax-loader.gif', 'ajax_register'))),
|
|
||||||
'animation' => 'fadeIn',
|
|
||||||
'animationSpeed' => 'fast',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
drupal_add_js($materio_flag_style, 'setting');
|
|
||||||
|
|
||||||
// Add module css and js.
|
|
||||||
//ctools_add_css('ajax-register', 'ajax_register');
|
|
||||||
//ctools_add_js('ajax-register', 'ajax_register');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Executes form.
|
|
||||||
*
|
|
||||||
* see _ajax_register_execute_form()
|
|
||||||
*/
|
|
||||||
function _materio_flag_addlists_execute_form($form_state, $nid){
|
|
||||||
|
|
||||||
$node = node_load($nid);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Include additional ajax commands.
|
|
||||||
ctools_include('ajax');
|
|
||||||
ctools_include('modal');
|
|
||||||
$message = t('@node has been added to newly created @name @title. The current page will be reloaded.', array(
|
|
||||||
'@node' => $node->title,
|
|
||||||
'@name' => variable_get('flag_lists_name', 'list'),
|
|
||||||
'@title' => $form_state['values']['title'])
|
|
||||||
);
|
|
||||||
|
|
||||||
$commands[] = ctools_modal_command_display(t('@title created', array('@title' => $form_state['values']['title'])), '<div>'.$message.'</div>'.theme('status_messages'));
|
|
||||||
// $commands[] = ctools_ajax_command_reload();
|
|
||||||
// dsm($form_state);
|
|
||||||
return $commands;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements hook_theme().
|
* Implements hook_theme().
|
||||||
*/
|
*/
|
||||||
|
@ -32,34 +32,68 @@ function materio_flag_refresh_block($flag){
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* materio_flag_createlist($type, $nid, $js)
|
* materio_flag_createlist($type)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function materio_flag_createlist($type, $nid, $js){
|
function materio_flag_createlist_form($type){
|
||||||
// Check whether js is enabled.
|
$debug = false;
|
||||||
if ($js) {
|
|
||||||
// Include ctools modal plugin.
|
|
||||||
ctools_include('modal');
|
|
||||||
|
|
||||||
$form_state = array('ajax' => TRUE);
|
$path = 'flag-lists/add/' . $type;
|
||||||
|
|
||||||
// Array with ajax response.
|
// check if request is ajax, if not rediret
|
||||||
$commands = array();
|
if (!$debug && (!isset($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest')) {
|
||||||
|
|
||||||
module_load_include('inc', 'flag_lists', 'flag_lists.admin');
|
|
||||||
$form_state['title'] = t('Create new @name', array('@name'=>variable_get('flag_lists_name', 'list')));
|
|
||||||
$form_state['build_info']['args'] = array(NULL, $type);
|
|
||||||
$commands = ctools_modal_form_wrapper('flag_lists_form', $form_state);
|
|
||||||
|
|
||||||
// If form was submited.
|
|
||||||
if (!empty($form_state['executed'])) {
|
|
||||||
$commands = _materio_flag_addlists_execute_form($form_state, $nid);
|
|
||||||
}
|
|
||||||
|
|
||||||
return array('#type' => 'ajax', '#commands' => $commands);
|
|
||||||
|
|
||||||
}else{
|
|
||||||
// If user has no js support redirect him to standart drupal forms.
|
|
||||||
drupal_goto('flag-lists/add/' . $type);
|
drupal_goto('flag-lists/add/' . $type);
|
||||||
|
exit ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// menu_set_active_item($path);
|
||||||
|
// $return = menu_execute_active_handler($path, FALSE);
|
||||||
|
|
||||||
|
// if (is_int($return)) {
|
||||||
|
// switch ($return) {
|
||||||
|
// case MENU_NOT_FOUND :
|
||||||
|
// drupal_add_http_header('Status', '404 Not Found');
|
||||||
|
// break;
|
||||||
|
// case MENU_ACCESS_DENIED :
|
||||||
|
// drupal_add_http_header('Status', '403 Forbidden');
|
||||||
|
// break;
|
||||||
|
// case MENU_SITE_OFFLINE :
|
||||||
|
// drupal_add_http_header('Status', '503 Service unavailable');
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// } elseif (isset($return)) {
|
||||||
|
$form_state['build_info']['args'] = array(null, $type);
|
||||||
|
// $form = drupal_get_form('flag_lists_form', $form_state);//, NULL, $type
|
||||||
|
$form = drupal_build_form('flag_lists_form', $form_state);
|
||||||
|
dsm($form, 'form');
|
||||||
|
|
||||||
|
// if (is_array($return)) {
|
||||||
|
$return = drupal_render($form);
|
||||||
|
// }
|
||||||
|
|
||||||
|
$rep = array(
|
||||||
|
'return'=>$return,
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($debug) {
|
||||||
|
dsm($rep, 'rep');
|
||||||
|
return "debug display";
|
||||||
|
}else{
|
||||||
|
drupal_json_output($rep);
|
||||||
|
}
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* materio_flag_createlist($type, $nid)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function materio_flag_createlist($title, $nid = null){
|
||||||
|
drupal_get_form('flag_lists_form', $title);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user