Flag list OK
all ajax OK Signed-off-by: bachy <git@g-u-i.net>
This commit is contained in:
parent
1d11663ec4
commit
b1bf1c9387
File diff suppressed because one or more lines are too long
@ -3,55 +3,135 @@
|
||||
(function($) {
|
||||
|
||||
MaterioFlag = function(){
|
||||
|
||||
var _isLoadingList = false ;
|
||||
|
||||
/**
|
||||
* init()
|
||||
*/
|
||||
function init(){
|
||||
trace('init MaterioFlag');
|
||||
$(document).bind('flagGlobalAfterLinkUpdate', onFlaging);
|
||||
$(document).bind('resultscompleted', onResultsUpdated);
|
||||
$(document)
|
||||
.bind('flagGlobalAfterLinkUpdate', onFlaging)
|
||||
.bind('resultscompleted resultschanged', onResultsUpdated)
|
||||
.bind('init-scroller-pager', onInitScrollerPager)
|
||||
.bind('load-scroller-pager', onLoadScrollerPager)
|
||||
.bind('view-mode-changed', onViewModeChanged)
|
||||
.bind('history-state-change', onHistoryStateChange);
|
||||
|
||||
ajaxifyLinks();
|
||||
|
||||
// trigger updated event for direct html loading
|
||||
setTimeout(function(){
|
||||
triggerContentChanged();
|
||||
}, 10);
|
||||
};
|
||||
|
||||
function onFlaging(event){
|
||||
trace('onFlaging', event);
|
||||
refreshBlocks();
|
||||
};
|
||||
|
||||
function refreshBlocks(name){
|
||||
trace('refreshBlocks | name', name);
|
||||
if($('#block-materio-flag-materio-flag-mybookmarks').length){
|
||||
$.getJSON('/materioflag/refresh/block/bookmarks', function(json){
|
||||
trace('json', json);
|
||||
$('#block-materio-flag-materio-flag-mybookmarks').replaceWith(json.block);
|
||||
Drupal.flagLink('#block-materio-flag-materio-flag-mybookmarks');
|
||||
// TODO: update flags stars on search results after unflaging from block
|
||||
$.event.trigger('mybookmarks-block-updated');
|
||||
});
|
||||
}
|
||||
|
||||
if($('#block-materio-flag-materio-flag-mylists').length){
|
||||
$.getJSON('/materioflag/refresh/block/mylists', function(json){
|
||||
trace('json', json);
|
||||
$('#block-materio-flag-materio-flag-mylists').replaceWith(json.block);
|
||||
Drupal.flagLink('#block-materio-flag-materio-flag-mylists');
|
||||
// TODO: update flags stars on search results after unflaging from block
|
||||
$.event.trigger('mylists-block-updated');
|
||||
var type = 'bookmarks';
|
||||
}else if($('#block-materio-flag-materio-flag-mylists').length){
|
||||
var type = 'lists';
|
||||
}
|
||||
|
||||
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);
|
||||
$(id).replaceWith(json.block);
|
||||
|
||||
var event = jQuery.Event('my'+type+'-block-updated');
|
||||
event.listname = name;
|
||||
$.event.trigger(event);
|
||||
});
|
||||
}
|
||||
|
||||
ajaxifyLinks();
|
||||
};
|
||||
|
||||
function onResultsUpdated(event){
|
||||
trace('onResultsUpdated', event);
|
||||
|
||||
ajaxifyLinks(event.container);
|
||||
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 ajaxifyLinks(container){
|
||||
trace('ajaxifyLinks', container);
|
||||
|
||||
container = ((container != null) ? container : 'body');
|
||||
|
||||
// trace('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');
|
||||
};
|
||||
|
||||
function onClickOpenLink(event){
|
||||
event.preventDefault();
|
||||
var $link = $(event.currentTarget);
|
||||
var fid = $link.attr('href').match(/lists\/([0-9]+)$/);
|
||||
// trace('type', type);
|
||||
loadList(fid[1]);
|
||||
return false;
|
||||
};
|
||||
|
||||
function loadList(fid){
|
||||
var url = Drupal.settings.basePath+Drupal.settings.pathPrefix+'materioflag/ajax/list/'+fid;
|
||||
|
||||
$.event.trigger('loading-content');
|
||||
|
||||
$.getJSON(url, function(json){
|
||||
trace('json', json);
|
||||
changeContent(json);
|
||||
});
|
||||
};
|
||||
|
||||
function changeContent(json){
|
||||
if(json.return){
|
||||
|
||||
$('.inner-content','#content').html(json.return);
|
||||
|
||||
$.event.trigger('loaded-content');
|
||||
|
||||
// no need of ajaxifylinks because it's triggered with resultschanged
|
||||
// ajaxifyLinks('#content');
|
||||
|
||||
var path = Drupal.settings.basePath + Drupal.settings.pathPrefix + json.path;
|
||||
|
||||
var event = jQuery.Event('new-history-page');
|
||||
event.path = path;
|
||||
event.title = json.title;
|
||||
event.content = json.return;
|
||||
$.event.trigger(event);
|
||||
|
||||
// TODO: change language links for folders
|
||||
// for (language in Drupal.settings.materio_search_api_ajax.languages) {
|
||||
// var l = Drupal.settings.materio_search_api_ajax.languages[language];
|
||||
// $('#block-locale-language li.'+language+' a').attr('href', Drupal.settings.basePath + l.prefix+'/' + json.search_path + '/' + json.keys)
|
||||
// };
|
||||
|
||||
triggerContentChanged();
|
||||
|
||||
}else{
|
||||
trace('no results');
|
||||
}
|
||||
};
|
||||
|
||||
function triggerContentChanged(){
|
||||
var event = jQuery.Event('resultschanged');
|
||||
event.container = '#content .flaglist-items';
|
||||
$.event.trigger(event);
|
||||
};
|
||||
|
||||
function onClickCreatLink(event){
|
||||
@ -59,40 +139,203 @@ MaterioFlag = function(){
|
||||
var $link = $(event.currentTarget);
|
||||
var type = $link.attr('href').match(/[^\/]*$/);
|
||||
// trace('type', type);
|
||||
var url = 'materioflag/createlist/form/'+type[0];
|
||||
var url = Drupal.settings.basePath+Drupal.settings.pathPrefix+'materioflag/createlist/form/'+type[0];
|
||||
|
||||
$.getJSON(url, function(json){
|
||||
trace('json', json);
|
||||
showCreateListForm(json);
|
||||
showCreateListForm(json, $link);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
function showCreateListForm(json){
|
||||
var $modal = $('<div id="modal"/>').appendTo('body');
|
||||
function showCreateListForm(json, $link){
|
||||
var $modal = $('<div id="modal" class="modal"/>').appendTo('body');
|
||||
$modal
|
||||
.css({
|
||||
position:'absolute',
|
||||
top:'40%', left:'50%',
|
||||
marginLeft:'-200px', width:'400px',
|
||||
marginLeft:'-150px', width:'300px',
|
||||
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;
|
||||
// });
|
||||
.append(json.return)
|
||||
.find('input[type="submit"]', '#materio-flag-create-list-form').bind('click', function(event) {
|
||||
event.preventDefault();
|
||||
switch($(this).attr('name')){
|
||||
case 'cancel':
|
||||
trace('cancel',event);
|
||||
$(this).parents('#modal').remove();
|
||||
break;
|
||||
case 'create':
|
||||
trace('create',event);
|
||||
var title = $(this).parents('form').find('input[name*="flag-lists-name"]').val();
|
||||
var type = $(this).parents('form').find('input[name*="type"]').val();
|
||||
createList($modal, type, title, $link);
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
})
|
||||
.parents('form').find('input[type="text"]').focus();
|
||||
};
|
||||
|
||||
function createList(title){
|
||||
var url = 'materioflag/createlist/'+title;
|
||||
$.getJSON(url, function(json){
|
||||
trace('json', json);
|
||||
function createList($modal, type, title, $link){
|
||||
var url = Drupal.settings.basePath+Drupal.settings.pathPrefix+'flag-lists/add/'+type+'/js';
|
||||
$.getJSON(url, {name:title}, function(data) {
|
||||
if (data.error) {
|
||||
trace(data.error);
|
||||
}
|
||||
else {
|
||||
// select.append('<option value="'+data.flag.fid+'">'+data.flag.title+'</option>');
|
||||
// $('input.name', $(this)).val('');
|
||||
// dialog.dialog('close');
|
||||
trace('created list : data', data);
|
||||
|
||||
flagEntityWithList(data.flag.name, $link.attr('nid'), $link.attr('token'));
|
||||
$modal.remove();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
function flagEntityWithList(name, nid, token){
|
||||
// var ret;
|
||||
// Send POST request
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: Drupal.settings.basePath+Drupal.settings.pathPrefix+'flag-lists/flag/'+name+'/'+nid,
|
||||
data: { js: true, token: token },
|
||||
dataType: 'json',
|
||||
success: function (data2) {
|
||||
trace('node taged with newly created list : data2', data2)
|
||||
if (data2.status) {
|
||||
// success
|
||||
refreshBlocks(name);
|
||||
refreshNodeLinks();
|
||||
}else {
|
||||
// Failure.
|
||||
alert(data2.errorMessage);
|
||||
}
|
||||
},
|
||||
error: function (xmlhttp) {
|
||||
alert('An HTTP error '+ xmlhttp.status +' occurred.\n'+ element.href);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
function refreshNodeLinks(){
|
||||
|
||||
var nids = new Array();
|
||||
$('.flag-lists-entity-links').parents('.node').each(function(index) {
|
||||
nids.push($(this).attr('class').match(/node-([0-9]+)/)[1]);
|
||||
});
|
||||
trace('nids', nids);
|
||||
|
||||
var url = Drupal.settings.basePath+Drupal.settings.pathPrefix+'materioflag/nodelinks';
|
||||
$.getJSON(url, {nids:nids.join(";")}, function(data) {
|
||||
trace('data', data);
|
||||
for(nid in data.links){
|
||||
trace('nid', nid);
|
||||
trace('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);
|
||||
// if (typeof Drupal.flagLink != 'undefined')
|
||||
// Drupal.flagLink($('.node-'+nid+' .flag-lists-entity-links'));
|
||||
|
||||
ajaxifyLinks('.node-'+nid+' .flag-lists-entity-links');
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
var event = jQuery.Event('materioflag-nodelinks-updated');
|
||||
event.nids = nids;
|
||||
$.event.trigger(event);
|
||||
};
|
||||
|
||||
function onInitScrollerPager(event){
|
||||
// trace('MaterioFlag :: onInitScrollerPager');
|
||||
if (isList()){
|
||||
// trace('event.pager', event);
|
||||
event.pager.hide();
|
||||
}
|
||||
};
|
||||
|
||||
function onLoadScrollerPager(event){
|
||||
if (isList())
|
||||
loadNextListPage(event.href);
|
||||
};
|
||||
|
||||
function loadNextListPage(href){
|
||||
// trace('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);
|
||||
loadNextPage(url, $('.materio-flags-list', '#content'), '.flaglist-items');
|
||||
}
|
||||
};
|
||||
|
||||
function loadNextPage(url, $container, target){
|
||||
trace('loadNextPage');
|
||||
_isLoadingList = true;
|
||||
$container.addClass('loading');
|
||||
$.getJSON(url, function(json){
|
||||
trace('json', json);
|
||||
_isLoadingList = false;
|
||||
$container.removeClass('loading');
|
||||
addNextpage(json, target);
|
||||
});
|
||||
};
|
||||
|
||||
function addNextpage(json, container_class){
|
||||
var $newcontent = $(json.return),
|
||||
$newitems = $(container_class, $newcontent).children('article').addClass('just-added'),
|
||||
$newpager = $('ul.pager', $newcontent);
|
||||
|
||||
$(container_class, '#content').append($newitems);
|
||||
$('ul.pager', '#content').replaceWith($newpager.hide());
|
||||
|
||||
|
||||
// TODO: animation, this should be on theme side
|
||||
$(container_class, '#content').children('.just-added').each(function(i){
|
||||
// $(this).delay(5000*i).removeClass('just-added');
|
||||
var $this = $(this);
|
||||
setTimeout(function(){
|
||||
$this.removeClass('just-added');
|
||||
}, 150*i);
|
||||
});
|
||||
|
||||
var event = jQuery.Event('resultscompleted');
|
||||
event.container = $(container_class, '#content');
|
||||
$.event.trigger(event);
|
||||
};
|
||||
|
||||
function onViewModeChanged(event){
|
||||
if (isList())
|
||||
loadList(getFid());
|
||||
};
|
||||
|
||||
/**
|
||||
* history
|
||||
*/
|
||||
function onHistoryStateChange(event){
|
||||
if(isList())
|
||||
triggerContentChanged();
|
||||
};
|
||||
|
||||
/**
|
||||
* Helpers
|
||||
*/
|
||||
|
||||
function getFid(){
|
||||
return $('.materio-flags-list', '#content').attr('fid');;
|
||||
};
|
||||
|
||||
function isList(){
|
||||
return $('.materio-flags-list', '#content').length;
|
||||
};
|
||||
|
||||
|
||||
init();
|
||||
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
@ -3,21 +3,16 @@
|
||||
(function($) {
|
||||
|
||||
MaterioSearchApiAjax = function(){
|
||||
|
||||
var _History = window.History,
|
||||
_isloadingresults = false;
|
||||
_$content = $('#content'),
|
||||
isExplore = $('.search-results', _$content).length,
|
||||
isActuality = $('.actuality-items', _$content).length;
|
||||
var _isloadingresults = false;
|
||||
var _$content = $('#content');
|
||||
// TODO: define $content by module settings
|
||||
/**
|
||||
* init()
|
||||
*/
|
||||
function init(){
|
||||
trace('init module');
|
||||
trace('init MaterioSearchApiAjax');
|
||||
|
||||
initSearchAjax();
|
||||
initHistoryNav();
|
||||
initViewMode();
|
||||
|
||||
};
|
||||
@ -27,7 +22,6 @@ MaterioSearchApiAjax = function(){
|
||||
*/
|
||||
function initSearchAjax(){
|
||||
// trace('initSearchAjax');
|
||||
// $('#edit-searchfield').focus();
|
||||
|
||||
$('#materio-search-api-search-form').bind('submit', function(event) {
|
||||
// trace('search submited', event);
|
||||
@ -38,34 +32,26 @@ MaterioSearchApiAjax = function(){
|
||||
return false;
|
||||
});
|
||||
|
||||
|
||||
// /!\ AUTOCOMPLETE SELECT EVENT need a patch http://drupal.org/node/365241#comment-5374686
|
||||
$("#edit-searchfield").bind('autocompleteSelect', function(event) {
|
||||
$(this).parents('.form').trigger('submit');
|
||||
});
|
||||
|
||||
_$content
|
||||
.bind('jsp-initialised', function(event, isScrollable){
|
||||
trace('isScrollable = '+isScrollable);
|
||||
// TODO: better to check scroll-y than isscrollable, load next page before the end of scroll
|
||||
if(!isScrollable)
|
||||
infinitScrollPager();
|
||||
// TODO: what happend when there is no more page
|
||||
})
|
||||
.bind('jsp-scroll-y', function(event, scrollPositionY, isAtTop, isAtBottom){
|
||||
if(isAtBottom)
|
||||
infinitScrollPager();
|
||||
});
|
||||
$(document)
|
||||
.bind('init-scroller-pager', onInitScrollerPager)
|
||||
.bind('load-scroller-pager', onLoadScrollerPager)
|
||||
.bind('view-mode-changed', onViewModeChanged)
|
||||
.bind('history-state-change', onHistoryStateChange);
|
||||
|
||||
// trigger updated event for direct html loading
|
||||
setTimeout(function(){
|
||||
var event = jQuery.Event('resultschanged');
|
||||
|
||||
if(isExplore)
|
||||
event.container = $('.search-results', _$content);
|
||||
if(isExplore())
|
||||
event.container = '#content .search-results';
|
||||
|
||||
if(isActuality)
|
||||
event.container = $('.actuality-items', _$content);
|
||||
if(isActuality())
|
||||
event.container = '#content .actuality-items';
|
||||
|
||||
$.event.trigger(event);
|
||||
}, 10);
|
||||
@ -93,6 +79,7 @@ MaterioSearchApiAjax = function(){
|
||||
|
||||
|
||||
if(!_isloadingresults){
|
||||
$.event.trigger('loading-content');
|
||||
_isloadingresults = true;
|
||||
$('#materio-search-api-search-form').addClass('loading');
|
||||
// TODO: record ajax path in a variable from materio_search_api_ajax_init
|
||||
@ -100,57 +87,75 @@ MaterioSearchApiAjax = function(){
|
||||
{'types':types},
|
||||
function(json){
|
||||
trace('json', json);
|
||||
$.event.trigger('resultsloaded');
|
||||
$.event.trigger('loaded-content');
|
||||
_isloadingresults = false;
|
||||
$('#materio-search-api-search-form').removeClass('loading');
|
||||
updateContent(json);
|
||||
|
||||
var path = Drupal.settings.basePath + Drupal.settings.pathPrefix + json.search_path + '/' + json.keys;
|
||||
|
||||
var event = jQuery.Event('new-history-page');
|
||||
event.path = path;
|
||||
event.title = json.keys;
|
||||
event.content = json.return;
|
||||
$.event.trigger(event);
|
||||
|
||||
for (language in Drupal.settings.materio_search_api_ajax.languages) {
|
||||
var l = Drupal.settings.materio_search_api_ajax.languages[language];
|
||||
$('#block-locale-language li.'+language+' a').attr('href', Drupal.settings.basePath + l.prefix+'/' + json.search_path + '/' + json.keys)
|
||||
};
|
||||
|
||||
changeContent(json);
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
function updateContent(json){
|
||||
function loadActuality(){
|
||||
if(!_isloadingresults){
|
||||
$.event.trigger('loading-content');
|
||||
_isloadingresults = true;
|
||||
$('#materio-search-api-search-form').addClass('loading');
|
||||
|
||||
var url = Drupal.settings.basePath+Drupal.settings.pathPrefix+'materio_search_api_ajax/actuality';
|
||||
$.getJSON(url,
|
||||
function(json){
|
||||
trace('json', json);
|
||||
$.event.trigger('resultsloaded');
|
||||
_isloadingresults = false;
|
||||
$('#materio-search-api-search-form').removeClass('loading');
|
||||
changeContent(json);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function changeContent(json){
|
||||
if(json.return){
|
||||
|
||||
$.event.trigger('loaded-content');
|
||||
$('.inner-content',_$content).html(json.return);
|
||||
|
||||
var path = Drupal.settings.basePath + Drupal.settings.pathPrefix + json.search_path + '/' + json.keys;
|
||||
|
||||
_History.pushState({content:json.return}, json.keys, path);
|
||||
$('input[name=location]','#feedback-form').attr('value', path);
|
||||
|
||||
for (language in Drupal.settings.materio_search_api_ajax.languages) {
|
||||
var l = Drupal.settings.materio_search_api_ajax.languages[language];
|
||||
$('#block-locale-language li.'+language+' a').attr('href', Drupal.settings.basePath + l.prefix+'/' + json.search_path + '/' + json.keys)
|
||||
};
|
||||
|
||||
var event = jQuery.Event('resultschanged');
|
||||
event.container = $('.search-results', _$content);
|
||||
$.event.trigger(event);
|
||||
|
||||
triggerContentChanged();
|
||||
}else{
|
||||
trace('no results');
|
||||
}
|
||||
};
|
||||
|
||||
function triggerContentChanged(){
|
||||
var event = jQuery.Event('resultschanged');
|
||||
event.container = '#content .search-results, #content .actuality-items';
|
||||
$.event.trigger(event);
|
||||
};
|
||||
|
||||
/**
|
||||
* infinit scroll
|
||||
*/
|
||||
function infinitScrollPager(){
|
||||
var $nextpage = $('ul.pager .pager-current', _$content).next(),
|
||||
href = $('a', $nextpage).attr('href');
|
||||
|
||||
if(href){
|
||||
if (isExplore)
|
||||
loadNextResultsPage(href);
|
||||
|
||||
if(isActuality)
|
||||
loadNextActualityPage(href);
|
||||
}
|
||||
function onInitScrollerPager(event){
|
||||
if(isActuality() || isExplore())
|
||||
event.pager.hide();
|
||||
};
|
||||
|
||||
function onLoadScrollerPager(event){
|
||||
if (isExplore())
|
||||
loadNextResultsPage(event.href);
|
||||
|
||||
if(isActuality())
|
||||
loadNextActualityPage(event.href);
|
||||
};
|
||||
|
||||
function loadNextResultsPage(href){
|
||||
@ -192,8 +197,9 @@ MaterioSearchApiAjax = function(){
|
||||
$newpager = $('ul.pager', $newcontent);
|
||||
|
||||
$(container_class, _$content).append($newitems);
|
||||
$('ul.pager', _$content).replaceWith($newpager);
|
||||
$('ul.pager', _$content).replaceWith($newpager.hide());
|
||||
|
||||
// TODO: animation, this should be on theme side
|
||||
$(container_class, _$content).children('.just-added').each(function(i){
|
||||
// $(this).delay(5000*i).removeClass('just-added');
|
||||
var $this = $(this);
|
||||
@ -207,28 +213,14 @@ MaterioSearchApiAjax = function(){
|
||||
$.event.trigger(event);
|
||||
};
|
||||
|
||||
/**
|
||||
* history navigation
|
||||
*/
|
||||
function initHistoryNav(){
|
||||
var state = _History.getState();
|
||||
_History.log('initial:', state.data, state.title, state.url);
|
||||
|
||||
_History.Adapter.bind(window,'statechange',function(){
|
||||
var state = _History.getState();
|
||||
_History.log('statechange:', state.data, state.title, state.url);
|
||||
// TODO: History : empty content if we go back to the homepage
|
||||
$('.inner-content',_$content).html(state.data.content);
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* viewmode
|
||||
*/
|
||||
function initViewMode(){
|
||||
$('.viewmode-link').click(function(event){
|
||||
event.preventDefault();
|
||||
changeViewMode($(this).attr('rel'), $(this));
|
||||
return false;
|
||||
});
|
||||
};
|
||||
|
||||
@ -236,7 +228,8 @@ MaterioSearchApiAjax = function(){
|
||||
$.getJSON(Drupal.settings.basePath+'materio_search_api_ajax/viewmode/change/'+vm, function(json){
|
||||
trace('viewmode json', json);
|
||||
if (json.statut == "saved"){
|
||||
loadResults(getSearchKeys());
|
||||
// loadResults(getSearchKeys());
|
||||
$.event.trigger('view-mode-changed');
|
||||
$('.viewmode-link').removeClass('active');
|
||||
$btn.addClass('active');
|
||||
}
|
||||
@ -244,6 +237,34 @@ MaterioSearchApiAjax = function(){
|
||||
});
|
||||
};
|
||||
|
||||
function onViewModeChanged(event){
|
||||
if (isExplore())
|
||||
loadResults(getSearchKeys());
|
||||
|
||||
if(isActuality())
|
||||
loadActuality();
|
||||
};
|
||||
|
||||
/**
|
||||
* history
|
||||
*/
|
||||
function onHistoryStateChange(event){
|
||||
if(isExplore() || isActuality())
|
||||
triggerContentChanged();
|
||||
};
|
||||
|
||||
/**
|
||||
* helpers
|
||||
*/
|
||||
function isExplore(){
|
||||
return $('.search-results', '#content').length;
|
||||
};
|
||||
|
||||
function isActuality(){
|
||||
return $('.actuality-items', '#content').length;
|
||||
};
|
||||
|
||||
|
||||
|
||||
init();
|
||||
|
||||
|
@ -44,7 +44,7 @@ function materio_flag_menu() {
|
||||
'page arguments' => array(3),
|
||||
);
|
||||
|
||||
$items['materioflag/refresh/block/mylists'] = $base+array(
|
||||
$items['materioflag/refresh/block/lists'] = $base+array(
|
||||
'access arguments' => array('create flag lists'),
|
||||
'page callback' => 'materio_flag_refresh_block',
|
||||
'page arguments' => array(3),
|
||||
@ -57,11 +57,26 @@ function materio_flag_menu() {
|
||||
'page arguments' => array(3),
|
||||
);
|
||||
|
||||
$items['materioflag/createlist/%'] = $base+array(
|
||||
|
||||
$items['materioflag/nodelinks'] = $base+array(
|
||||
'access arguments' => array('create flag lists'),
|
||||
'access callback' => 'user_access',
|
||||
'page callback' => 'materio_flag_createlist',
|
||||
'page arguments' => array(2, 3),
|
||||
'page callback' => 'materio_flag_nodelinks',
|
||||
// 'page arguments' => array(3),
|
||||
);
|
||||
|
||||
$items['lists/%'] = $base+array(
|
||||
'access arguments' => array('create flag lists'),
|
||||
'access callback' => 'user_access',
|
||||
'page callback' => 'materio_flag_user_lists',
|
||||
'page arguments' => array(1),
|
||||
);
|
||||
|
||||
$items['materioflag/ajax/list/%'] = $base+array(
|
||||
'page callback' => 'materio_flag_ajax_list',
|
||||
'access arguments' => array('create flag lists'),
|
||||
'access callback' => 'user_access',
|
||||
'page arguments' => array(3, 4),
|
||||
);
|
||||
|
||||
return $items;
|
||||
@ -83,6 +98,10 @@ function materio_flag_block_info() {
|
||||
'cache' => DRUPAL_NO_CACHE
|
||||
);
|
||||
|
||||
$blocks['materio_flag_mylists_nav'] = array(
|
||||
'info' => t('My Materio flag lists navigation'),
|
||||
'cache' => DRUPAL_NO_CACHE
|
||||
);
|
||||
|
||||
return $blocks;
|
||||
}
|
||||
@ -122,6 +141,7 @@ function materio_flag_block_view($delta = '') {
|
||||
// dsm($flags, 'flags');
|
||||
|
||||
foreach ($flags as $name => $flag) {
|
||||
$flag->path = url('lists/'.$flag->fid);
|
||||
$flaged_content = flag_lists_get_flagged_content($flag->fid, $user->uid);
|
||||
// dsm($flaged_content, 'flaged_content');
|
||||
$fcn = array();
|
||||
@ -134,6 +154,7 @@ function materio_flag_block_view($delta = '') {
|
||||
$fcn[] = $node;
|
||||
}
|
||||
}
|
||||
|
||||
$lists[$name] = array(
|
||||
'list' => $flag,
|
||||
'content' => $fcn,
|
||||
@ -152,6 +173,19 @@ function materio_flag_block_view($delta = '') {
|
||||
drupal_add_js(drupal_get_path('module', 'materio_flag').'/js/materio_flag-ck.js');
|
||||
}
|
||||
break;
|
||||
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...
|
||||
// }
|
||||
|
||||
|
||||
$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));
|
||||
// $block['content'] = theme('flag_lists_user_page', array('uid' => $user->uid));
|
||||
}
|
||||
break;
|
||||
}
|
||||
return $block;
|
||||
}
|
||||
@ -174,120 +208,136 @@ function materio_flag_entity_info_alter(&$entity_info) {
|
||||
function materio_flag_entity_view($entity, $type, $view_mode, $langcode) {
|
||||
if($type == 'node'){
|
||||
|
||||
// dsm($entity, 'entity');
|
||||
// Do we have a list template for this node type, or are we s
|
||||
if (!flag_lists_template_exists($entity->type)) {
|
||||
return;
|
||||
}
|
||||
$flaglists_links = materio_flag_get_entity_links($entity, $type, $view_mode);
|
||||
// dsm($flaglists_links, 'flaglists_links');
|
||||
|
||||
global $user;
|
||||
$entity->content['links']['flaglistslinks'] = array('#markup' => $flaglists_links,"#html"=>true);
|
||||
|
||||
if ($flags = flag_lists_get_user_flags($entity->type, $user)) {
|
||||
// dsm($flags, 'flags');
|
||||
# if flag name is provided we are on flaglists content list (block mylists)
|
||||
if(isset($entity->flag_names)){
|
||||
// TODO: limit flag link by current flag list
|
||||
foreach ($flags as $flag) {
|
||||
//dsm($flag->name, 'flag');
|
||||
if(in_array($flag->name, $entity->flag_names)){
|
||||
if ($flag->module == 'flag_lists') {
|
||||
$action = _flag_lists_is_flagged($flag, $entity->nid, $user->uid, 0) ? 'unflag' : 'flag';
|
||||
} else {
|
||||
$action = $flag->is_flagged($entity->nid) ? 'unflag' : 'flag';
|
||||
}
|
||||
$flag->module = 'materio_flag';
|
||||
$link = $flag->theme($action, $entity->nid);
|
||||
|
||||
// If it's a list, fix the link.
|
||||
if ($flag->module == 'flag_lists') {
|
||||
flag_lists_fix_link($link, $action);
|
||||
}
|
||||
|
||||
$items[] = array(
|
||||
'data' => $link,
|
||||
'class' => array('flag-lists-link', $action.'-action'),
|
||||
);
|
||||
|
||||
// array_splice($entity->flag_names, array_search($flag->name, $entity->flag_names), 1);
|
||||
|
||||
// dsm($entity->flag_names, 'entity->flag_name');
|
||||
|
||||
// break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#normal display
|
||||
}else{
|
||||
// Build the list of lists for this node.
|
||||
foreach ($flags as $flag) {
|
||||
if ($flag->module == 'flag_lists') {
|
||||
$action = _flag_lists_is_flagged($flag, $entity->nid, $user->uid, 0) ? 'unflag' : 'flag';
|
||||
}
|
||||
else {
|
||||
$action = $flag->is_flagged($entity->nid) ? 'unflag' : 'flag';;
|
||||
}
|
||||
|
||||
// dsm($flag, 'flag');
|
||||
|
||||
// $flag->module = 'materio_flag';
|
||||
|
||||
$link = $flag->theme($action, $entity->nid);
|
||||
|
||||
// If it's a list, fix the link.
|
||||
if ($flag->module == 'flag_lists') {
|
||||
flag_lists_fix_link($link, $action);
|
||||
}
|
||||
|
||||
$items[] = array(
|
||||
'data' => $link,
|
||||
'class' => array('flag-lists-link', $action.'-action'),
|
||||
);
|
||||
}
|
||||
|
||||
#create new list
|
||||
$link = l(
|
||||
t('New @name', array('@name' => variable_get('flag_lists_name', t('list')))),
|
||||
'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'))))
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$create = array(
|
||||
'data' => $link,// . '<i class="icon-plus"></i>',
|
||||
'class' => array('flag-lists-create'),
|
||||
);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
if( (!isset($items) || !count($items)) && !isset($create))
|
||||
return;
|
||||
|
||||
$ops = array(
|
||||
'node' => $entity,
|
||||
'items' => $items,
|
||||
);
|
||||
|
||||
if(isset($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);
|
||||
|
||||
$entity->content['links']['flaglistslinks'] = array('#markup' => $flaglists_links,"#html"=>true);
|
||||
|
||||
}
|
||||
drupal_add_css(drupal_get_path('module', 'flag') . '/theme/flag.css');
|
||||
drupal_add_js(drupal_get_path('module', 'flag') . '/theme/flag.js');
|
||||
}
|
||||
}
|
||||
|
||||
function materio_flag_get_entity_links($entity, $type, $view_mode = null){
|
||||
// dsm($entity, 'entity');
|
||||
|
||||
// Do we have a list template for this node type, or are we s
|
||||
if (!flag_lists_template_exists($entity->type)) {
|
||||
return;
|
||||
}
|
||||
|
||||
global $user;
|
||||
|
||||
# if flag name is provided we are on flaglists content list (block mylists)
|
||||
if($view_mode == 'bookmark'){
|
||||
// TODO: define view mode in settings
|
||||
// if (isset($entity->flag_names) && $flags = flag_lists_get_user_flags($entity->type, $user)) {
|
||||
// // dsm($flags, 'flags');
|
||||
// // TODO: limit flag link by current flag list
|
||||
// foreach ($flags as $flag) {
|
||||
// //dsm($flag->name, 'flag');
|
||||
// if(in_array($flag->name, $entity->flag_names)){
|
||||
// if ($flag->module == 'flag_lists') {
|
||||
// $action = _flag_lists_is_flagged($flag, $entity->nid, $user->uid, 0) ? 'unflag' : 'flag';
|
||||
// } else {
|
||||
// $action = $flag->is_flagged($entity->nid) ? 'unflag' : 'flag';
|
||||
// }
|
||||
// $flag->module = 'materio_flag';
|
||||
// $link = $flag->theme($action, $entity->nid);
|
||||
|
||||
// // If it's a list, fix the link.
|
||||
// if ($flag->module == 'flag_lists') {
|
||||
// flag_lists_fix_link($link, $action);
|
||||
// }
|
||||
|
||||
// $items[] = array(
|
||||
// 'data' => $link,
|
||||
// 'class' => array('flag-lists-link', $action.'-action'),
|
||||
// );
|
||||
|
||||
// // array_splice($entity->flag_names, array_search($flag->name, $entity->flag_names), 1);
|
||||
// // dsm($entity->flag_names, 'entity->flag_name');
|
||||
// // break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
#normal display
|
||||
}else{
|
||||
if ($flags = flag_lists_get_user_flags($entity->type, $user)) {
|
||||
// dsm($flags, 'flags');
|
||||
// Build the list of lists for this node.
|
||||
foreach ($flags as $flag) {
|
||||
// dsm($flag, 'flag');
|
||||
if ($flag->module == 'flag_lists') {
|
||||
$action = _flag_lists_is_flagged($flag, $entity->nid, $user->uid, 0) ? 'unflag' : 'flag';
|
||||
}
|
||||
else {
|
||||
$action = $flag->is_flagged($entity->nid) ? 'unflag' : 'flag';;
|
||||
}
|
||||
|
||||
$link = $flag->theme($action, $entity->nid);
|
||||
|
||||
// If it's a list, fix the link.
|
||||
if ($flag->module == 'flag_lists') {
|
||||
flag_lists_fix_link($link, $action);
|
||||
}
|
||||
|
||||
$items[] = array(
|
||||
'data' => $link,
|
||||
'class' => array('flag-lists-link', $action.'-action'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#create new list
|
||||
$link = l(
|
||||
'<span>' . t('New @name', array('@name' => variable_get('flag_lists_name', t('list')))) . '</span> <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')))),
|
||||
'nid' => $entity->nid,
|
||||
'token' => flag_get_token($entity->nid),
|
||||
),
|
||||
'html' => TRUE,
|
||||
)
|
||||
);
|
||||
|
||||
$create = array(
|
||||
'data' => $link,
|
||||
'class' => array('flag-lists-create'),
|
||||
);
|
||||
}
|
||||
|
||||
// if( (!isset($items) || !count($items)) && !isset($create))
|
||||
// return;
|
||||
|
||||
if(isset($items)){
|
||||
$ops = array(
|
||||
'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');
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_theme().
|
||||
*/
|
||||
@ -303,18 +353,40 @@ function materio_flag_theme($existing, $type, $theme, $path) {
|
||||
'template' => 'materio-flag-mylists-block',
|
||||
'path' => drupal_get_path('module', 'materio_flag').'/templates',
|
||||
),
|
||||
'materio_flag_mylists_nav_block' => array(
|
||||
'arguments' => array(),
|
||||
'template' => 'materio-flag-mylists-nav-block',
|
||||
'path' => drupal_get_path('module', 'materio_flag').'/templates',
|
||||
),
|
||||
'materio_flag_mylists_entity_links' => array(
|
||||
'variables' => array('node' => NULL, 'create' => NULL, 'items' => array()),
|
||||
),
|
||||
'materio_flag_mylists_list' => array(
|
||||
'template' => 'materio-flag-mylists-list',
|
||||
'path' => drupal_get_path('module', 'materio_flag').'/templates',
|
||||
'variables' => array(
|
||||
'count' => 0,
|
||||
'items' => array(),
|
||||
'view_mode' => 'teaser',
|
||||
'pager' => NULL,
|
||||
'fid' => null,
|
||||
'name' => null,
|
||||
'title' => null,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function template_preprocess_materio_flag_mybookmarks_block($vars){
|
||||
function template_preprocess_materio_flag_mybookmarks_block(&$vars){
|
||||
// dsm($vars, 'vars');
|
||||
}
|
||||
|
||||
|
||||
function template_preprocess_materio_flag_mylists_block($vars){
|
||||
function template_preprocess_materio_flag_mylists_block(&$vars){
|
||||
// dsm($vars, 'vars');
|
||||
}
|
||||
|
||||
function template_preprocess_materio_flag_mylists_nav_block(&$vars){
|
||||
// dsm($vars, 'vars');
|
||||
}
|
||||
|
||||
@ -336,3 +408,19 @@ function theme_materio_flag_mylists_entity_links($vars){
|
||||
return theme('item_list', array('items' => $items, 'type' => 'ul', 'attributes' => array('class' => 'flag-lists-entity-links')));
|
||||
|
||||
}
|
||||
|
||||
function template_preprocess_materio_flag_mylists_list(&$vars) {
|
||||
|
||||
$vars['list_count'] = format_plural(
|
||||
$vars['count'],
|
||||
'@name @title contains 1 item.', // in @sec seconds
|
||||
'@name @title contains @count items.', // in @sec seconds
|
||||
array(
|
||||
'@name' => $vars['name'],
|
||||
'@title' => $vars['title'],
|
||||
)
|
||||
);
|
||||
|
||||
// dsm($vars, '$vars');
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ function materio_flag_refresh_block($flag){
|
||||
case 'bookmarks':
|
||||
$block_name = 'materio_flag_mybookmarks';
|
||||
break;
|
||||
case 'mylists':
|
||||
case 'lists':
|
||||
$block_name = 'materio_flag_mylists';
|
||||
break;
|
||||
}
|
||||
@ -62,17 +62,167 @@ function materio_flag_createlist_form($type){
|
||||
// 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);
|
||||
// }
|
||||
$form_state['build_info']['args'] = array(NULL, 'breve');
|
||||
// $f = drupal_get_form('flag_lists_form', $form_state);
|
||||
// dsm($f);
|
||||
|
||||
$form = array(
|
||||
'#type' => 'form',
|
||||
'#id' => 'materio-flag-create-list-form',
|
||||
);
|
||||
|
||||
$form['type'] = array(
|
||||
'#type' => 'hidden',
|
||||
'#value' => $type,
|
||||
'#name' => 'type',
|
||||
);
|
||||
|
||||
$form['listname'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Create new @name', array('@name'=>variable_get('flag_lists_name', 'list'))),
|
||||
'#default_value' => '',
|
||||
// '#size' => 100,
|
||||
'#maxlength' => 255,
|
||||
'#name' => 'flag-lists-name',
|
||||
'#description' => t('A short, descriptive title for this Folder list. Limit to 255 characters.'),
|
||||
);
|
||||
|
||||
$form['actions'] = array(
|
||||
'#prefix' => '<div class="actions">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
|
||||
|
||||
$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');
|
||||
|
||||
$return = drupal_render($form);
|
||||
|
||||
$rep = array(
|
||||
'return'=>$return,
|
||||
);
|
||||
|
||||
if ($debug) {
|
||||
dsm($rep, 'rep');
|
||||
return "debug display";
|
||||
}else{
|
||||
drupal_json_output($rep);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function materio_flag_nodelinks(){
|
||||
$nids = explode(';', $_REQUEST['nids']);
|
||||
|
||||
if(count($nids)){
|
||||
foreach ($nids as $nid) {
|
||||
$node = node_load($nid);
|
||||
$lks = materio_flag_get_entity_links($node, 'node');
|
||||
$links[$nid] = $lks;
|
||||
}
|
||||
|
||||
$rep = array(
|
||||
'return'=>$return,
|
||||
"status" => 1,
|
||||
"nids" => $nids,
|
||||
'links' => $links,
|
||||
);
|
||||
}else{
|
||||
$rep['status'] = 0;
|
||||
}
|
||||
|
||||
drupal_json_output($rep);
|
||||
}
|
||||
|
||||
function materio_flag_user_lists($fid){
|
||||
global $user;
|
||||
$flag = flag_lists_get_flag($fid);
|
||||
// dsm($flag, 'flag');
|
||||
|
||||
$flaged_content = flag_lists_get_flagged_content($fid, $user->uid);
|
||||
// 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;
|
||||
|
||||
for ($i=$offset; $i < $max; $i++) {
|
||||
if($flaged_content[$i]->entity_type == 'node'){
|
||||
$items[] = node_load($flaged_content[$i]->entity_id);
|
||||
}
|
||||
}
|
||||
|
||||
$ret['#items'] = $items;
|
||||
$ret['#theme'] = 'materio_flag_mylists_list';
|
||||
$ret['#view_mode'] = $viewmode;
|
||||
$ret['#fid'] = $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');
|
||||
|
||||
return $ret;
|
||||
|
||||
}
|
||||
|
||||
function materio_flag_ajax_list($fid, $page = 0){
|
||||
$debug = false;
|
||||
|
||||
$_GET['page'] = $page;
|
||||
|
||||
$path = 'lists/'.$fid;
|
||||
|
||||
// check if request is ajax, if not rediret to search_api_page page with right keys
|
||||
if (!$debug && (!isset($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest')) {
|
||||
drupal_goto($path, array('query'=>array('page'=>$page)), 301);
|
||||
exit;
|
||||
}
|
||||
|
||||
// get results
|
||||
menu_set_active_item($path);
|
||||
$return = menu_execute_active_handler($path, FALSE);
|
||||
|
||||
// dsm($return, '$return');
|
||||
|
||||
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)) {
|
||||
|
||||
if (is_array($return)) {
|
||||
$return = drupal_render($return);
|
||||
}
|
||||
|
||||
$rep = array(
|
||||
'return' => $return,
|
||||
'path' => $path,
|
||||
'title' => 'folder',
|
||||
);
|
||||
|
||||
if ($debug) {
|
||||
@ -81,19 +231,5 @@ function materio_flag_createlist_form($type){
|
||||
}else{
|
||||
drupal_json_output($rep);
|
||||
}
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* materio_flag_createlist($type, $nid)
|
||||
*
|
||||
*/
|
||||
function materio_flag_createlist($title, $nid = null){
|
||||
drupal_get_form('flag_lists_form', $title);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -227,6 +227,21 @@ function materio_search_api_search_form($form, &$form_state){
|
||||
global $user;
|
||||
$form = array();
|
||||
|
||||
|
||||
$args = arg();
|
||||
$path = array_shift($args);
|
||||
$keys = implode('/', $args);
|
||||
|
||||
$form['searchfield'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => $path == 'explore' ? $keys : "", // TODO: set the search page path global or a variable in settings
|
||||
// '#value' => $keys,
|
||||
'#autocomplete_path' => 'materiosearchapi/autocomplete/searchapi',
|
||||
//'#autocomplete_path' => 'materiosearchapi/autocomplete/dbselect',
|
||||
'#size' => 30,
|
||||
'#maxlength' => 1024,
|
||||
);
|
||||
|
||||
if(user_access('use materio search api filters')){
|
||||
|
||||
$index = search_api_index_load(variable_get('mainsearchindex', -1));
|
||||
@ -247,20 +262,6 @@ function materio_search_api_search_form($form, &$form_state){
|
||||
);
|
||||
}
|
||||
|
||||
$args = arg();
|
||||
$path = array_shift($args);
|
||||
$keys = implode('/', $args);
|
||||
|
||||
$form['searchfield'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => $path == 'explore' ? $keys : "", // TODO: set the search page path global or a variable in settings
|
||||
// '#value' => $keys,
|
||||
'#autocomplete_path' => 'materiosearchapi/autocomplete/searchapi',
|
||||
//'#autocomplete_path' => 'materiosearchapi/autocomplete/dbselect',
|
||||
'#size' => 30,
|
||||
'#maxlength' => 1024,
|
||||
);
|
||||
|
||||
$form['create'] = array(
|
||||
'#type' => 'image_button',
|
||||
'#src' => drupal_get_path('module', 'materio_search_api') . '/images/search.png',
|
||||
@ -307,22 +308,27 @@ function materio_search_api_search_form_submit($form, &$form_state){
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_form_alter().
|
||||
*
|
||||
* Adds language fields to user forms.
|
||||
* viewmode
|
||||
*/
|
||||
// TODO: user can choose preferred view mode
|
||||
// function materio_search_api_form_alter(&$form, &$form_state, $form_id) {
|
||||
// if (user_access('use materio search api viewmode selection')) {
|
||||
// if ($form_id == 'user_register_form' || ($form_id == 'user_profile_form' && $form['#user_category'] == 'account')) {
|
||||
// materio_search_api_viewmode_selector_form($form, $form_state, $form['#user']);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// function materio_search_api_viewmode_selector_form(&$form, &$form_state, $user) {
|
||||
function _materio_search_api_change_viewmode($vm){
|
||||
// dsm($vm, '_materio_search_api_change_viewmode');
|
||||
|
||||
// }
|
||||
global $user;
|
||||
// dsm($user, 'user');
|
||||
|
||||
$entity_infos = entity_get_info();
|
||||
// dsm($entity_infos, 'entity_infos');
|
||||
|
||||
if (in_array($vm, variable_get('availableviewmodes', array()))) {
|
||||
user_save($user, array("data"=>array('materiosearchapi_viewmode' => $vm)));
|
||||
$rep = array('statut'=>'saved');
|
||||
}else{
|
||||
$rep = array('statut'=>'viewmode not allowed');
|
||||
}
|
||||
|
||||
return $rep;
|
||||
}
|
||||
|
||||
/**
|
||||
* - - - - - - - - - - - - THEME - - - - - - - - - - - -
|
||||
@ -409,10 +415,29 @@ 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)){
|
||||
$content .= '<div class="viewmode-link viewmode-'.$viewmode.($active == $viewmode ? " active" : '').'" rel="'.$viewmode.'"><span class="inner">'.$value['label'].'</span></div>';
|
||||
$link = l(
|
||||
'<span class="inner">'.$value['label'].'</span>',
|
||||
'materiosearchapi/viewmode/change/'.$viewmode,
|
||||
array(
|
||||
'query' => drupal_get_destination(),
|
||||
'html' => true,
|
||||
'attributes' => array(
|
||||
'class' => array(
|
||||
'viewmode-link',
|
||||
'viewmode-'.$viewmode,
|
||||
$active == $viewmode ? " active" : ''
|
||||
),
|
||||
'rel' => $viewmode
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$content .= $link;
|
||||
}
|
||||
}
|
||||
$content .= '</div>';
|
||||
@ -471,11 +496,11 @@ function template_preprocess_materio_search_api_results(array &$variables) {
|
||||
$variables['result_count'] = $results['result count'];
|
||||
$variables['sec'] = round($results['performance']['complete'], 3);
|
||||
$variables['search_performance'] = format_plural(
|
||||
$results['result count'],
|
||||
'The search found 1 result.', // in @sec seconds
|
||||
'The search found @count results.', // in @sec seconds
|
||||
array('@sec' => $variables['sec'])
|
||||
);
|
||||
$results['result count'],
|
||||
'The search found 1 result.', // in @sec seconds
|
||||
'The search found @count results.', // in @sec seconds
|
||||
array('@sec' => $variables['sec'])
|
||||
);
|
||||
|
||||
// $variables['search_results'] = array(
|
||||
// '#theme' => 'search_results_list',
|
||||
@ -497,7 +522,7 @@ function template_preprocess_materio_search_api_actuality(&$vars){
|
||||
// $items[] = node_load($nid);
|
||||
// }
|
||||
// $vars['items'] = $items;
|
||||
|
||||
$vars['actualities_infos'] = t('Actualities by materiO\'');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -119,7 +119,7 @@ function materio_search_api_autocomplete_searchapi($typed = ''){
|
||||
*
|
||||
*
|
||||
*/
|
||||
function materio_search_api_results_search(){//, $limit = 20, $page = 0
|
||||
function materio_search_api_results_search(){
|
||||
global $user;
|
||||
|
||||
//dsm("materio_search_api_results_search");
|
||||
@ -166,8 +166,6 @@ function materio_search_api_results_search(){//, $limit = 20, $page = 0
|
||||
|
||||
$query = search_api_query($index_machine_name, array('parse mode'=>'direct'))
|
||||
->keys(implode(' ', $keys))
|
||||
// TODO: add bundle filter
|
||||
// ->condition('type', 'breve')
|
||||
->range($offset, $limit);
|
||||
|
||||
$filter = $query->createFilter('OR');
|
||||
@ -256,11 +254,14 @@ function materio_search_api_results_search(){//, $limit = 20, $page = 0
|
||||
*
|
||||
*/
|
||||
function materio_search_api_actuality(){
|
||||
global $user;
|
||||
|
||||
$date = strtotime('-6 month');
|
||||
|
||||
$viewmode = isset($user->data['materiosearchapi_viewmode']) ? $user->data['materiosearchapi_viewmode'] : variable_get('defaultviewmode', 'full');
|
||||
$limit = 10;//variable_get($viewmode.'_limite', '10');
|
||||
$offset = pager_find_page() * $limit;
|
||||
// dsm($offset);
|
||||
|
||||
$query = new EntityFieldQuery;
|
||||
$query
|
||||
@ -308,9 +309,20 @@ function materio_search_api_actuality(){
|
||||
|
||||
return theme('materio_search_api_actuality', array(
|
||||
'items' => $items,
|
||||
'view_mode' => 'cardmedium',
|
||||
'view_mode' => $viewmode,
|
||||
'count' => $count,
|
||||
'pager' => theme('pager'),
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
function materio_search_api_viewmode_change($vm){
|
||||
dsm($vm, 'materio_search_api_viewmode_change');
|
||||
$rep = _materio_search_api_change_viewmode($vm);
|
||||
|
||||
//return 'debug mode for materio_search_api_viewmode_change';
|
||||
// drupal_json_output($rep);
|
||||
|
||||
drupal_goto();
|
||||
|
||||
}
|
||||
|
@ -90,20 +90,21 @@ function materio_search_api_ajax_search($keys, $page = 0){
|
||||
function materio_search_api_ajax_viewmode_change($vm){
|
||||
// dsm($vm);
|
||||
|
||||
global $user;
|
||||
// dsm($user, 'user');
|
||||
// global $user;
|
||||
// // dsm($user, 'user');
|
||||
|
||||
$entity_infos = entity_get_info();
|
||||
// dsm($entity_infos, 'entity_infos');
|
||||
// $entity_infos = entity_get_info();
|
||||
// // dsm($entity_infos, 'entity_infos');
|
||||
|
||||
if (in_array($vm, variable_get('availableviewmodes', array()))) {
|
||||
user_save($user, array("data"=>array('materiosearchapi_viewmode' => $vm)));
|
||||
$rep = array('statut'=>'saved');
|
||||
}else{
|
||||
$rep = array('statut'=>'viewmode not allowed');
|
||||
}
|
||||
// if (in_array($vm, variable_get('availableviewmodes', array()))) {
|
||||
// user_save($user, array("data"=>array('materiosearchapi_viewmode' => $vm)));
|
||||
// $rep = array('statut'=>'saved');
|
||||
// }else{
|
||||
// $rep = array('statut'=>'viewmode not allowed');
|
||||
// }
|
||||
$_GET['page'] = 0;
|
||||
$rep = _materio_search_api_change_viewmode($vm);
|
||||
|
||||
//return 'debug mode for materio_search_api_viewmode_change';
|
||||
drupal_json_output($rep);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,10 @@
|
||||
<section class="mylists">
|
||||
<?php foreach ($lists as $name => $list): ?>
|
||||
<h2 class="listname"><?php print $list['list']->title; ?></h2>
|
||||
<div class="flaged"> <?php print render(entity_view('node', $list['content'], $viewmode)); ?> </div>
|
||||
<?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>
|
||||
<?php endforeach; ?>
|
||||
</section>
|
9
templates/materio-flag-mylists-list.tpl.php
Normal file
9
templates/materio-flag-mylists-list.tpl.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php //dsm($variables, '$variables'); ?>
|
||||
<div class="materio-flags-list <?php print ' view-mode-' . $variables['view_mode'];?>" fid="<?php print $variables['fid']; ?>">
|
||||
<div class="flaglist-items">
|
||||
<p class="flaglist-infos"><?php print $list_count; ?></p>
|
||||
<?php print render(entity_view('node', $items, $variables['view_mode'])); ?>
|
||||
</div>
|
||||
<?php print $pager; ?>
|
||||
</div>
|
||||
|
7
templates/materio-flag-mylists-nav-block.tpl.php
Normal file
7
templates/materio-flag-mylists-nav-block.tpl.php
Normal file
@ -0,0 +1,7 @@
|
||||
<section class="mylists">
|
||||
<ul>
|
||||
<?php foreach ($flags as $name => $flag): ?>
|
||||
<li class="flaglist <?php print $flag->name; ?>"><?php print $flag->title; ?></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</section>
|
@ -3,6 +3,7 @@
|
||||
?>
|
||||
<section class="materiobase-actuality">
|
||||
<?php if($count): ?>
|
||||
<p class="actualities-infos"><?php print $actualities_infos; ?></p>
|
||||
<div class="actuality-items">
|
||||
<?php print render(entity_view('node', $items, $view_mode)); ?>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user