-
Notifications
You must be signed in to change notification settings - Fork 578
/
Copy pathitem.js
68 lines (55 loc) · 2.4 KB
/
item.js
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
(function(angular) {
'use strict';
angular.module('FileManagerApp').factory('item', ['fileManagerConfig', 'chmod', function(fileManagerConfig, Chmod) {
var Item = function(model, path) {
var rawModel = {
name: model && model.name || '',
path: path || [],
type: model && model.type || 'file',
size: model && parseInt(model.size || 0),
date: parseMySQLDate(model && model.date),
perms: new Chmod(model && model.rights),
content: model && model.content || '',
recursive: false,
fullPath: function() {
var path = this.path.filter(Boolean);
return ('/' + path.join('/') + '/' + this.name).replace(/\/\//, '/');
}
};
this.error = '';
this.processing = false;
this.model = angular.copy(rawModel);
this.tempModel = angular.copy(rawModel);
function parseMySQLDate(mysqlDate) {
var d = (mysqlDate || '').toString().split(/[- :]/);
return new Date(d[0], d[1] - 1, d[2], d[3], d[4], d[5]);
}
};
Item.prototype.update = function() {
angular.extend(this.model, angular.copy(this.tempModel));
};
Item.prototype.revert = function() {
angular.extend(this.tempModel, angular.copy(this.model));
this.error = '';
};
Item.prototype.isFolder = function() {
return this.model.type === 'dir';
};
Item.prototype.isEditable = function() {
return !this.isFolder() && fileManagerConfig.isEditableFilePattern.test(this.model.name);
};
Item.prototype.isImage = function() {
return fileManagerConfig.isImageFilePattern.test(this.model.name);
};
Item.prototype.isCompressible = function() {
return this.isFolder();
};
Item.prototype.isExtractable = function() {
return !this.isFolder() && fileManagerConfig.isExtractableFilePattern.test(this.model.name);
};
Item.prototype.isSelectable = function() {
return (this.isFolder() && fileManagerConfig.allowedActions.pickFolders) || (!this.isFolder() && fileManagerConfig.allowedActions.pickFiles);
};
return Item;
}]);
})(angular);