@@ -0,0 +1,161 @@
2+ * Copyright (C) 2014 Canonical, Ltd.
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
18+import Ubuntu.Components 0.1
23+ property int windowHeight: 0
25+ property var scope: null
27+ property bool showList: false
29+ readonly property var currentDepartment: scope && scope.hasDepartments ? scope.getDepartment(scope.currentDepartment) : null
31+ // Are we drilling down the tree or up?
32+ property bool isGoingBack: false
34+ visible: root.currentDepartment != null
36+ height: visible ? units.gu(5) : 0
39+ root.showList = !root.showList;
46+ anchors.top: departmentListView.top
57+ fillMode: Image.Stretch
58+ source: "graphics/dash_divider_top_lightgrad.png"
64+ bottom: parent.bottom
68+ fillMode: Image.Stretch
69+ source: "graphics/dash_divider_top_darkgrad.png"
75+ anchors.margins: units.gu(2)
76+ verticalAlignment: Text.AlignVCenter
77+ text: root.currentDepartment ? root.currentDepartment.label : ""
81+ anchors.verticalCenter: parent.verticalCenter
82+ anchors.right: parent.right
83+ anchors.rightMargin: units.gu(2)
84+ rotation: showList ? 180 : 0
85+ source: "image://theme/dropdown-menu"
86+ height: parent.height - units.gu(2)
87+ fillMode: Image.PreserveAspectFit
90+ // departmentListView is outside root
92+ id: departmentListView
93+ orientation: ListView.Horizontal
99+ readonly property int maxHeight: units.gu(60)
100+ property int prevHeight: maxHeight
101+ height: currentItem ? currentItem.height : maxHeight
103+ console.log("MOOO", height)
104+ prevHeight = height;
106+ anchors.top: root.bottom
107+ delegate: DashDepartmentsList {
108+ visible: root.showList
109+ width: departmentListView.width
110+ height: department && department.loaded ? Math.min(implicitHeight, departmentListView.maxHeight) : departmentListView.prevHeight
111+ department: scope.getDepartment(departmentId)
112+ onEnterDepartment: {
113+ scope.loadDepartment(departmentId);
114+ // We only need to add a new item to the model
115+ // if we have children, otherwise just load it
117+ isGoingBack = false;
118+ departmentModel.append({"departmentId": departmentId});
119+ departmentListView.currentIndex++;
124+ onGoBackToParentClicked: {
125+ scope.loadDepartment(department.parentId);
127+ departmentModel.setProperty(departmentListView.currentIndex - 1, "departmentId", department.parentId);
128+ departmentListView.currentIndex--;
130+ onAllDepartmentClicked: {
132+ if (root.currentDepartment.count == 0) {
133+ // For leaves we have to go to the parent too
134+ scope.loadDepartment(root.currentDepartment.parentId);
138+ onContentXChanged: {
139+ if (contentX == width * departmentListView.currentIndex) {
141+ departmentModel.remove(departmentListView.currentIndex + 1);
143+ departmentModel.setProperty(departmentListView.currentIndex - 1, "departmentId", "");
150+ anchors.fill: departmentListView
151+ enabled: root.showList
152+ onClicked: root.showList = false
156+ departmentModel.clear();
157+ if (scope && scope.hasDepartments) {
158+ departmentModel.append({"departmentId": scope.currentDepartment});