New folders block nav

++
search field : select on focus

Signed-off-by: bachy <git@g-u-i.net>
This commit is contained in:
bachy 2012-11-16 20:02:37 +01:00
parent 7dafe10be1
commit d2285db42a
11 changed files with 231 additions and 111 deletions

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,10 @@ MaterioFlag = function(){
* init()
*/
function init(){
trace('init MaterioFlag');
trace('MaterioFlag :: init MaterioFlag');
buildBlocks();
$(document)
.bind('flagGlobalAfterLinkUpdate', onFlaging)
.bind('resultscompleted resultschanged', onResultsUpdated)
@ -29,12 +32,48 @@ MaterioFlag = function(){
};
function onFlaging(event){
trace('onFlaging', event);
trace('MaterioFlag :: onFlaging', event);
refreshBlocks();
};
function onResultsUpdated(event){
trace('MaterioFlag :: onResultsUpdated', event);
ajaxifyLinks(event.container);
};
function buildBlocks(activename){
trace('MaterioFlag :: buildBlocks', activename);
// nav block
$('a.open-list:not(.ajax-processed)', '#block-materio-flag-materio-flag-mylists-nav').each(function(index){
$this = $(this)
.bind('click', onClickOpenLink)
.addClass('ajax-processed');
var name = $this.attr('class').match(/flag_lists_[^_]+_[0-9]+/);
// trace('MaterioFlag :: name', name);
$('<span class="preview">open preview</span>').attr('name', name).insertAfter($this).bind('click', onClickShowPreview);
});
// preview block
$('section.flag-list:not(.ajax-processed)', '#block-materio-flag-materio-flag-mylists').each(function(index){
var name = $(this).attr('class').match(/flag_lists_[^_]+_[0-9]+/);
$('<i class="icon-remove"></i>').appendTo($('h2.listname', this)).attr('name', name).bind('click', onClickClosePreview);
$('a.open-list', this).bind('click', onClickOpenLink);
}).addClass('ajax-processed');
// trace('MaterioFlag :: activename', activename);
if(activename == undefined)
activename = readCookie('materiomyflaglistsopened');
// trace('MaterioFlag :: activename', activename);
if(activename)
showPreview(activename);
};
function refreshBlocks(name){
trace('refreshBlocks | name', name);
trace('MaterioFlag :: refreshBlocks | name', name);
if($('#block-materio-flag-materio-flag-mybookmarks').length){
var type = 'bookmarks';
}else if($('#block-materio-flag-materio-flag-mylists').length){
@ -43,9 +82,14 @@ MaterioFlag = function(){
if(type != undefined){
var id = '#block-materio-flag-materio-flag-my'+type;
$.getJSON(Drupal.settings.basePath+Drupal.settings.pathPrefix+'materioflag/refresh/block/'+type, function(json){
trace('block refreshed '+type, json);
var url = Drupal.settings.basePath+Drupal.settings.pathPrefix+'materioflag/refresh/block/'+type;
$.getJSON(url, function(json){
trace('MaterioFlag :: block refreshed '+type, json);
$(id).replaceWith(json.block);
$('#block-materio-flag-materio-flag-mylists-nav').replaceWith(json.block_nav);
buildBlocks(name);
$.event.trigger({
type : 'my'+type+'-block-updated',
@ -57,34 +101,54 @@ MaterioFlag = function(){
ajaxifyLinks();
};
function onResultsUpdated(event){
trace('MaterioFlag :: onResultsUpdated', event);
ajaxifyLinks(event.container);
};
function ajaxifyLinks(container){
trace('ajaxifyLinks', container);
trace('MaterioFlag :: ajaxifyLinks', container);
container = ((container != null) ? container : 'body');
// trace('typeof Drupal.flagLink', typeof Drupal.flagLink);
// trace('MaterioFlag :: typeof Drupal.flagLink', typeof Drupal.flagLink);
if (typeof Drupal.flagLink != 'undefined')
Drupal.flagLink(container);
$('a.flag-lists-create:not(.ajax-processed)', container)
.bind('click', onClickCreatLink)
.addClass('ajax-processed');
$('a.open-list:not(.ajax-processed)', '#block-materio-flag-materio-flag-mylists')
.bind('click', onClickOpenLink)
.addClass('ajax-processed');
};
/**
* show hide preview
*/
function onClickShowPreview(event){
trace('MaterioFlag :: onClickShowPreview', event);
showPreview($(this).attr('name'));
};
function showPreview(name){
trace('MaterioFlag :: showPreview', name);
$('section.'+name, '#block-materio-flag-materio-flag-mylists').addClass('active')
.siblings('section').removeClass('active');
createCookie('materiomyflaglistsopened', name, 1);
$.event.trigger('init-layout');
};
function onClickClosePreview(event){
trace('MaterioFlag :: onClickClosePreview', event);
eraseCookie('materiomyflaglistsopened');
$(this).parents('section.flag-list').removeClass('active');
$.event.trigger('init-layout');
};
/**
* onClickOpenLink
*/
function onClickOpenLink(event){
event.preventDefault();
var $link = $(event.currentTarget);
var fid = $link.attr('href').match(/lists\/([0-9]+)$/);
// trace('type', type);
// trace('MaterioFlag :: type', type);
loadList(fid[1]);
return false;
};
@ -95,7 +159,7 @@ MaterioFlag = function(){
$.event.trigger('loading-content');
$.getJSON(url, function(json){
trace('json', json);
trace('MaterioFlag :: json', json);
changeContent(json);
});
};
@ -128,7 +192,7 @@ MaterioFlag = function(){
triggerContentChanged();
}else{
trace('no results');
trace('MaterioFlag :: no results');
}
};
@ -139,15 +203,18 @@ MaterioFlag = function(){
});
};
/**
* onClickCreatLink(event)
*/
function onClickCreatLink(event){
event.preventDefault();
var $link = $(event.currentTarget);
var type = $link.attr('href').match(/[^\/]*$/);
// trace('type', type);
// trace('MaterioFlag :: type', type);
var url = Drupal.settings.basePath+Drupal.settings.pathPrefix+'materioflag/createlist/form/'+type[0];
$.getJSON(url, function(json){
trace('json', json);
trace('MaterioFlag :: json', json);
showCreateListForm(json, $link);
});
return false;
@ -175,7 +242,7 @@ MaterioFlag = function(){
event.preventDefault();
switch($(this).attr('name')){
case 'cancel':
trace('cancel',event);
trace('MaterioFlag :: cancel',event);
$(this).parents('#modal').remove();
// google analytics
@ -187,7 +254,7 @@ MaterioFlag = function(){
break;
case 'create':
trace('create',event);
trace('MaterioFlag :: create',event);
var title = $(this).parents('form').find('input[name*="flag-lists-name"]').val();
var type = $(this).parents('form').find('input[name*="type"]').val();
@ -219,7 +286,7 @@ MaterioFlag = function(){
// select.append('<option value="'+data.flag.fid+'">'+data.flag.title+'</option>');
// $('input.name', $(this)).val('');
// dialog.dialog('close');
trace('created list : data', data);
trace('MaterioFlag :: created list : data', data);
flagEntityWithList(data.flag.name, $link.attr('nid'), $link.attr('token'));
$modal.remove();
@ -236,7 +303,7 @@ MaterioFlag = function(){
data: { js: true, token: token },
dataType: 'json',
success: function (data2) {
trace('node taged with newly created list : data2', data2)
trace('MaterioFlag :: node taged with newly created list : data2', data2)
if (data2.status) {
// google analytics
@ -266,17 +333,17 @@ MaterioFlag = function(){
$('.flag-lists-entity-links').parents('.node').each(function(index) {
nids.push($(this).attr('class').match(/node-([0-9]+)/)[1]);
});
// trace('nids', nids);
// trace('MaterioFlag :: nids', nids);
var url = Drupal.settings.basePath+Drupal.settings.pathPrefix+'materioflag/nodelinks';
$.getJSON(url, {nids:nids.join(";")}, function(data) {
// trace('data', data);
// trace('MaterioFlag :: data', data);
for(nid in data.links){
// trace('nid', nid);
// trace('data.links[nid]', data.links[nid]);
// trace('MaterioFlag :: nid', nid);
// trace('MaterioFlag :: data.links[nid]', data.links[nid]);
$('.node-'+nid+' .flag-lists-entity-links').parent('.item-list').replaceWith(data.links[nid]);
// trace('typeof Drupal.flagLink', typeof Drupal.flagLink);
// trace('MaterioFlag :: typeof Drupal.flagLink', typeof Drupal.flagLink);
// if (typeof Drupal.flagLink != 'undefined')
// Drupal.flagLink($('.node-'+nid+' .flag-lists-entity-links'));
@ -292,9 +359,9 @@ MaterioFlag = function(){
};
function onInitScrollerPager(event){
// trace('MaterioFlag :: onInitScrollerPager');
// trace('MaterioFlag :: MaterioFlag :: onInitScrollerPager');
if (isList()){
// trace('event.pager', event);
// trace('MaterioFlag :: event.pager', event);
event.pager.hide();
}
};
@ -305,18 +372,18 @@ MaterioFlag = function(){
};
function loadNextListPage(href){
// trace('loadNextListPage', href);
// trace('MaterioFlag :: loadNextListPage', href);
if(!_isLoadingList){
var fid = href.match(/lists\/([^\/|\?]+)/);
var page = href.match(/\?page=([0-9]+)/);
var url = Drupal.settings.basePath+Drupal.settings.pathPrefix+'materioflag/ajax/list/'+fid[1]+'/'+page[1];
// trace('url', url);
// trace('MaterioFlag :: url', url);
loadNextPage(url, $('.materio-flags-list', '#content'), '.flaglist-items');
}
};
function loadNextPage(url, $container, target){
trace('loadNextPage');
trace('MaterioFlag :: loadNextPage');
_isLoadingList = true;
$container.addClass('loading');
$.getJSON(url, function(json){
@ -377,6 +444,35 @@ MaterioFlag = function(){
};
/**
* cookies
*/
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function eraseCookie(name) {
createCookie(name,"",-1);
}
init();

File diff suppressed because one or more lines are too long

View File

@ -14,7 +14,6 @@ MaterioSearchApiAjax = function(){
initSearchAjax();
initViewMode();
};
/**
@ -33,9 +32,13 @@ MaterioSearchApiAjax = function(){
});
// /!\ AUTOCOMPLETE SELECT EVENT need a patch http://drupal.org/node/365241#comment-5374686
$("#edit-searchfield").bind('autocompleteSelect', function(event) {
$(this).parents('.form').trigger('submit');
});
$("#edit-searchfield")
.bind('autocompleteSelect', function(event) {
$(this).parents('.form').trigger('submit');
})
.bind('focus', function(event){
$(this).select();
});
$(document)
.bind('init-scroller-pager', onInitScrollerPager)
@ -79,14 +82,6 @@ MaterioSearchApiAjax = function(){
_isloadingresults = true;
$('#materio-search-api-search-form').addClass('loading');
// google analytics
$.event.trigger({
type : "record-stat",
categorie : 'Search event',
action : 'Search',
label : 'keys :'+ keys +' | filters : '+ stringTypes.join(' ,')
});
// TODO: record ajax path in a variable from materio_search_api_ajax_init
$.getJSON(Drupal.settings.basePath+Drupal.settings.pathPrefix+'materio_search_api_ajax/search/'+keys,
{'types':types},
@ -96,6 +91,15 @@ MaterioSearchApiAjax = function(){
_isloadingresults = false;
$('#materio-search-api-search-form').removeClass('loading');
// google analytics
$.event.trigger({
type : "record-stat",
categorie : 'Search',
action : keys,
label : 'filters : '+ stringTypes.join(' ,'),
value : json.count
});
changeContent(json);
});
}
@ -133,7 +137,7 @@ MaterioSearchApiAjax = function(){
$.event.trigger({
type : 'new-history-page',
path : Drupal.settings.basePath + Drupal.settings.pathPrefix + json.search_path + '/' + json.keys,
path : Drupal.settings.basePath + Drupal.settings.pathPrefix + json.path,
title : json.title,
content : json.return
});

View File

@ -150,7 +150,7 @@ function materio_flag_block_view($delta = '') {
$node = node_load($entity->entity_id);
// dsm($node, 'node');
$node->flag_names[] = $name;
// $node->flag_names[] = $name;
$fcn[] = $node;
}
}
@ -162,7 +162,7 @@ function materio_flag_block_view($delta = '') {
}
if(isset($lists)){
$block['subject'] = t('My !listname'.'s', array('!listname'=>variable_get('flag_lists_name', 'list')));
$block['subject'] = t('My !listname'.'s', array('!listname'=>t(variable_get('flag_lists_name', 'list'))));
$block['content'] = theme('materio_flag_mylists_block', array("lists"=>$lists, "viewmode"=>"bookmark"));
// $block['content'] = theme('flag_lists_user_page', array('uid' => $user->uid));
}else{
@ -176,10 +176,12 @@ function materio_flag_block_view($delta = '') {
case 'materio_flag_mylists_nav':
if(user_access('create flag lists')){
$flags = flag_lists_get_user_flags(NULL, $user);
// foreach ($flags as $name => $flag) {
// # code...
// }
foreach ($flags as $name => $flag) {
$flaged_content = flag_lists_get_flagged_content($flag->fid, $user->uid);
$flag->flaged_content = $flaged_content;
$flags[$name] = $flag;
}
$block['subject'] = t('My !listname'.'s', array('!listname'=>variable_get('flag_lists_name', 'list')));
$block['content'] = theme('materio_flag_mylists_nav_block', array("flags"=>$flags));
@ -208,13 +210,25 @@ function materio_flag_entity_info_alter(&$entity_info) {
function materio_flag_entity_view($entity, $type, $view_mode, $langcode) {
if($type == 'node'){
if(user_access('create flag lists')){
$flaglists_links = materio_flag_get_entity_links($entity, $type, $view_mode);
// dsm($flaglists_links, 'flaglists_links');
$entity->content['links']['flaglistslinks'] = array('#markup' => $flaglists_links,"#html"=>true);
$entity->content['flaglistslinks'] = materio_flag_get_entity_links($entity, $type, $view_mode);
drupal_add_css(drupal_get_path('module', 'flag') . '/theme/flag.css');
drupal_add_js(drupal_get_path('module', 'flag') . '/theme/flag.js');
// Do we have a list template for this node type, or are we s
if (flag_lists_template_exists($entity->type)) {
global $user;
if ($flags = flag_lists_get_user_flags($entity->type, $user)) {
foreach ($flags as $flag) {
// dsm($flag, 'flag');
if ( ($flag->module == 'flag_lists' && _flag_lists_is_flagged($flag, $entity->nid, $user->uid, 0)) || $flag->is_flagged($entity->nid) ) {
$entity->flags[] = $flag;
}
}
}
}
}
}
}
@ -228,7 +242,7 @@ function materio_flag_get_entity_links($entity, $type, $view_mode = null){
}
global $user;
$links = array();
# if flag name is provided we are on flaglists content list (block mylists)
if($view_mode == 'bookmark'){
// TODO: define view mode in settings
@ -287,15 +301,17 @@ function materio_flag_get_entity_links($entity, $type, $view_mode = null){
'data' => $link,
'class' => array('flag-lists-link', $action.'-action'),
);
}
}
// dsm($items, 'items '.$entity->title);
#create new list
$link = l(
'<span>' . t('New @name', array('@name' => variable_get('flag_lists_name', t('list')))) . '</span>&nbsp;<i class="icon-plus"></i>',
'flag-lists/add/' . $entity->type,
array(
// 'query' => drupal_get_destination(),
'attributes' => array(
'class' => array('flag-lists-create'),
'title' => t('create a new @name and use it.', array('@name'=>variable_get('flag_lists_name', t('list')))),
@ -312,27 +328,22 @@ function materio_flag_get_entity_links($entity, $type, $view_mode = null){
);
}
// if( (!isset($items) || !count($items)) && !isset($create))
// return;
if(isset($items)){
$ops = array(
'node' => $entity,
'items' => $items,
'#node' => $entity,
'#items' => $items,
);
}
if(isset($create)){
$ops['create'] = $create;
// drupal_add_css(drupal_get_path('module', 'flag') . '/theme/flag.css');
// drupal_add_js(drupal_get_path('module', 'flag') . '/theme/flag.js');
$ops['#create'] = $create;
}
if(isset($ops)){
// dsm($ops, 'ops');
drupal_add_js(drupal_get_path('module', 'materio_flag').'/js/materio_flag-ck.js');
return theme('materio_flag_mylists_entity_links', $ops);
$ops['#theme'] = "materio_flag_mylists_entity_links";
return $ops;
}
return;

View File

@ -1,32 +1,39 @@
<?php
/**
* materio_flag_refresh_block($flag)
* materio_flag_refresh_blocks($flag)
*
*/
function materio_flag_refresh_block($flag){
$rep = array();
switch ($flag) {
case 'bookmarks':
$block_name = 'materio_flag_mybookmarks';
break;
case 'lists':
$block_name = 'materio_flag_mylists';
$block_nav_name = 'materio_flag_mylists_nav';
break;
}
if(!isset($block_name))
return;
// $block_content = module_invoke('block', 'block_view', 'materio_flag_mybookmarks');
$rep = array();
$block = block_load('materio_flag', $block_name);
$block_content = _block_render_blocks(array($block));
$build = _block_get_renderable_array($block_content);
$block_rendered = drupal_render($build);
$rep['block'] = $block_rendered;
if(isset($block_nav_name))
$block = block_load('materio_flag', $block_nav_name);
$block_content = _block_render_blocks(array($block));
$build = _block_get_renderable_array($block_content);
$block_rendered = drupal_render($build);
$rep['block_nav'] = $block_rendered;
$rep['block'] = $block_rendered;
drupal_json_output($rep);
}
@ -93,18 +100,17 @@ function materio_flag_createlist_form($type){
'#suffix' => '</div>',
);
$form['actions']['create'] = array(
'#type' => 'submit',
'#value' => t('create'),
'#name' => 'create',
);
$form['actions']['cancel'] = array(
'#type' => 'button',
'#value' => t('cancel'),
'#name' => 'cancel',
);
$form['actions']['create'] = array(
'#type' => 'submit',
'#value' => t('create'),
'#name' => 'create',
);
// dsm($form, 'form');
@ -130,7 +136,7 @@ function materio_flag_nodelinks(){
if(count($nids)){
foreach ($nids as $nid) {
$node = node_load($nid);
$lks = materio_flag_get_entity_links($node, 'node');
$lks = render(materio_flag_get_entity_links($node, 'node'));
$links[$nid] = $lks;
}

View File

@ -415,8 +415,6 @@ function template_preprocess_materio_search_api_select_viewmode_block(&$vars){
$entity_infos = entity_get_info();
// dsm($entity_infos, 'entity_infos');
// TODO: refaire les boutons view modes pour qu'il fonctionne sans javascript
// faire un lien vers l'enregistrement du mode puis un reload de la page courante
$content = '<div class="btn-group btn-group-vertical">';
foreach ($entity_infos['node']['view modes'] as $viewmode => $value) {
if(in_array($viewmode, $availableviewmodes)){
@ -502,14 +500,6 @@ function template_preprocess_materio_search_api_results(array &$variables) {
array('@sec' => $variables['sec'])
);
// $variables['search_results'] = array(
// '#theme' => 'search_results_list',
// 'results' => $variables['results']['results'],
// 'items' => $variables['items'],
// 'index' => $variables['index'],
// 'type' => 'ul',
// );
//dsm($variables, 'variables');
}
@ -517,11 +507,6 @@ function template_preprocess_materio_search_api_results(array &$variables) {
function template_preprocess_materio_search_api_actuality(&$vars){
// dsm($vars, 'template_preprocess_materio_search_api_actuality | vars');
// $items = array();
// foreach ($vars['items'] as $nid => $item) {
// $items[] = node_load($nid);
// }
// $vars['items'] = $items;
$vars['actualities_infos'] = t('Actualities by materiO\'');
}

View File

@ -64,17 +64,22 @@ function materio_search_api_ajax_search($keys, $page = 0){
} elseif (isset($return)) {
if (is_array($return)) {
$count = $return['results']['#results']['result count'];
$return = drupal_render($return);
// $return = theme($return['#theme'], $return);
}
$rep = array(
// 'id'=>$id,
'path'=>$path,
'keys'=>$keys,
'search_path'=>$search_path,
'return'=>$return,
'active_types'=>$active_types,
'title' => drupal_get_title(),
);
if(isset($count))
$rep['count'] = $count;
if ($debug) {
dsm($rep, 'rep');
@ -146,6 +151,7 @@ function materio_search_api_ajax_actuality($page = 0){
}
$rep = array(
'path' => $path,
'return'=>$return,
'title' => drupal_get_title(),
);

View File

@ -1,10 +1,17 @@
<section class="mylists">
<div class="mylists">
<?php foreach ($lists as $name => $list): ?>
<?php //dsm($list, 'list');?>
<h2 class="listname <?php print $list['list']->name; ?>">
<span><?php print $list['list']->title.' ('.count($list['content']).')'; ?></span>
<a class="open-list" href="<?php print $list['list']->path; ?>"><?php print t('open this @name', array('@name'=>variable_get('flag_lists_name', 'list'))) ;?></a>
</h2>
<div class="flaged <?php print $list['list']->name; ?>"> <?php print render(entity_view('node', $list['content'], $viewmode)); ?> </div>
<section class="flag-list <?php print $list['list']->name; ?>">
<?php //dsm($list, 'list');?>
<h2 class="listname">
<span class="listname">
<?php print $list['list']->title.' ('.count($list['content']).')'; ?>
</span>
<a class="open-list" href="<?php print $list['list']->path; ?>">
<?php //print t('open this @name', array('@name'=>variable_get('flag_lists_name', 'list'))) ;?>
<?php print t('open'); ?>
</a>
</h2>
<div class="flaged <?php print $list['list']->name; ?>"> <?php print render(entity_view('node', $list['content'], $viewmode)); ?> </div>
</section>
<?php endforeach; ?>
</section>
</div>

View File

@ -1,7 +1,10 @@
<section class="mylists">
<ul>
<?php foreach ($flags as $name => $flag): ?>
<li class="flaglist <?php print $flag->name; ?>"><?php print $flag->title; ?></li>
<?php //dsm($flag, 'flag') ;?>
<li class="flaglist <?php print $flag->name; ?>">
<?php print l($flag->title . '<span class="count">('.count($flag->flaged_content).')</span>', 'lists/'.$flag->fid, array('html'=>true,'attributes'=>array('class'=>array('open-list', $flag->name)))); ?>
</li>
<?php endforeach; ?>
</ul>
</section>

View File

@ -33,18 +33,20 @@
?>
<?php //dsm($index, 'index'); ?>
<?php //dsm($search_performance, 'search_performance'); ?>
<?php //dsm($result_count, 'result_count'); ?>
<?php if (!empty($result_count)) : ?>
<?php //if (!empty($result_count)) : ?>
<div class="materiobase-results <?php print ' view-mode-' . $variables['view_mode'];?>">
<?php if ($result_count) : ?>
<p class="search-performance"><?php print render($search_performance); ?></p>
<?php //print render($spellcheck); ?>
<div class="search-results">
<?php //dsm($items, '$items'); ?>
<?php print render(entity_view($index->item_type, $items, $variables['view_mode'])); ?>
</div>
<?php print $pager; ?>
<?php else : ?>
<h2><?php print t('Your search yielded no results.');?></h2>
<p class="search-noresults"><?php print t('Your search yielded no results.');?></p>
<?php endif; ?>
</div>
<?php endif; ?>
<?php //endif; ?>