-
Notifications
You must be signed in to change notification settings - Fork 41
/
html-upload-plus.js
183 lines (156 loc) · 8.57 KB
/
html-upload-plus.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
(function () {
Alfresco.logger.debug("html-upload-plus.js");
SoftwareLoop.HtmlUpload = function (id)
{
// use "null" to avoid Alfresco.component.Base + Alfresco.util.ComponentManager to override Alfresco.DNDUpload
SoftwareLoop.HtmlUpload.superclass.constructor.call(this, "null");
// re-register with correct id and name
Alfresco.util.ComponentManager.unregister(this);
this.id = (typeof id == "undefined" || id === null) ? Alfresco.util.generateDomId() : id;
this.name = "SoftwareLoop.HtmlUpload";
Alfresco.util.ComponentManager.register(this);
return this;
};
YAHOO.lang.extend(SoftwareLoop.HtmlUpload, Alfresco.HtmlUpload, YAHOO.lang.merge(SoftwareLoop.UploaderPlusMixin, {
records : null,
currentRecordIndex : -1,
//**************************************************************************
// Initialisation at show
//**************************************************************************
show: function (config) {
Alfresco.logger.debug("show", arguments);
this.showMainDialog();
SoftwareLoop.HtmlUpload.superclass.show.call(this, config);
this.loadTypes(function () {
Alfresco.logger.debug("loadTypes callback");
this.populateSelect();
if (this.types != null) {
Alfresco.logger.debug("this.types is not null");
this.fixButtons();
}
}, this);
Alfresco.logger.debug("END show");
},
fixButtons: function () {
Alfresco.logger.debug("fixButtons", arguments);
this.widgets.uploadButton.set("label", this.msg("uploader.plus.next"));
this.widgets.uploadButton.removeListener("click");
this.widgets.uploadButton.on(
"click", function (event) {
Alfresco.logger.debug("uploadButton callback", event);
this.widgets.form._setAllFieldsAsVisited();
if (this.widgets.form.validate()) {
Alfresco.logger.debug("Form validation passed");
this.showMetadataDialog();
}
}, this, this);
Alfresco.logger.debug("END fixButtons");
},
//**************************************************************************
// Metadata dialog management
//**************************************************************************
showMetadataDialog: function () {
Alfresco.logger.debug("showMetadataDialog", arguments);
YAHOO.util.Dom.addClass(this.id + "-main-dialog", "fake-hidden");
YAHOO.util.Dom.removeClass(this.id + "-metadata-dialog", "hidden");
var filename;
if (this.widgets.filedata.files) {
Alfresco.logger.debug("Filedata files available");
filename = this.widgets.filedata.files[0].name;
} else {
Alfresco.logger.debug("IE-style full path");
var path = this.widgets.filedata.value;
filename = path.substring(path.lastIndexOf('\\') + 1);
}
this.currentRecordIndex = 0;
this.records = [];
this.records.push({
getData: function () {
Alfresco.logger.debug("getData callback");
return {
name: filename
}
}
});
SoftwareLoop.fireEvent(this.contentTypeSelectNode, "change");
Alfresco.logger.debug("END showMetadataDialog");
},
showMainDialog: function () {
Alfresco.logger.debug("showMainDialog", arguments);
this.records = null;
this.currentRecordIndex = -1;
YAHOO.util.Dom.removeClass(this.id + "-main-dialog", "fake-hidden");
YAHOO.util.Dom.addClass(this.id + "-metadata-dialog", "hidden");
this.centerPanel();
Alfresco.logger.debug("END showMainDialog");
},
//**************************************************************************
// Form button handling
//**************************************************************************
onMetadataSubmit: function (event) {
Alfresco.logger.debug("onMetadataSubmit", arguments);
this.formUi.formsRuntime._setAllFieldsAsVisited();
if (this.formUi.formsRuntime.validate()) {
Alfresco.logger.debug("Form validated");
this.processMetadata();
this.widgets.form._submitInvoked.call(this.widgets.form, event);
} else {
Alfresco.logger.debug("Form with errors");
Alfresco.util.PopupManager.displayMessage({
text: this.msg("validation.errors.correct.before.proceeding")
});
}
Alfresco.logger.debug("END onMetadataSubmit");
},
processMetadata: function () {
Alfresco.logger.debug("processMetadata", arguments);
var contentTypeInputNode =
YAHOO.util.Dom.get(
this.id + "-contentTypeInput");
if (contentTypeInputNode) {
Alfresco.logger.debug("contentTypeInputNode found");
contentTypeInputNode.value =
this.contentTypeSelectNode.value;
}
var formRuntime = this.formUi.formsRuntime;
var form = Dom.get(formRuntime.formId);
var propertyData = formRuntime._buildAjaxForSubmit(form);
var submitForm =
YAHOO.util.Dom.get(this.widgets.form.formId);
for (var current in propertyData) {
Alfresco.logger.debug("Current:", current);
if (propertyData.hasOwnProperty(current) &&
(current != "prop_mimetype" ||
(current == "prop_mimetype" && YAHOO.lang.isString(propertyData[current]) && propertyData[current].length > 0)
)) {
Alfresco.logger.debug("Adding property", current);
var input = document.createElement("input");
input.setAttribute("type", "hidden");
input.setAttribute("name", current);
input.setAttribute("value", propertyData[current]);
submitForm.appendChild(input);
}
}
Alfresco.logger.debug("END processMetadata", propertyData);
},
onMetadataCancel: function () {
Alfresco.logger.debug("onMetadataCancel", arguments);
this.showMainDialog();
Alfresco.logger.debug("END onMetadataCancel");
},
_applyConfig : function (showConfig)
{
SoftwareLoop.HtmlUpload.superclass._applyConfig.apply(this, arguments);
// need to adapt the URL (if none was provided)
var formEl = Dom.get(this.id + "-htmlupload-form");
if (this.showConfig.uploadURL === null)
{
// The .html suffix is required - it is not possible to do a multipart post using an ajax call.
// So it has to be a FORM submit, to make it feel like an ajax call a a hidden iframe is used.
// Since the component still needs to be called when the upload is finished, the script returns
// an html template with SCRIPT tags inside that which calls the component that triggered it.
formEl.action = Alfresco.constants.PROXY_URI + "uploader-plus/upload.html";
}
}
}));
})();