aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/js/detailtabview.js
blob: b9b1dda2ccc1b6070fcf2c8f4ea04658ffbe52b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
 * Copyright (c) 2015
 *
 * This file is licensed under the Affero General Public License version 3
 * or later.
 *
 * See the COPYING-README file.
 *
 */

(function() {

	/**
	 * @class OCA.Files.DetailTabView
	 * @classdesc
	 *
	 * Base class for tab views to display file information.
	 *
	 */
	var DetailTabView = function(id) {
		this.initialize(id);
	};

	/**
	 * @memberof OCA.Files
	 */
	DetailTabView.prototype = {
		/**
		 * jQuery element
		 */
		$el: null,

		/**
		 * Tab id
		 */
		_id: null,

		/**
		 * Tab label
		 */
		_label: null,

		_template: null,

		/**
		 * Currently displayed file info
		 *
		 * @type OCA.Files.FileInfo
		 */
		_fileInfo: null,

		/**
		 * Initialize the details view
		 *
		 * @param {string} id tab id
		 */
		initialize: function(id) {
			if (!id) {
				throw 'Argument "id" is required';
			}
			this._id = id;
			this.$el = $('<div class="tab"></div>');
			this.$el.attr('data-tabid', id);
		},

		/**
		 * Destroy / uninitialize this instance.
		 */
		destroy: function() {
			if (this.$el) {
				this.$el.remove();
			}
		},

		/**
		 * Returns the tab element id
		 *
		 * @return {string} tab id
		 */
		getId: function() {
			return this._id;
		},

		/**
		 * Returns the tab label
		 *
		 * @return {String} label
		 */
		getLabel: function() {
			return 'Tab ' + this._id;
		},

		/**
		 * returns the jQuery object for HTML output
		 *
		 * @returns {jQuery}
		 */
		get$: function() {
			return this.$el;
		},

		/**
		 * Renders this details view
		 *
		 * @abstract
		 */
		render: function() {
			// to be implemented in subclass
			// FIXME: code is only for testing
			this.$el.empty();
			this.$el.append('<div>Hello ' + this._id + '</div>');
		},

		/**
		 * Sets the file info to be displayed in the view
		 *
		 * @param {OCA.Files.FileInfo} fileInfo file info to set
		 */
		setFileInfo: function(fileInfo) {
			this._fileInfo = fileInfo;
			this.render();
		},

		/**
		 * Returns the file info.
		 *
		 * @return {OCA.Files.FileInfo} file info
		 */
		getFileInfo: function() {
			return this._fileInfo;
		}
	};

	OCA.Files.DetailTabView = DetailTabView;
})();