bookmarks fixing

Signed-off-by: bachy <git@g-u-i.net>
This commit is contained in:
bachy 2013-03-07 19:04:15 +01:00
parent 454adf9478
commit 06a4d254c2
6 changed files with 169 additions and 64 deletions

File diff suppressed because one or more lines are too long

View File

@ -52,40 +52,48 @@ MaterioFlag = function(){
var block = '#block-materio-flag-materio-flag-mylists';
}
if(type == 'lists'){
switch(type){
case 'bookmarks':
var name = type;
$('h2 .listname', block).attr('name', name).bind('click', onClickShowPreview);
$('<i class="icon-remove"></i>').appendTo($('h2', block)).attr('name', name).bind('click', onClickClosePreview);
// $('<span class="preview"><i class="icon-eye-open"></i></span>').appendTo($('h2', block)).bind('click', onClickShowPreview);
// if(!readCookie('materiobookmarkspreviewopened')){
// showPreview('bookmarks', block);
// }else{
// }
break;
case 'lists':
// 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');
// 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"><i class="icon-eye-open"></i></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);
var name = $this.attr('class').match(/flag_lists_[^_]+_[0-9]+/);
// trace('MaterioFlag :: name', name);
$('<span class="preview"><i class="icon-eye-open"></i></span>').attr('name', name).insertAfter($this).bind('click', onClickShowPreview);
});
$('a.open-list', this).bind('click', onClickOpenLink);
// 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');
// trigger refresh block event for enabling lazyload images
setTimeout(function(){
$.event.trigger({
type : 'my'+type+'-block-builded',
block : block,
name : name
});
},10);
}).addClass('ajax-processed');
break;
}
// trigger refresh block event for enabling lazyload images
setTimeout(function(){
$.event.trigger({
type : 'my'+type+'-block-builded',
block : block,
name : name
});
},10);
// trace('MaterioFlag :: activename', activename);
if(activename == undefined)
@ -93,9 +101,7 @@ MaterioFlag = function(){
// trace('MaterioFlag :: activename', activename);
if(activename)
showPreview(activename);
showPreview(activename, block);
};
function refreshBlocks(name){
@ -136,6 +142,14 @@ MaterioFlag = function(){
if (typeof Drupal.flagLink != 'undefined')
Drupal.flagLink(container);
if(isList()){
var fid = $('.materio-flags-list', '#content').attr('fid');
$('li.unflag-action.fid-'+fid+' a:not(.ajax-processed), li.flag-bookmarks a.unflag-action:not(.ajax-processed)')
.bind('click', onUnflagList)
.addClass('ajax-processed');
}
$('a.flag-lists-create:not(.ajax-processed)', container)
.bind('click', onClickCreatLink)
.addClass('ajax-processed');
@ -150,12 +164,12 @@ MaterioFlag = function(){
*/
function onClickShowPreview(event){
//trace('MaterioFlag :: onClickShowPreview', event);
showPreview($(this).attr('name'));
showPreview($(this).attr('name'), $(this).parent('.block').attr('id'));
};
function showPreview(name){
function showPreview(name, block){
//trace('MaterioFlag :: showPreview', name);
$('section.'+name, '#block-materio-flag-materio-flag-mylists').addClass('active')
$('section.'+name, block).addClass('active')
.siblings('section').removeClass('active');
createCookie('materiomyflaglistsopened', name, 1);
@ -166,7 +180,11 @@ MaterioFlag = function(){
function onClickClosePreview(event){
//trace('MaterioFlag :: onClickClosePreview', event);
eraseCookie('materiomyflaglistsopened');
$(this).parents('section.flag-list').removeClass('active');
if($(this).attr('name') == 'bookmarks'){
$(this).parents('.block').find('section.bookmarks').removeClass('active');
}else{
$(this).parents('section.flag-list').removeClass('active');
}
$.event.trigger('init-layout');
};
@ -321,8 +339,13 @@ MaterioFlag = function(){
// $('input.name', $(this)).val('');
// dialog.dialog('close');
//trace('MaterioFlag :: created list : data', data);
if($link.attr('nid') && $link.attr('token')){
flagEntityWithList(data.flag.name, $link.attr('nid'), $link.attr('token'));
}else{
refreshBlocks(data.flag.name);
refreshNodeLinks();
}
flagEntityWithList(data.flag.name, $link.attr('nid'), $link.attr('token'));
$modal.remove();
}
});
@ -523,7 +546,16 @@ MaterioFlag = function(){
$modal.remove();
}
});
}
};
/**
* onUnflagList()
*/
function onUnflagList(event){
//trace('onUnflagList', event);
$(this).parents('article.node').addClass('removed');
};
/**
*

View File

@ -37,13 +37,18 @@ function materio_flag_menu() {
'file' => 'materio_flag.pages.inc',
);
$items['materioflag/refresh/block/bookmarks'] = $base+array(
'access arguments' => array('flag bookmarks'),
'page callback' => 'materio_flag_refresh_block',
'page arguments' => array(3),
);
$items['bookmarks'] = $base+array(
'access arguments' => array('flag bookmarks'),
'page callback' => 'materio_flag_user_bookmarks',
'page arguments' => array(),
);
$items['materioflag/refresh/block/lists'] = $base+array(
'access arguments' => array('create flag lists'),
'page callback' => 'materio_flag_refresh_block',
@ -156,7 +161,9 @@ function materio_flag_block_view($delta = '') {
foreach ($userflags['bookmarks'] as $nid => $flag) {
$userbookmarks[] = node_load($nid);
}
$block['subject'] = t('My bookmarks (@len)', array("@len"=>count($userbookmarks)));
// TODO: put this title generation on a theme function
$subject = '<span class="listname">'.t('My bookmarks (@len) ', array("@len"=>count($userbookmarks))).'</span>';
$block['subject'] = $subject . l('<i class="icon-resize-full"></i>', 'bookmarks', array('html'=>true, 'attributes' => array('class' => array('open-list')),)); //
$block['content'] = theme('materio_flag_mybookmarks_block', array("bookmarks"=>$userbookmarks, "viewmode"=>"bookmark"));
}else{
$block['subject'] = t('My bookmarks');
@ -215,16 +222,17 @@ function materio_flag_block_view($delta = '') {
$flag->flaged_content = $flaged_content;
$flags[$name] = $flag;
}
if($flags){
// if($flags){
// $block['subject'] = t('My !listname'.'s', array('!listname'=>variable_get('flag_lists_name', 'list')));
$block['subject'] = t('My '.variable_get('flag_lists_name', 'list').'s');
$block['content'] = theme('materio_flag_mylists_nav_block', array("flags"=>$flags));
// $block['content'] = theme('flag_lists_user_page', array('uid' => $user->uid));
}
// }
# what happend if no flags yet
// else{
// $block['content'] = t('No !listname yet. Add !listname on clicking on results star', array('!listname'=>variable_get('flag_lists_name', 'list')));
// $block['subject'] = t('My '.variable_get('flag_lists_name', 'list').'s');
// // $block['content'] = t('No !listname yet. Add !listname on clicking on results star', array('!listname'=>variable_get('flag_lists_name', 'list')));
// }
}
break;
@ -339,7 +347,7 @@ function materio_flag_get_entity_links($entity, $type, $view_mode = null){
$items[] = array(
'data' => $link,
'class' => array('flag-lists-link', $action.'-action'),
'class' => array('flag-lists-link', $action.'-action', 'fid-'.$flag->fid),
);
}

View File

@ -333,6 +333,54 @@ function materio_flag_nodelinks(){
drupal_json_output($rep);
}
function materio_flag_user_bookmarks(){
global $user;
drupal_set_title(t('My bookmarks'), PASS_THROUGH);
$flaged = flag_get_user_flags('node');
// dsm($flaged, 'flaged');
$flag = flag_get_flag('bookmarks');
$flaged_content = $flaged['bookmarks'];
// dsm($flaged_content, 'flaged_content');
$viewmode = isset($user->data['materiosearchapi_viewmode']) ? $user->data['materiosearchapi_viewmode'] : variable_get('defaultviewmode', 'full');
$limit = variable_get($viewmode.'_limite', '10');
$offset = pager_find_page() * $limit;
$count = count($flaged_content);
$max = $offset+$limit > $count ? $count : $offset+$limit;
$i = 0;
foreach ($flaged_content as $id => $item) {
if($i >= $offset){
if($i < $max){
if($item->entity_type == 'node'){
$items[] = node_load($id);
}
}else{
break;
}
}
}
$ret['#items'] = $items;
$ret['#theme'] = 'materio_flag_mylists_list';
$ret['#view_mode'] = $viewmode;
$ret['#fid'] = $flag->fid;
$ret['#count'] = $count;
$ret['#name'] = variable_get('flag_lists_name', 'list');
$ret['#title'] = $flag->title;
pager_default_initialize($count, $limit);
$ret['#pager'] = theme('pager');
drupal_add_js(drupal_get_path('module', 'materio_flag').'/js/materio_flag-ck.js');
return $ret;
}
function materio_flag_user_lists($fid){
global $user;
$flag = flag_lists_get_flag($fid);
@ -368,7 +416,6 @@ function materio_flag_user_lists($fid){
$ret['#pager'] = theme('pager');
return $ret;
}
function materio_flag_ajax_list($fid, $page = 0){

View File

@ -1,4 +1,4 @@
<section class="mybookmarks">
<section class="bookmarks">
<?php print render(entity_view('node', $bookmarks, $viewmode)); ?>
</section>

View File

@ -1,21 +1,39 @@
<section class="mylists">
<ul>
<?php foreach ($flags as $name => $flag): ?>
<?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)))); ?>
<?php if(flag_lists_is_owner('edit', $flag->fid)): ?>
<?php
print l('<i class="icon-wrench"></i>',
'flags/lists/edit/'.$flag->fid,
array(
'html'=>true,
'attributes'=>array('class'=>array('edit-list', $flag->name)),
)
);
?>
<?php endif; ?>
</li>
<?php endforeach; ?>
<?php if($flags): ?>
<?php foreach ($flags as $name => $flag): ?>
<?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)))); ?>
<?php if(flag_lists_is_owner('edit', $flag->fid)): ?>
<?php
print l('<i class="icon-wrench"></i>',
'flags/lists/edit/'.$flag->fid,
array(
'html'=>true,
'attributes'=>array('class'=>array('edit-list', $flag->name)),
)
);
?>
<?php endif; ?>
</li>
<?php endforeach; ?>
<?php else: ?>
<?php
#create new list
$create_link = l(
'<i class="icon-plus"></i>&nbsp;<span>' . t('New @name', array('@name' => t(variable_get('flag_lists_name', 'list')))) . '</span>',
'flag-lists/add/materiau',
array(
'attributes' => array(
'class' => array('flag-lists-create'),
'title' => t('create a new @name.', array('@name'=>t(variable_get('flag_lists_name', 'list')))),
),
'html' => TRUE,
)
);
?>
<li class="flag-lists-create"><?php print $create_link; ?> </li>
<?php endif; ?>
</ul>
</section>