Issues (108)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

js/documents.js (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
/*globals $,OC,fileDownloadPath,t,document,odf,webodfEditor,alert,require,dojo,runtime */
2
3
$.widget('oc.documentGrid', {
4
	options : {
5
		context : '.documentslist',
6
		documents : {},
7
		sessions : {},
8
		members : {}
9
	},
10
	
11
	_create : function (){
12
			
13
	},
14
	
15
	render : function(){
16
		var that = this;
17
		jQuery.when(this._load())
18
			.then(function(){
19
				that._render();
20
			});
21
	},
22
	
23
	add : function(document) {
24
		var docElem = $(this.options.context + ' .template').clone(),
25
			a = docElem.find('a')
26
		;
27
28
		//Fill an element
29
		docElem.removeClass('template').attr('data-id', document.fileid);
30
		a.css('background-image', 'url("'+document.icon+'")')
31
			.attr('href', OC.generateUrl('apps/files/download{file}',{file:document.path}))
32
			.attr('original-title', document.path)
33
			.find('label').text(document.name)
34
		;
35
		
36
		docElem.appendTo(this.options.context).show();
37
		
38
		//Preview
39
		var previewURL,
40
			urlSpec = {
41
			file : document.path.replace(/^\/\//, '/'),
42
			x : 200,
43
			y : 200,
44
			c : document.etag,
45
			forceIcon : 0
46
		};
47
48
		if ( $('#isPublic').length ) {
49
			urlSpec.t = $('#dirToken').val();
50
		}
51
		
52
		if (!urlSpec.x) {
53
			urlSpec.x = $('#filestable').data('preview-x');
54
		}
55
		if (!urlSpec.y) {
56
			urlSpec.y = $('#filestable').data('preview-y');
57
		}
58
		urlSpec.y *= window.devicePixelRatio;
59
		urlSpec.x *= window.devicePixelRatio;
60
61
		previewURL = OC.generateUrl('/core/preview.png?') + $.param(urlSpec);
62
		previewURL = previewURL.replace('(', '%28').replace(')', '%29');
63
		
64
		if ( $('#previews_enabled').length && document.hasPreview) {
65
			var img = new Image();
66
			img.onload = function(){
67
				var ready = function (node){
68
					return function(path){
69
						node.css('background-image', 'url("'+ path +'")');
70
					}; 
71
				}(a);
72
				ready(previewURL);
73
			};
74
			img.src = previewURL;
75
		}
76
	},
77
	
78
	_load : function (){
79
		var that = this;
80
		var def = new $.Deferred();
81
		$.getJSON(OC.generateUrl('apps/documents/ajax/documents/list'))
82
			.done(function (data) {
83
				that.options.documents = data.documents;
84
				that.options.sessions = data.sessions;
85
				that.options.members = data.members;
86
				def.resolve();
87
			})
88
			.fail(function(data){
89
				console.log(t('documents','Failed to load documents.'));
90
			});
91
		return def;
92
	},
93
	
94
	_render : function (data){
95
		var that = this,
96
			documents = data && data.documents || this.options.documents,
97
			sessions = data && data.sessions || this.options.sessions,
98
			members = data && data.members || this.options.members,
99
			hasDocuments = false
100
		;
101
		
102
		$(this.options.context + ' .document:not(.template,.progress)').remove();
103
		
104
		$.each(documents, function(i, document){
105
			hasDocuments = true;
106
			that.add(document);
107
		});
108
		
109
		$.each(sessions, function(i, session){
110
			if (members[session.es_id].length > 0) {
111
				var docElem = $(that.options.context + ' .document[data-id="'+session.file_id+'"]');
112
				if (docElem.length > 0) {
113
					docElem.attr('data-esid', session.es_id);
114
					docElem.find('label').after('<img class="svg session-active" src="'+OC.imagePath('core','places/contacts-dark')+'">');
115
					docElem.addClass('session');
116
				} else {
117
					console.log('Could not find file '+session.file_id+' for session '+session.es_id);
118
				}
119
			}
120
		});
121
		
122
		if (!hasDocuments){
123
			$(this.options.context).before('<div id="emptycontent">'
124
				+ t('documents', 'No documents were found. Upload or create a document to get started!')
125
				+ '</div>'
126
			);
127
		} else {
128
			$('#emptycontent').remove();
129
		}
130
	}
131
});
132
133
$.widget('oc.documentOverlay', {
134
	options : {
135
		parent : 'document.body'
136
	},
137
	_create : function (){
138
		$(this.element).hide().appendTo(document.body);
139
	},
140
	show : function(){
141
		$(this.element).fadeIn('fast');
142
	},
143
	hide : function(){
144
		$(this.element).fadeOut('fast');
145
	}
146
});
147
148
var documentsMain = {
149
	isEditormode : false,
150
	useUnstable : false,
151
	isGuest : false,
152
	memberId : false,
153
	esId : false,
154
	ready :false,
155
	fileName: null,
156
	canShare : false,
157
	toolbar : '<div id="ocToolbar"><div id="ocToolbarInside"></div><span id="toolbar" class="claro"></span></div>',
158
	
159
	UI : {		
160
		/* Editor wrapper HTML */
161
		container : '<div id="mainContainer" class="claro">' +
162
					'  <div id="editor" class="webodfeditor-editor">' +
163
					'    <div id="container" class="webodfeditor-canvascontainer">' +
164
					'      <div id="canvas" class="webodfeditor-canvas"></div>' +
165
					'    </div>' +
166
					'  </div>' +
167
					'  <div id="collaboration">' +
168
					'    <div id="collabContainer">' +
169
					'      <div id="members">' +
170
					'        <div id="inviteButton"></div>' +
171
					'        <div id="memberList"></div>' +
172
					'      </div>' +
173
					'    </div>' +
174
					'  </div>' +
175
					'</div>',
176
					
177
		/* Previous window title */
178
		mainTitle : '',
179
				
180
		init : function(){
181
			documentsMain.UI.mainTitle = $('title').text();
182
		},
183
		
184
		showEditor : function(title){
185
			if (documentsMain.isGuest){
186
				// !Login page mess wih WebODF toolbars
187
				$(document.body).attr('id', 'body-user');
188
			}
189
190
			$(document.body).addClass("claro");
191
			$(document.body).prepend(documentsMain.UI.container);
192
			// in case we are on the public sharing page we shall display the odf into the preview tag
193
			$('#preview').html(container);
194
			$('title').text(title + ' - ' + documentsMain.UI.mainTitle);
195
		},
196
		
197
		hideEditor : function(){
198
			if (documentsMain.isGuest){
199
				// !Login page mess wih WebODF toolbars
200
				$(document.body).attr('id', 'body-login');
201
				$('footer,nav').show();
202
			}
203
			
204
			// Fade out editor
205
			$('#mainContainer').fadeOut('fast', function() {
206
				$('#mainContainer').remove();
207
				$('#content-wrapper').fadeIn('fast');
208
				$(document.body).removeClass('claro');
209
				$('title').text(documentsMain.UI.mainTitle);
210
			});
211
		},
212
		
213
		showSave : function (){
214
			$('#odf-close').hide();
215
			$('#saving-document').show();
216
		},
217
		
218
		hideSave : function(){
219
			$('#saving-document').hide();
220
			$('#odf-close').show();
221
		},
222
		
223
		showProgress : function(message){
224
			if (!message){
225
				message = '&nbsp;';
226
			}
227
			$('.documentslist .progress div').text(message);
228
			$('.documentslist .progress').show();
229
		},
230
		
231
		hideProgress : function(){
232
			$('.documentslist .progress').hide();
233
		},
234
		
235
		showLostConnection : function(){
236
			$('#memberList .memberListButton').css({opacity : 0.3});
237
			$('#ocToolbar').children(':not(#document-title)').hide();
238
			$('<div id="connection-lost"></div>').prependTo('#memberList');
239
			$('<div id="warning-connection-lost">' + t('documents', 'No connection to server. Trying to reconnect.') +'<img src="'+ OC.imagePath('core', 'loading-dark.gif') +'" alt="" /></div>').prependTo('#ocToolbar');
240
		},
241
		
242
		hideLostConnection : function() {
243
			$('#connection-lost,#warning-connection-lost').remove();
244
			$('#ocToolbar').children(':not(#document-title,#saving-document)').show();
245
			$('#memberList .memberListButton').css({opacity : 1});
246
		},
247
		
248
		notify : function(message){
249
			OC.Notification.show(message);
250
			setTimeout(OC.Notification.hide, 10000);
251
		}
252
	},
253
	
254
	onStartup: function() {
255
		var fileId;
256
		documentsMain.useUnstable = $('#webodf-unstable').val()==='true';
257
		documentsMain.UI.init();
258
		
259
		if (!OC.currentUser){
260
			documentsMain.isGuest = true;
261
			
262
			if ($("[name='document']").val()){
263
				$(documentsMain.toolbar).appendTo('#header');
264
				documentsMain.prepareSession();
265
				documentsMain.joinSession(
266
					$("[name='document']").val()
267
				);
268
			}
269
270
		} else {
271
			// Does anything indicate that we need to autostart a session?
272
			fileId = parent.location.hash.replace(/\W*/g, '');
273
		}
274
		
275
		documentsMain.show();
276
		if (fileId){
277
			documentsMain.overlay.documentOverlay('show');
278
		}
279
		
280
		OC.addScript('documents', '3rdparty/webodf/webodf-debug').done(function() {
281
			// preload stuff in the background
282
			require({}, ["dojo/ready"], function(ready) {
283
				ready(function() {
284
					require({}, ["webodf/editor/Editor"], function(Editor) {
285
						runtime.setTranslator(function(s){return t('documents', s);});
286
						documentsMain.ready = true;
287
						if (fileId){
288
							documentsMain.prepareSession();
289
							documentsMain.joinSession(fileId);
290
						}
291
					});
292
				});
293
			});
294
		});
295
	},
296
	
297
	prepareSession : function(){
298
		documentsMain.isEditorMode = true;
299
		documentsMain.overlay.documentOverlay('show');
300
		$(window).on('beforeunload', function(){
301
			return t('documents', "Leaving this page in Editor mode might cause unsaved data. It is recommended to use 'Close' button instead."); 
302
		});
303
		$(window).on("unload", documentsMain.onTerminate);
304
	},
305
	
306
	prepareGrid : function(){
307
		documentsMain.isEditorMode = false;
308
		documentsMain.overlay.documentOverlay('hide');
309
	},
310
	
311
	initSession: function(response) {
312
		if(response && (response.id && !response.es_id)){
313
			return documentsMain.view(response.id);
314
		}
315
		
316
		$('footer,nav').hide();
317
		$(documentsMain.toolbar).appendTo('#header');
318
		
319
		if (!response || !response.status || response.status==='error'){
320
			documentsMain.onEditorShutdown(t('documents', 'Failed to load this document. Please check if it can be opened with an external odt editor. This might also mean it has been unshared or deleted recently.'));
321
			return;
322
		}
323
		
324
		//Wait for 3 sec if editor is still loading 
325
		if (!documentsMain.ready){
326
			setTimeout(function(){ documentsMain.initSession(response); }, 3000);
327
			console.log('Waiting for the editor to start...');
328
			return;
329
		}
330
331
		var pollUrl = documentsMain.isGuest 
332
				? OC.generateUrl('apps/documents/session/guest/poll/{token}', {'token' : $("[name='document']").val()})
333
				: OC.generateUrl('apps/documents/session/user/poll'),
334
			saveUrl = documentsMain.isGuest 
335
				? OC.generateUrl('apps/documents/session/guest/save/{token}', {'token' : $("[name='document']").val()})
336
				: OC.generateUrl('apps/documents/session/user/save')
337
				;
338
		documentsMain.canShare = !documentsMain.isGuest
339
				&& typeof OC.Share !== 'undefined' && response.permissions & OC.PERMISSION_SHARE;
340
		require({ }, ["owncloud/ServerFactory", "webodf/editor/Editor"], function (ServerFactory, Editor) {
341
			// fade out file list and show WebODF canvas
342
			$('#content-wrapper').fadeOut('fast').promise().done(function() {
343
				
344
				documentsMain.fileId = response.file_id;
345
				documentsMain.fileName = response.title;
346
				
347
				documentsMain.UI.showEditor(documentsMain.fileName || response.title);
348
				if (documentsMain.isGuest){
349
					$('#odf-close').text(t('documents', 'Save') );
350
					$('#odf-close').removeClass('icon-view-close');
351
				}
352
				var serverFactory = new ServerFactory();
353
				documentsMain.esId = response.es_id;
354
				documentsMain.memberId = response.member_id;
355
356
				// TODO: set webodf translation system, by passing a proper function translate(!string):!string in "runtime.setTranslator(translate);"
357
				documentsMain.webodfServerInstance = serverFactory.createServer({
358
					url : pollUrl,
359
					sessionStateToFileUrl : saveUrl
360
				});
361
				documentsMain.webodfServerInstance.setToken(oc_requesttoken);
362
				documentsMain.webodfEditorInstance = new Editor(
363
						{
364
							allFeaturesEnabled: true,
365
							collabEditingEnabled: true
366
						},
367
						documentsMain.webodfServerInstance, serverFactory
368
				);
369
				
370
				documentsMain.webodfEditorInstance.addEventListener(Editor.EVENT_BEFORESAVETOFILE, documentsMain.UI.showSave);
371
				documentsMain.webodfEditorInstance.addEventListener(Editor.EVENT_SAVEDTOFILE, documentsMain.UI.hideSave);
372
				documentsMain.webodfEditorInstance.addEventListener(Editor.EVENT_ERROR, documentsMain.onEditorShutdown);
373
				documentsMain.webodfEditorInstance.addEventListener(Editor.EVENT_HASSESSIONHOSTCONNECTIONCHANGED, function(has) {
374
					if (has){
375
						documentsMain.UI.hideLostConnection();
376
					} else {
377
						documentsMain.UI.showLostConnection();
378
					}
379
				});
380
				// load the document and get called back when it's live
381
				documentsMain.webodfEditorInstance.openSession(documentsMain.esId, documentsMain.memberId, function() {
382
					documentsMain.webodfEditorInstance.startEditing();
383
					documentsMain.overlay.documentOverlay('hide');
384
					parent.location.hash = response.file_id;
385
				});
386
			});
387
		});
388
	},
389
	
390
391
	joinSession: function(fileId) {
392
		console.log('joining session '+fileId);
393
		var url;
394
		if (documentsMain.isGuest){
395
			url = OC.generateUrl('apps/documents/session/guest/join/{token}', {token: fileId});
396
		} else {
397
			url = OC.generateUrl('apps/documents/session/user/join/{file_id}', {file_id: fileId});
398
		}
399
		$.post(
400
			url,
401
			{ name : $("[name='memberName']").val() },
402
			documentsMain.initSession
403
		);
404
	},
405
	
406
	view : function(id){
407
		OC.addScript('documents', 'viewer/viewer', function() {
408
			documentsMain.prepareGrid();
409
			$(window).off('beforeunload');
410
			$(window).off('unload');
411
			var path = $('li[data-id='+ id +']>a').attr('href');
412
			odfViewer.isDocuments = true;
413
			odfViewer.onView(path);
414
		});
415
	},
416
			
417
	onCreate: function(event){
418
		event.preventDefault();
419
		var docElem = $('.documentslist .template').clone();
420
		docElem.removeClass('template');
421
		docElem.addClass('document');
422
		docElem.insertAfter('.documentslist .template');
423
		docElem.show();
424
		$.post(
425
			OC.generateUrl('apps/documents/ajax/documents/create'),
426
			{},
427
			function(response){
428
				if (response && response.fileid){
429
					documentsMain.prepareSession();
430
					documentsMain.joinSession(response.fileid);
431
				} else {
432
					if (response && response.message){
433
						documentsMain.UI.notify(response.message);
434
					}
435
					documentsMain.show();
436
				}
437
			}
438
			
439
		);
440
	},
441
	
442
	changeNick: function(memberId, name, node){
443
		var url = OC.generateUrl('apps/documents/ajax/user/rename');
444
		$.ajax({
445
			url: url,
446
			type: "POST",
447
			data: JSON.stringify({ 
448
				name : name,
449
				memberId : memberId
450
			}),
451
			contentType: 'application/json; charset=utf-8',
452
			dataType:"json",
453
			success: function(result) {
454
				if (result && result.status === 'error') {
455
					if (result.message){
456
						documentsMain.UI.notify(result.message);
457
					}
458
					return;
459
				}
460
			}
461
		});
462
	},
463
	
464
	onNickChange: function(memberId, fullNameNode){
465
		if (!documentsMain.isGuest || memberId !== documentsMain.memberId){
466
			return;
467
		}
468
		if ($(fullNameNode.parentNode).children('input').length !== 0){
469
			return;
470
		}
471
		
472
		var input = $('<input type="text"/>').val($(fullNameNode).attr('fullname'));
473
		$(fullNameNode.parentNode).append(input);
474
		$(fullNameNode).hide();
475
476
		input.on('blur', function(){
477
			var newName = input.val();
478
			if (!newName || newName === name) {
479
				input.tipsy('hide');
480
				input.remove();
481
				$(fullNameNode).show();
482
				return;
483
			}
484
			else {
485
				try {
486
					input.tipsy('hide');
487
					input.removeClass('error');
488
					input.tipsy('hide');
489
					input.remove();
490
					$(fullNameNode).show();
491
					documentsMain.changeNick(memberId, newName, fullNameNode);
492
				}
493
				catch (error) {
494
					input.attr('title', error);
495
					input.tipsy({gravity: 'n', trigger: 'manual'});
496
					input.tipsy('show');
497
					input.addClass('error');
498
				}
499
			}
500
		});
501
		input.on('keyup', function(event){
502
			if (event.keyCode === 27) {
503
				// cancel by putting in an empty value
504
				$(this).val('');
505
				$(this).blur();
506
				event.preventDefault();
507
			}
508
			if (event.keyCode === 13) {
509
				$(this).blur();
510
				event.preventDefault();
511
			}
512
		});
513
		input.focus();
514
		input.selectRange(0, name.length);
515
	},
516
517
	renameDocument: function(name) {
518
		var url = OC.generateUrl('apps/documents/ajax/documents/rename/{file_id}', {file_id: documentsMain.fileId});
519
		$.post(
520
			url,
521
			{ name : name },
522
			function(result) {
523
				if (result && result.status === 'error') {
524
					if (result.message){
525
						documentsMain.IU.notify(result.message);
526
					}
527
					return;
528
				}
529
				documentsMain.fileName = name;
530
				$('title').text(documentsMain.UI.mainTitle + '| ' + name);
531
				$('#document-title').text(name);
532
			}
533
		);
534
	},
535
536
	onEditorShutdown : function (message){
537
			OC.Notification.show(message);
538
539
			$(window).off('beforeunload');
540
			$(window).off('unload');
541
			if (documentsMain.isEditorMode){
542
				documentsMain.isEditorMode = false;
543
				parent.location.hash = "";
544
			} else {
545
				setTimeout(OC.Notification.hide, 7000);
546
			}
547
			documentsMain.prepareGrid();
548
			try {
549
				documentsMain.webodfEditorInstance.endEditing();
550
				documentsMain.webodfEditorInstance.closeSession(function() {
551
					documentsMain.webodfEditorInstance.destroy(documentsMain.UI.hideEditor);
552
				});
553
			} catch (e){
554
				documentsMain.UI.hideEditor();
555
			}
556
			
557
			documentsMain.show();
558
			$('footer,nav').show();
559
	},
560
		
561
562
	onClose: function() {
563
		if (!documentsMain.isEditorMode){
564
			return;
565
		}
566
		documentsMain.isEditorMode = false;
567
		$(window).off('beforeunload');
568
		$(window).off('unload');
569
		parent.location.hash = "";
570
571
		documentsMain.webodfEditorInstance.endEditing();
572
		documentsMain.webodfEditorInstance.closeSession(function() {
573
			$('footer,nav').show();
574
			documentsMain.webodfEditorInstance.destroy(documentsMain.UI.hideEditor);
575
576
			var url = '';
577
			if (documentsMain.isGuest){
578
				url = OC.generateUrl('apps/documents/ajax/user/disconnectGuest', {});
579
			} else {
580
				url = OC.generateUrl('apps/documents/ajax/user/disconnect', {});
581
			}
582
			
583
			$.post(url, {
584
				memberId : documentsMain.memberId,
585
				esId: documentsMain.esId
586
			});
587
			
588
			documentsMain.show();
589
		});
590
	},
591
	
592
	onTerminate: function(){
593
		var url = '';
594
		if (documentsMain.isGuest){
595
			url = OC.generateUrl('apps/documents/ajax/user/disconnectGuest/{member_id}', {member_id: documentsMain.memberId});
596
		} else {
597
			url = OC.generateUrl('apps/documents/ajax/user/disconnect/{member_id}', {member_id: documentsMain.memberId});
598
		}
599
		$.ajax({
600
				type: "POST",
601
				url: url,
602
				data: {esId: documentsMain.esId},
603
				dataType: "json",
604
				async: false // Should be sync to complete before the page is closed
605
		});
606
607
		
608
		documentsMain.webodfEditorInstance.endEditing();
609
		documentsMain.webodfEditorInstance.closeSession(function() {
610
			if (documentsMain.isGuest){
611
				$('footer,nav').show();
612
			}
613
			documentsMain.webodfEditorInstance.destroy(documentsMain.UI.hideEditor);
614
		});
615
	},
616
	
617
	show: function(){
618
		if (documentsMain.isGuest){
619
			return;
620
		}
621
		documentsMain.UI.showProgress(t('documents', 'Loading documents...'));
622
		documentsMain.docs.documentGrid('render');
623
		documentsMain.UI.hideProgress();
624
	}
625
};
626
627
628
//web odf bootstrap code. Added here to reduce number of requests
629
/*globals navigator,dojoConfig */
630
var usedLocale = "C";
631
632
if (navigator && navigator.language && navigator.language.match(/^(de)/)) {
633
	usedLocale = navigator.language.substr(0,2);
634
}
635
636
dojoConfig = {
0 ignored issues
show
Read only.
Loading history...
637
	locale: usedLocale,
638
	paths: {
639
		"webodf/editor": OC.appswebroots.documents + "/js/3rdparty/webodf/editor",
640
		"dijit": OC.appswebroots.documents + "/js/3rdparty/resources/dijit",
641
		"dojox": OC.appswebroots.documents + "/js/3rdparty/resources/dojox",
642
		"dojo": OC.appswebroots.documents + "/js/3rdparty/resources/dojo",
643
		"resources": OC.appswebroots.documents + "/js/3rdparty/resources",
644
		"owncloud" : OC.appswebroots.documents + "/js"
645
	}
646
};
647
648
649
//init
650
var Files = Files || {
651
	// FIXME: copy/pasted from Files.isFileNameValid, needs refactor into core
652
	isFileNameValid:function (name) {
653
		if (name === '.') {
654
			throw t('files', '\'.\' is an invalid file name.');
655
		} else if (name.length === 0) {
656
			throw t('files', 'File name cannot be empty.');
657
		}
658
659
		// check for invalid characters
660
		var invalid_characters = ['\\', '/', '<', '>', ':', '"', '|', '?', '*'];
661
		for (var i = 0; i < invalid_characters.length; i++) {
662
			if (name.indexOf(invalid_characters[i]) !== -1) {
663
				throw t('files', "Invalid name, '\\', '/', '<', '>', ':', '\"', '|', '?' and '*' are not allowed.");
664
			}
665
		}
666
		return true;
667
	},
668
	
669
	updateStorageStatistics: function(){}
670
},
671
FileList = FileList || {};
672
673
FileList.getCurrentDirectory = function(){
674
	return $('#dir').val() || '/';
675
};
676
677
FileList.setViewerMode = function(){
678
};
679
FileList.findFile = function(fileName){
680
	fullPath = escapeHTML(FileList.getCurrentDirectory + '/' + fileName);
681
	return !!$('.documentslist .document:not(.template,.progress) a[original-title="' + fullPath + '"]').length
682
}
683
684
$(document).ready(function() {
685
	documentsMain.docs = $('.documentslist').documentGrid();
686
	documentsMain.overlay = $('<div id="documents-overlay" class="icon-loading"></div><div id="documents-overlay-below" class="icon-loading-dark"></div>').documentOverlay();
687
	
688
	$('li.document a').tipsy({fade: true, live: true});
689
	
690
	$('.documentslist').on('click', 'li:not(.add-document)', function(event) {
691
		event.preventDefault();
692
693
		if (documentsMain.isEditorMode){
694
			return;
695
		}
696
		
697
		documentsMain.prepareSession();
698
		if ($(this).attr('data-id')){
699
			documentsMain.joinSession($(this).attr('data-id'));
700
		}
701
	});
702
	
703
	$('.add-document').on('click', '.add', documentsMain.onCreate);
704
705
	OC.Upload._isReceivedSharedFile = function () {
706
		return false;
707
	}
708
709
	var file_upload_start = $('#file_upload_start');
710
	if (typeof supportAjaxUploadWithProgress !== 'undefined' && supportAjaxUploadWithProgress()) {
711
		file_upload_start.on('fileuploadstart', function(e, data) {
712
			$('#upload').addClass('icon-loading');
713
			$('.add-document .upload').css({opacity:0});
714
		});
715
	}
716
	file_upload_start.on('fileuploaddone', function(){
717
		$('#upload').removeClass('icon-loading');
718
		$('.add-document .upload').css({opacity:0.7});
719
		documentsMain.show();
720
	});
721
	OC.addStyle('documents', '3rdparty/webodf/wodotexteditor');
722
	OC.addStyle('documents', '/3rdparty/webodf/wodocollabpane');
723
724
	OC.addScript('documents', '3rdparty/webodf/dojo-amalgamation', documentsMain.onStartup);
725
});
726