summaryrefslogtreecommitdiffstats
path: root/core/js/shareitemmodel.js
blob: 1db49536db5fe5c4e40b9d5415d1ef7f9e43e86c (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
/*
 * Copyright (c) 2015
 *
 * This file is licensed under the Affero General Public License version 3
 * or later.
 *
 * See the COPYING-README file.
 *
 */

(function() {
	if(!OC.Share) {
		OC.Share = {};
		OC.Share.Types = {};
	}

	/**
	 * @typedef {object} OC.Share.Types.Reshare
	 * @property {string} uid_owner
	 * @property {number} share_type
	 * @property {string} share_with
	 * @property {string} displayname_owner
	 * @property {number} permissions
	 */

	/**
	 * @typedef {object} OC.Share.Types.ShareInfo
	 * @property {number} share_type
	 * @property {number} permissions
	 * @property {number} file_source optional
	 * @property {number} item_source
	 * @property {string} token
	 * @property {string} share_with
	 * @property {string} share_with_displayname
	 * @property {string} share_mail_send
	 * @property {bool} collection //TODO: verify
	 * @property {Date} expiration optional?
	 * @property {number} stime optional?
	 */

	/**
	 * @typedef {object} OC.Share.Types.ShareItemInfo
	 * @property {OC.Share.Types.Reshare} reshare
	 * @property {OC.Share.Types.ShareInfo[]} shares
	 */

	/**
	 * @class OCA.Share.ShareItemModel
	 * @classdesc
	 *
	 * Represents the GUI of the share dialogue
	 *
	 */
	var ShareItemModel = function(itemType, itemSource) {
		this.initialize(itemType, itemSource);
	};

	/**
	 * @memberof OCA.Sharing
	 */
	ShareItemModel.prototype = {
		/** @var {string} **/
		_itemType: null,
		/** @var {mixed} **/	//TODO: what type?
		_itemSource: null,

		/** @var {OC.Share.Types.Reshare} **/
		_reshare: null,

		/** @var {OC.Share.Types.ShareInfo[]} **/
		_shares: null,

		initialize: function(itemType, itemSource) {
			this._itemType = itemType;
			this._itemSource = itemSource;
			this._retrieveData();
		},

		hasReshare: function() {
			return _.isObject(this._reshare) && !_.isUndefined(this._reshare.uid_owner);
		},

		getReshareOwner: function() {
			return this._reshare.uid_owner;
		},

		getReshareOwnerDisplayname: function() {
			return this._reshare.displayname_owner;
		},

		getReshareWith: function() {
			return this._reshare.share_with;
		},

		getReshareType: function() {
			return this._reshare.share_type;
		},

		_retrieveData: function() {
			/** var {OC.Share.Types.ShareItemInfo} **/
			var data = OC.Share.loadItem(this._itemType, this._itemSource);
			if(data === false) {
				console.warn('no data was returned');
				return;
			}
			this._reshare = data.reshare;
			this._shares = data.shares;

		}
	};

	OC.Share.ShareItemModel = ShareItemModel;
})();