Skip to content

Commit fb10bf4

Browse files
author
Vincent Petry
committed
Files app navigation can now switch
- added new OCA.Files namespace for files classes - the sidebar can now switch between views/containers - the trashbin renders in its own container but currently doesn't work due to overrides - added app.js as entry point for JS code (ideally all other files should only contain classes and not trigger anything)
1 parent 88ebb15 commit fb10bf4

File tree

9 files changed

+124
-7
lines changed

9 files changed

+124
-7
lines changed

.jshintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"fakeServer": true,
2727
"_": true,
2828
"OC": true,
29+
"OCA": true,
2930
"t": true,
3031
"n": true
3132
}

apps/files/index.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
OCP\Util::addStyle('files', 'files');
2929
OCP\Util::addStyle('files', 'upload');
3030
OCP\Util::addStyle('files', 'mobile');
31+
OCP\Util::addscript('files', 'app');
3132
OCP\Util::addscript('files', 'file-upload');
3233
OCP\Util::addscript('files', 'jquery.iframe-transport');
3334
OCP\Util::addscript('files', 'jquery.fileupload');
@@ -110,13 +111,14 @@ function renderScript($appName, $scriptName) {
110111
$content = renderScript($item['appname'], $item['script']);
111112
}
112113
$contentItem = array();
113-
$contentItem['appname'] = $item['appname'];
114+
$contentItem['id'] = $item['id'];
114115
$contentItem['content'] = $content;
115116
$contentItems[] = $contentItem;
116117
}
117118

118119
OCP\Util::addscript('files', 'fileactions');
119120
OCP\Util::addscript('files', 'files');
121+
OCP\Util::addscript('files', 'navigation');
120122
OCP\Util::addscript('files', 'keyboardshortcuts');
121123
$tmpl = new OCP\Template('files', 'index', 'user');
122124
$tmpl->assign('dir', $dir);

apps/files/js/app.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (c) 2014
3+
*
4+
* @author Vincent Petry
5+
* @copyright 2014 Vincent Petry <pvince81@owncloud.com>
6+
*
7+
* This file is licensed under the Affero General Public License version 3
8+
* or later.
9+
*
10+
* See the COPYING-README file.
11+
*
12+
*/
13+
14+
if (!OCA.Files) {
15+
OCA.Files = {};
16+
}
17+
18+
$(document).ready(function() {
19+
var nav = new OCA.Files.Navigation($('#app-navigation ul'));
20+
21+
nav.setSelectedItem('files');
22+
23+
// TODO: init file list, actions and others
24+
});
25+

apps/files/js/navigation.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright (c) 2014
3+
*
4+
* @author Vincent Petry
5+
* @copyright 2014 Vincent Petry <pvince81@owncloud.com>
6+
*
7+
* This file is licensed under the Affero General Public License version 3
8+
* or later.
9+
*
10+
* See the COPYING-README file.
11+
*
12+
*/
13+
14+
(function() {
15+
16+
var Navigation = function($el) {
17+
this.initialize($el);
18+
};
19+
20+
Navigation.prototype = {
21+
22+
/**
23+
* Currently selected item in the list
24+
*/
25+
_selectedItem: null,
26+
27+
/**
28+
* Currently selected container
29+
*/
30+
$currentContent: null,
31+
32+
/**
33+
* Initializes the navigation from the given container
34+
* @param $el element containing the navigation
35+
*/
36+
initialize: function($el) {
37+
this.$el = $el;
38+
this._selectedItem = null;
39+
this.$currentContent = null;
40+
this._setupEvents();
41+
},
42+
43+
/**
44+
* Setup UI events
45+
*/
46+
_setupEvents: function() {
47+
this.$el.on('click', 'li a', _.bind(this._onClickItem, this));
48+
},
49+
50+
/**
51+
* Switch the currently selected item, mark it as selected and
52+
* make the content container visible, if any.
53+
* @param string itemId id of the navigation item to select
54+
*/
55+
setSelectedItem: function(itemId) {
56+
if (itemId === this._selectedItem) {
57+
return;
58+
}
59+
this._selectedItem = itemId;
60+
this.$el.find('li').removeClass('selected');
61+
if (this.$currentContent) {
62+
this.$currentContent.addClass('hidden');
63+
}
64+
this.$currentContent = $('#app-content-' + itemId);
65+
this.$currentContent.removeClass('hidden');
66+
this.$el.find('li[data-id=' + itemId + ']').addClass('selected');
67+
},
68+
69+
/**
70+
* Event handler for when clicking on an item.
71+
*/
72+
_onClickItem: function(ev) {
73+
var $target = $(ev.target);
74+
var itemId = $target.closest('li').attr('data-id');
75+
this.setSelectedItem(itemId);
76+
}
77+
};
78+
79+
OCA.Files.Navigation = Navigation;
80+
81+
})();

apps/files/templates/appnavigation.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<div id="app-navigation">
22
<ul>
3-
<li class="nav-allfiles"><a href="<?php p(OC_Helper::linkTo('files', '')) ?>"><?php p($l->t('All Files'));?></a></li>
3+
<li data-id="files" class="nav-allfiles"><a href="#"><?php p($l->t('All Files'));?></a></li>
44
<li class="sep"></li>
55
<?php foreach ($_['navigationItems'] as $item) { ?>
6-
<li class="nav-<?php p($item['appname']) ?>"><a href="<?php p(isset($item['href']) ? $item['href'] : '#') ?>"><?php p($item['name']);?></a></li>
6+
<li data-id="<?php p($item['id']) ?>" class="nav-<?php p($item['id']) ?>"><a href="<?php p(isset($item['href']) ? $item['href'] : '#') ?>"><?php p($item['name']);?></a></li>
77
<?php } ?>
88
</ul>
99
<div id="app-settings">

apps/files/templates/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
</div>
114114
</div><!-- closing app-content-files -->
115115
<?php foreach ($_['appContents'] as $content) { ?>
116-
<div id="app-content-<?php p($content['appname']) ?>" class="hidden">
116+
<div id="app-content-<?php p($content['id']) ?>" class="hidden">
117117
<?php print_unescaped($content['content']) ?>
118118
</div>
119119
<?php } ?>

apps/files_trashbin/appinfo/app.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
\OCA\Files\App::getNavigationManager()->add(
88
array(
9+
"id" => 'trashbin',
910
"appname" => 'files_trashbin',
1011
"script" => 'index.php',
1112
"order" => 1,

apps/files_trashbin/index.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
// Check if we are a user
44
OCP\User::checkLoggedIn();
55

6-
OCP\Util::addScript('files_trashbin', 'disableDefaultActions');
76

87
$tmpl = new OCP\Template('files_trashbin', 'index', '');
9-
8+
// TODO: re-enable after making sure the scripts doesn't
9+
// override the files app
10+
/*
11+
OCP\Util::addScript('files_trashbin', 'disableDefaultActions');
1012
OCP\Util::addStyle('files_trashbin', 'trash');
1113
OCP\Util::addScript('files_trashbin', 'filelist');
1214
OCP\Util::addScript('files_trashbin', 'trash');
13-
15+
*/
1416
$tmpl->printPage();

core/js/js.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,11 @@ OC.set=function(name, value) {
13671367
}
13681368
})();
13691369

1370+
/**
1371+
* Namespace for apps
1372+
*/
1373+
window.OCA = {};
1374+
13701375
/**
13711376
* select a range in an input field
13721377
* @link http://stackoverflow.com/questions/499126/jquery-set-cursor-position-in-text-area

0 commit comments

Comments
 (0)