Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>tags/v14.0.0beta1
@@ -239,7 +239,7 @@ | |||
var params; | |||
if (e && e.itemId) { | |||
params = { | |||
view: e.view !== '' ? e.view : e.itemId, | |||
view: typeof e.view === 'string' && e.view !== '' ? e.view : e.itemId, | |||
dir: e.dir ? e.dir : '/' | |||
}; | |||
this._changeUrl(params.view, params.dir); |
@@ -81,8 +81,6 @@ | |||
_setupEvents: function () { | |||
this.$el.on('click', 'li a', _.bind(this._onClickItem, this)) | |||
this.$el.on('click', 'li button', _.bind(this._onClickMenuButton, this)); | |||
this._setOnDrag(); | |||
}, | |||
/** | |||
@@ -135,7 +133,7 @@ | |||
} | |||
this._activeItem = itemId; | |||
currentItem.children('a').addClass('active'); | |||
this.$currentContent = $('#app-content-' + (itemView !== '' ? itemView : itemId)); | |||
this.$currentContent = $('#app-content-' + (typeof itemView === 'string' && itemView !== '' ? itemView : itemId)); | |||
this.$currentContent.removeClass('hidden'); | |||
if (!options || !options.silent) { | |||
this.$currentContent.trigger(jQuery.Event('show')); | |||
@@ -169,74 +167,6 @@ | |||
ev.preventDefault(); | |||
}, | |||
/** | |||
* Event handler for when dragging an item | |||
*/ | |||
_setOnDrag: function () { | |||
var scope = this; | |||
var element = $("#sublist-favorites"); | |||
$(function () { | |||
if (document.getElementById(scope.$quickAccessListKey.toString()).hasAttribute("draggable")) { | |||
element.sortable({ | |||
axis: "y", | |||
containment: "parent", | |||
scroll: false, | |||
zIndex: 0, | |||
opacity: 0.5, | |||
tolerance: "pointer", | |||
//revert: 0.05, | |||
//delay: 150, | |||
start: function (event, ui) { | |||
//Fix for offset | |||
ui.helper[0].style.left = '0px'; | |||
//Change Icon while dragging | |||
var list = document.getElementById(scope.$quickAccessListKey).getElementsByTagName('li'); | |||
for (var j = 0; j < list.length; j++) { | |||
if (!(typeof list[j].getElementsByTagName('a')[0] === 'undefined')) { | |||
list[j].getElementsByTagName('a')[0].classList.remove("nav-icon-files"); | |||
list[j].getElementsByTagName('a')[0].classList.add('icon-menu'); | |||
} | |||
} | |||
}, | |||
stop: function (event, ui) { | |||
//Clean up offset | |||
ui.item.removeAttr("style"); | |||
//Change Icon back after dragging | |||
var list = document.getElementById(scope.$quickAccessListKey.toString()).getElementsByTagName('li'); | |||
for (var j = 0; j < list.length; j++) { | |||
if (!(typeof list[j].getElementsByTagName('a')[0] === 'undefined')) { | |||
list[j].getElementsByTagName('a')[0].classList.add("nav-icon-files"); | |||
list[j].getElementsByTagName('a')[0].classList.remove('icon-menu'); | |||
} | |||
} | |||
}, | |||
update: function (event, ui) { | |||
var list = document.getElementById(scope.$quickAccessListKey.toString()).getElementsByTagName('li'); | |||
var string = []; | |||
for (var j = 0; j < list.length; j++) { | |||
var Object = { | |||
id: j, | |||
name: scope.getCompareValue(list, j, 'alphabet') | |||
}; | |||
string.push(Object); | |||
} | |||
var resultorder = JSON.stringify(string); | |||
$.get(OC.generateUrl("/apps/files/api/v1/quickaccess/set/CustomSortingOrder"), { | |||
order: resultorder | |||
}, function (data, status) { | |||
}); | |||
} | |||
}); | |||
} else { | |||
if (scope.$sortingStrategy === 'customorder') { | |||
scope.$sortingStrategy = 'datemodified'; | |||
} | |||
} | |||
}); | |||
}, | |||
/** | |||
* Event handler for clicking a button | |||
*/ |
@@ -72,6 +72,9 @@ | |||
var quickAccessList = 'sublist-favorites'; | |||
var collapsibleButtonId = 'button-collapse-favorites'; | |||
var listULElements = document.getElementById(quickAccessList); | |||
if (!listULElements) { | |||
return; | |||
} | |||
var listLIElements = listULElements.getElementsByTagName('li'); | |||
var apppath=appfolder; | |||
@@ -101,6 +104,9 @@ | |||
var quickAccessList = 'sublist-favorites'; | |||
var collapsibleButtonId = 'button-collapse-favorites'; | |||
var listULElements = document.getElementById(quickAccessList); | |||
if (!listULElements) { | |||
return; | |||
} | |||
var listLIElements = listULElements.getElementsByTagName('li'); | |||
var appName = appfolder.substring(appfolder.lastIndexOf("/") + 1, appfolder.length); |
@@ -206,10 +206,6 @@ class ViewController extends Controller { | |||
// show_Quick_Access stored as string | |||
$defaultExpandedState = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_Quick_Access', '0') === '1'; | |||
// see Javascript navigation.js for possible sorting strategies | |||
$quickAccessDraggable = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_sorting_strategy', 'alphabet') === 'customorder'; | |||
\OCA\Files\App::getNavigationManager()->add( | |||
[ | |||
'id' => 'favorites', | |||
@@ -219,7 +215,6 @@ class ViewController extends Controller { | |||
'order' => 5, | |||
'name' => $this->l10n->t('Favorites'), | |||
'sublist' => $favoritesSublistArray, | |||
'draggableSublist' => $quickAccessDraggable, | |||
'defaultExpandedState' => $defaultExpandedState, | |||
'enableMenuButton' => 0, | |||
] |
@@ -81,7 +81,7 @@ function NavigationListElements($item, $l, $pinned) { | |||
?> | |||
<button id="button-collapse-<?php p($item['id']); ?>" | |||
class="collapse app-navigation-noclose" <?php if (sizeof($item['sublist']) == 0) { ?> style="display: none" <?php } ?>></button> | |||
<ul id="sublist-<?php p($item['id']); ?>" <?php if ($item['draggableSublist'] === 'true') { ?> draggable="true" style="resize: none;"<?php } ?>> | |||
<ul id="sublist-<?php p($item['id']); ?>"> | |||
<?php | |||
foreach ($item['sublist'] as $item) { | |||
$pinned = NavigationListElements($item, $l, $pinned); |
@@ -239,38 +239,38 @@ describe('OCA.Files.App tests', function() { | |||
expect(App.navigation.getActiveItem()).toEqual('other'); | |||
expect($('#app-content-files').hasClass('hidden')).toEqual(true); | |||
expect($('#app-content-other').hasClass('hidden')).toEqual(false); | |||
expect($('li[data-id=files]').hasClass('active')).toEqual(false); | |||
expect($('li[data-id=other]').hasClass('active')).toEqual(true); | |||
expect($('li[data-id=files] > a').hasClass('active')).toEqual(false); | |||
expect($('li[data-id=other] > a').hasClass('active')).toEqual(true); | |||
App._onPopState({view: 'files', dir: '/somedir'}); | |||
expect(App.navigation.getActiveItem()).toEqual('files'); | |||
expect($('#app-content-files').hasClass('hidden')).toEqual(false); | |||
expect($('#app-content-other').hasClass('hidden')).toEqual(true); | |||
expect($('li[data-id=files]').hasClass('active')).toEqual(true); | |||
expect($('li[data-id=other]').hasClass('active')).toEqual(false); | |||
expect($('li[data-id=files] > a').hasClass('active')).toEqual(true); | |||
expect($('li[data-id=other] > a').hasClass('active')).toEqual(false); | |||
}); | |||
it('clicking on navigation switches the panel visibility', function() { | |||
$('li[data-id=other]>a').click(); | |||
$('li[data-id=other] > a').click(); | |||
expect(App.navigation.getActiveItem()).toEqual('other'); | |||
expect($('#app-content-files').hasClass('hidden')).toEqual(true); | |||
expect($('#app-content-other').hasClass('hidden')).toEqual(false); | |||
expect($('li[data-id=files]').hasClass('active')).toEqual(false); | |||
expect($('li[data-id=other]').hasClass('active')).toEqual(true); | |||
expect($('li[data-id=files] > a').hasClass('active')).toEqual(false); | |||
expect($('li[data-id=other] > a').hasClass('active')).toEqual(true); | |||
$('li[data-id=files]>a').click(); | |||
$('li[data-id=files] > a').click(); | |||
expect(App.navigation.getActiveItem()).toEqual('files'); | |||
expect($('#app-content-files').hasClass('hidden')).toEqual(false); | |||
expect($('#app-content-other').hasClass('hidden')).toEqual(true); | |||
expect($('li[data-id=files]').hasClass('active')).toEqual(true); | |||
expect($('li[data-id=other]').hasClass('active')).toEqual(false); | |||
expect($('li[data-id=files] > a').hasClass('active')).toEqual(true); | |||
expect($('li[data-id=other] > a').hasClass('active')).toEqual(false); | |||
}); | |||
it('clicking on navigation sends "show" and "urlChanged" event', function() { | |||
var handler = sinon.stub(); | |||
var showHandler = sinon.stub(); | |||
$('#app-content-other').on('urlChanged', handler); | |||
$('#app-content-other').on('show', showHandler); | |||
$('li[data-id=other]>a').click(); | |||
$('li[data-id=other] > a').click(); | |||
expect(handler.calledOnce).toEqual(true); | |||
expect(handler.getCall(0).args[0].view).toEqual('other'); | |||
expect(handler.getCall(0).args[0].dir).toEqual('/'); | |||
@@ -281,7 +281,7 @@ describe('OCA.Files.App tests', function() { | |||
var showHandler = sinon.stub(); | |||
$('#app-content-files').on('urlChanged', handler); | |||
$('#app-content-files').on('show', showHandler); | |||
$('li[data-id=files]>a').click(); | |||
$('li[data-id=files] > a').click(); | |||
expect(handler.calledOnce).toEqual(true); | |||
expect(handler.getCall(0).args[0].view).toEqual('files'); | |||
expect(handler.getCall(0).args[0].dir).toEqual('/'); |