forked from mozilla/cleopatra
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathfileList.js
155 lines (136 loc) · 5.31 KB
/
fileList.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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
'use strict';
(function(window) {
function loadLocalStorageProfile(profileKey) {
var reporter = AppUI.enterProgressUI();
var subreporters = reporter.addSubreporters({
fileLoading: 1000,
parsing: 1000
});
gLocalStorage.getProfile(profileKey, function(profile) {
subreporters.fileLoading.finish();
Cleopatra.loadRawProfile(subreporters.parsing, profile, profileKey);
});
subreporters.fileLoading.begin("Reading local storage...");
}
/**
* FileList is the panel displaying all files.
*/
function FileList() {
this._container = document.createElement("ul");
this._container.id = "fileList";
this._selectedFileItem = null;
this._fileItemList = [];
}
FileList.prototype = {
getContainer: function FileList_getContainer() {
return this._container;
},
clearFiles: function FileList_clearFiles() {
this.fileItemList = [];
this._selectedFileItem = null;
this._container.innerHTML = "";
},
loadProfileListFromLocalStorage: function FileList_loadProfileListFromLocalStorage() {
var self = this;
gLocalStorage.getProfileList(function(profileList) {
for (var i = profileList.length - 1; i >= 0; i--) {
(function closure() {
// This only carries info about the profile and the access key to retrieve it.
var profileInfo = profileList[i];
//PROFILERTRACE("Profile list from local storage: " + JSON.stringify(profileInfo));
var dateObj = new Date(profileInfo.date);
var fileEntry = self.addFile(profileInfo, dateObj.toLocaleString(), function fileEntryClick() {
loadLocalStorageProfile(profileInfo.profileKey);
},
function fileRename(newName) {
gLocalStorage.renameProfile(profileInfo.profileKey, newName);
},
function fileDelete() {
gLocalStorage.deleteLocalProfile(profileInfo.profileKey, function deletedProfileCallback() {
self.clearFiles();
gFileList.loadProfileListFromLocalStorage();
});
});
})();
}
});
gLocalStorage.onProfileListChange(function(profileList) {
self.clearFiles();
self.loadProfileListFromLocalStorage();
});
},
addFile: function FileList_addFile(profileInfo, description, onselect, onrename, ondelete) {
var li = document.createElement("li");
var fileName;
if (profileInfo.profileKey && profileInfo.profileKey.indexOf("http://profile-store.commondatastorage.googleapis.com/") >= 0) {
fileName = profileInfo.profileKey.substring(54);
fileName = fileName.substring(0, 8) + "..." + fileName.substring(28);
} else {
fileName = profileInfo.name;
}
li.fileName = fileName || "(New Profile)";
li.description = description || "(empty)";
li.className = "fileListItem";
if (!this._selectedFileItem) {
li.classList.add("selected");
this._selectedFileItem = li;
}
var self = this;
li.onclick = function() {
self.setSelection(li);
if (onselect)
onselect();
}
var fileListItemTitleSpan = document.createElement("input");
fileListItemTitleSpan.type = "input";
fileListItemTitleSpan.className = "fileListItemTitle";
fileListItemTitleSpan.value = li.fileName;
fileListItemTitleSpan.onclick = function(event) {
event.stopPropagation();
};
fileListItemTitleSpan.onblur = function() {
if (fileListItemTitleSpan.value != li.fileName) {
onrename(fileListItemTitleSpan.value);
}
};
fileListItemTitleSpan.onkeypress = function(event) {
var code = event.keyCode;
var ENTER_KEYCODE = 13;
if (code == ENTER_KEYCODE) {
fileListItemTitleSpan.blur();
onrename(fileListItemTitleSpan.value);
}
};
li.appendChild(fileListItemTitleSpan);
var fileListItemDescriptionSpan = document.createElement("span");
fileListItemDescriptionSpan.className = "fileListItemDescription";
fileListItemDescriptionSpan.textContent = li.description;
li.appendChild(fileListItemDescriptionSpan);
var deleteProfileButton = document.createElement("div");
deleteProfileButton.className = "fileListItemDelete";
deleteProfileButton.title = "Delete the profile from your local cache";
deleteProfileButton.onclick = function(event) {
event.stopPropagation();
ondelete();
};
li.appendChild(deleteProfileButton);
this._container.appendChild(li);
this._fileItemList.push(li);
return li;
},
setSelection: function FileList_setSelection(fileEntry) {
if (this._selectedFileItem) {
this._selectedFileItem.classList.remove("selected");
}
this._selectedFileItem = fileEntry;
fileEntry.classList.add("selected");
if (this._selectedFileItem.onselect)
this._selectedFileItem.onselect();
},
profileParsingFinished: function FileList_profileParsingFinished() {
//this._container.querySelector(".fileListItemTitle").textContent = "Current Profile";
//this._container.querySelector(".fileListItemDescription").textContent = gNumSamples + " Samples";
}
};
window.FileList = FileList;
}(this));