* This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. */ namespace Test; use OC_Util; /** * Class UtilTest * * @package Test * @group DB */ class UtilTest extends \Test\TestCase { public function testGetVersion() { $version = \OCP\Util::getVersion(); $this->assertTrue(is_array($version)); foreach ($version as $num) { $this->assertTrue(is_int($num)); } } public function testGetVersionString() { $version = \OC_Util::getVersionString(); $this->assertTrue(is_string($version)); } public function testGetEditionString() { $edition = \OC_Util::getEditionString(); $this->assertTrue(is_string($edition)); } public function testSanitizeHTML() { $badArray = [ 'While it is unusual to pass an array', 'this function actually supports it.', 'And therefore there needs to be a for it!', [ 'And It Even May Nest', ], ]; $goodArray = [ 'While it is unusual to pass an array', 'this function actually <blink>supports</blink> it.', 'And therefore there needs to be a <script>alert("Unit"+'test')</script> for it!', [ 'And It Even May <strong>Nest</strong>' ], ]; $result = OC_Util::sanitizeHTML($badArray); $this->assertEquals($goodArray, $result); $badString = ''; $result = OC_Util::sanitizeHTML($badString); $this->assertEquals('<img onload="alert(1)" />', $result); $badString = ""; $result = OC_Util::sanitizeHTML($badString); $this->assertEquals('<script>alert('Hacked!');</script>', $result); $goodString = 'This is a good string without HTML.'; $result = OC_Util::sanitizeHTML($goodString); $this->assertEquals('This is a good string without HTML.', $result); } public function testEncodePath() { $component = '/§#@test%&^ä/-child'; $result = OC_Util::encodePath($component); $this->assertEquals("/%C2%A7%23%40test%25%26%5E%C3%A4/-child", $result); } public function testIsNonUTF8Locale() { // OC_Util::isNonUTF8Locale() assumes escapeshellcmd('§') returns '' with non-UTF-8 locale. $locale = setlocale(LC_CTYPE, 0); setlocale(LC_CTYPE, 'C'); $this->assertEquals('', escapeshellcmd('§')); $this->assertEquals('\'\'', escapeshellarg('§')); setlocale(LC_CTYPE, 'C.UTF-8'); $this->assertEquals('§', escapeshellcmd('§')); $this->assertEquals('\'§\'', escapeshellarg('§')); setlocale(LC_CTYPE, $locale); } public function testFileInfoLoaded() { $expected = function_exists('finfo_open'); $this->assertEquals($expected, \OC_Util::fileInfoLoaded()); } public function testGetDefaultEmailAddress() { $email = \OCP\Util::getDefaultEmailAddress("no-reply"); $this->assertEquals('no-reply@localhost', $email); } public function testGetDefaultEmailAddressFromConfig() { $config = \OC::$server->getConfig(); $config->setSystemValue('mail_domain', 'example.com'); $email = \OCP\Util::getDefaultEmailAddress("no-reply"); $this->assertEquals('no-reply@example.com', $email); $config->deleteSystemValue('mail_domain'); } public function testGetConfiguredEmailAddressFromConfig() { $config = \OC::$server->getConfig(); $config->setSystemValue('mail_domain', 'example.com'); $config->setSystemValue('mail_from_address', 'owncloud'); $email = \OCP\Util::getDefaultEmailAddress("no-reply"); $this->assertEquals('owncloud@example.com', $email); $config->deleteSystemValue('mail_domain'); $config->deleteSystemValue('mail_from_address'); } public function testGetInstanceIdGeneratesValidId() { \OC::$server->getConfig()->deleteSystemValue('instanceid'); $instanceId = OC_Util::getInstanceId(); $this->assertStringStartsWith('oc', $instanceId); $matchesRegex = preg_match('/^[a-z0-9]+$/', $instanceId); $this->assertSame(1, $matchesRegex); } /** * @dataProvider filenameValidationProvider */ public function testFilenameValidation($file, $valid) { // private API $this->assertEquals($valid, \OC_Util::isValidFileName($file)); // public API $this->assertEquals($valid, \OCP\Util::isValidFileName($file)); } public function filenameValidationProvider() { return [ // valid names ['boringname', true], ['something.with.extension', true], ['now with spaces', true], ['.a', true], ['..a', true], ['.dotfile', true], ['single\'quote', true], [' spaces before', true], ['spaces after ', true], ['allowed chars including the crazy ones $%&_-^@!,()[]{}=;#', true], ['汉字也能用', true], ['und Ümläüte sind auch willkommen', true], // disallowed names ['', false], [' ', false], ['.', false], ['..', false], ['back\\slash', false], ['sl/ash', false], ['ltgt', true], ['col:on', true], ['double"quote', true], ['pi|pe', true], ['dont?ask?questions?', true], ['super*star', true], ['new\nline', false], // better disallow these to avoid unexpected trimming to have side effects [' ..', false], ['.. ', false], ['. ', false], [' .', false], // part files not allowed ['.part', false], ['notallowed.part', false], ['neither.filepart', false], // part in the middle is ok ['super movie part one.mkv', true], ['super.movie.part.mkv', true], ]; } /** * Test needUpgrade() when the core version is increased */ public function testNeedUpgradeCore() { $config = \OC::$server->getConfig(); $oldConfigVersion = $config->getSystemValue('version', '0.0.0'); $oldSessionVersion = \OC::$server->getSession()->get('OC_Version'); $this->assertFalse(\OCP\Util::needUpgrade()); $config->setSystemValue('version', '7.0.0.0'); \OC::$server->getSession()->set('OC_Version', [7, 0, 0, 1]); self::invokePrivate(new \OCP\Util, 'needUpgradeCache', [null]); $this->assertTrue(\OCP\Util::needUpgrade()); $config->setSystemValue('version', $oldConfigVersion); \OC::$server->getSession()->set('OC_Version', $oldSessionVersion); self::invokePrivate(new \OCP\Util, 'needUpgradeCache', [null]); $this->assertFalse(\OCP\Util::needUpgrade()); } public function testCheckDataDirectoryValidity() { $dataDir = \OC::$server->getTempManager()->getTemporaryFolder(); touch($dataDir . '/.ocdata'); $errors = \OC_Util::checkDataDirectoryValidity($dataDir); $this->assertEmpty($errors); \OCP\Files::rmdirr($dataDir); $dataDir = \OC::$server->getTempManager()->getTemporaryFolder(); // no touch $errors = \OC_Util::checkDataDirectoryValidity($dataDir); $this->assertNotEmpty($errors); \OCP\Files::rmdirr($dataDir); $errors = \OC_Util::checkDataDirectoryValidity('relative/path'); $this->assertNotEmpty($errors); } protected function setUp(): void { parent::setUp(); \OC_Util::$scripts = []; \OC_Util::$styles = []; self::invokePrivate(\OCP\Util::class, 'scripts', [[]]); self::invokePrivate(\OCP\Util::class, 'scriptDeps', [[]]); } protected function tearDown(): void { parent::tearDown(); \OC_Util::$scripts = []; \OC_Util::$styles = []; self::invokePrivate(\OCP\Util::class, 'scripts', [[]]); self::invokePrivate(\OCP\Util::class, 'scriptDeps', [[]]); } public function testAddScript() { \OCP\Util::addScript('first', 'myFirstJSFile'); \OCP\Util::addScript('core', 'myFancyJSFile1'); \OCP\Util::addScript('files', 'myFancyJSFile2', 'core'); \OCP\Util::addScript('myApp5', 'myApp5JSFile', 'myApp2'); \OCP\Util::addScript('myApp', 'myFancyJSFile3'); \OCP\Util::addScript('core', 'myFancyJSFile4'); // after itself \OCP\Util::addScript('core', 'myFancyJSFile5', 'core'); // add duplicate \OCP\Util::addScript('core', 'myFancyJSFile1'); // dependency chain \OCP\Util::addScript('myApp4', 'myApp4JSFile', 'myApp3'); \OCP\Util::addScript('myApp3', 'myApp3JSFile', 'myApp2'); \OCP\Util::addScript('myApp2', 'myApp2JSFile', 'myApp'); \OCP\Util::addScript('core', 'common'); \OCP\Util::addScript('core', 'main'); $scripts = \OCP\Util::getScripts(); // Core should appear first $this->assertEquals( 0, array_search('core/js/common', $scripts, true) ); $this->assertEquals( 1, array_search('core/js/main', $scripts, true) ); $this->assertEquals( 2, array_search('core/js/myFancyJSFile1', $scripts, true) ); $this->assertEquals( 3, array_search('core/js/myFancyJSFile4', $scripts, true) ); // Dependencies should appear before their children $this->assertLessThan( array_search('files/js/myFancyJSFile2', $scripts, true), array_search('core/js/myFancyJSFile3', $scripts, true) ); $this->assertLessThan( array_search('myApp2/js/myApp2JSFile', $scripts, true), array_search('myApp/js/myFancyJSFile3', $scripts, true) ); $this->assertLessThan( array_search('myApp3/js/myApp3JSFile', $scripts, true), array_search('myApp2/js/myApp2JSFile', $scripts, true) ); $this->assertLessThan( array_search('myApp4/js/myApp4JSFile', $scripts, true), array_search('myApp3/js/myApp3JSFile', $scripts, true) ); $this->assertLessThan( array_search('myApp5/js/myApp5JSFile', $scripts, true), array_search('myApp2/js/myApp2JSFile', $scripts, true) ); // No duplicates $this->assertEquals( $scripts, array_unique($scripts) ); // All scripts still there $scripts = [ "core/js/common", "core/js/main", "core/js/myFancyJSFile1", "core/js/myFancyJSFile4", "core/js/myFancyJSFile5", "first/l10n/en", "first/js/myFirstJSFile", "files/l10n/en", "files/js/myFancyJSFile2", "myApp/l10n/en", "myApp/js/myFancyJSFile3", "myApp2/l10n/en", "myApp2/js/myApp2JSFile", "myApp5/l10n/en", "myApp5/js/myApp5JSFile", "myApp3/l10n/en", "myApp3/js/myApp3JSFile", "myApp4/l10n/en", "myApp4/js/myApp4JSFile", ]; foreach ($scripts as $script) { $this->assertContains($script, $scripts); } } public function testAddScriptCircularDependency() { \OCP\Util::addScript('circular', 'file1', 'dependency'); \OCP\Util::addScript('dependency', 'file2', 'circular'); $scripts = \OCP\Util::getScripts(); $this->assertContains('circular/js/file1', $scripts); $this->assertContains('dependency/js/file2', $scripts); } public function testAddVendorScript() { \OC_Util::addVendorScript('core', 'myFancyJSFile1'); \OC_Util::addVendorScript('myApp', 'myFancyJSFile2'); \OC_Util::addVendorScript('core', 'myFancyJSFile0', true); \OC_Util::addVendorScript('core', 'myFancyJSFile10', true); // add duplicate \OC_Util::addVendorScript('core', 'myFancyJSFile1'); $this->assertEquals([ 'core/vendor/myFancyJSFile10', 'core/vendor/myFancyJSFile0', 'core/vendor/myFancyJSFile1', 'myApp/vendor/myFancyJSFile2', ], \OC_Util::$scripts); $this->assertEquals([], \OC_Util::$styles); } public function testAddTranslations() { \OC_Util::addTranslations('appId', 'de'); $this->assertEquals([ 'appId/l10n/de' ], \OC_Util::$scripts); $this->assertEquals([], \OC_Util::$styles); } public function testAddStyle() { \OC_Util::addStyle('core', 'myFancyCSSFile1'); \OC_Util::addStyle('myApp', 'myFancyCSSFile2'); \OC_Util::addStyle('core', 'myFancyCSSFile0', true); \OC_Util::addStyle('core', 'myFancyCSSFile10', true); // add duplicate \OC_Util::addStyle('core', 'myFancyCSSFile1'); $this->assertEquals([], \OC_Util::$scripts); $this->assertEquals([ 'core/css/myFancyCSSFile10', 'core/css/myFancyCSSFile0', 'core/css/myFancyCSSFile1', 'myApp/css/myFancyCSSFile2', ], \OC_Util::$styles); } public function testAddVendorStyle() { \OC_Util::addVendorStyle('core', 'myFancyCSSFile1'); \OC_Util::addVendorStyle('myApp', 'myFancyCSSFile2'); \OC_Util::addVendorStyle('core', 'myFancyCSSFile0', true); \OC_Util::addVendorStyle('core', 'myFancyCSSFile10', true); // add duplicate \OC_Util::addVendorStyle('core', 'myFancyCSSFile1'); $this->assertEquals([], \OC_Util::$scripts); $this->assertEquals([ 'core/vendor/myFancyCSSFile10', 'core/vendor/myFancyCSSFile0', 'core/vendor/myFancyCSSFile1', 'myApp/vendor/myFancyCSSFile2', ], \OC_Util::$styles); } public function testShortenMultibyteString() { $this->assertEquals('Short nuff', \OCP\Util::shortenMultibyteString('Short nuff', 255)); $this->assertEquals('ABC', \OCP\Util::shortenMultibyteString('ABCDEF', 3)); // each of the characters is 12 bytes $this->assertEquals('🙈', \OCP\Util::shortenMultibyteString('🙈🙊🙉', 16, 2)); } } rl Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
aboutsummaryrefslogtreecommitdiffstats
path: root/core/js/oc-dialogs.js
blob: 0fa41696a164906557f8250de5349608cbfdc0dd (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
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/**
 * ownCloud
 *
 * @author Bartek Przybylski
 * @copyright 2012 Bartek Przybylski bartek@alefzero.eu
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

/**
 * this class to ease the usage of jquery dialogs
 */
OCdialogs = {
	/**
	* displays alert dialog
	* @param text content of dialog
	* @param title dialog title
	* @param callback which will be triggered when user press OK
	*/
	alert:function(text, title, callback, modal) {
		var content = '<p><span class="ui-icon ui-icon-alert"></span>'+text+'</p>';
		OCdialogs.message(content, title, OCdialogs.ALERT_DIALOG, OCdialogs.OK_BUTTON, callback, modal);
	},
	/**
	* displays info dialog
	* @param text content of dialog
	* @param title dialog title
	* @param callback which will be triggered when user press OK
	*/
	info:function(text, title, callback, modal) {
		var content = '<p><span class="ui-icon ui-icon-info"></span>'+text+'</p>';
		OCdialogs.message(content, title, OCdialogs.ALERT_DIALOG, OCdialogs.OK_BUTTON, callback, modal);
	},
	/**
	* displays confirmation dialog
	* @param text content of dialog
	* @param title dialog title
	* @param callback which will be triggered when user press YES or NO (true or false would be passed to callback respectively)
	*/
	confirm:function(text, title, callback, modal) {
		var content = '<p><span class="ui-icon ui-icon-notice"></span>'+text+'</p>';
		OCdialogs.message(content, title, OCdialogs.ALERT_DIALOG, OCdialogs.YES_NO_BUTTONS, callback, modal);
	},
	/**
	* prompt for user input
	* @param text content of dialog
	* @param title dialog title
	* @param callback which will be triggered when user press OK (input text will be passed to callback)
	*/
	prompt:function(text, title, default_value, callback, modal) {
		var content = '<p><span class="ui-icon ui-icon-pencil"></span>'+text+':<br/><input type="text" id="oc-dialog-prompt-input" value="'+default_value+'" style="width:90%"></p>';
		OCdialogs.message(content, title, OCdialogs.PROMPT_DIALOG, OCdialogs.OK_CANCEL_BUTTONS, callback, modal);
	},
	/**
	* prompt user for input with custom form
	* fields should be passed in following format: [{text:'prompt text', name:'return name', type:'input type', value: 'dafault value'},...]
	* @param fields to display 
	* @param title dialog title
	* @param callback which will be triggered when user press OK (user answers will be passed to callback in following format: [{name:'return name', value: 'user value'},...])
	*/
	form:function(fields, title, callback, modal) {
		var content = '<table>';
		for (var a in fields) {
			content += '<tr><td>'+fields[a].text+'</td><td>';
			var type=fields[a].type;
			if (type == 'text' || type == 'checkbox' || type == 'password') {
				content += '<input type="'+type+'" name="'+fields[a].name+'"';
				if (type == 'checkbox') {
					if (fields[a].value != undefined && fields[a].value == true) {
						content += ' checked="checked">';
					} else {
						content += '>';
					}
				} else if (type == 'text' || type == 'password' && fields[a].value) {
					content += ' value="'+fields[a].value+'">';
				}
			} else if (type == 'select') {
				content += '<select name="'+fields[a].name+'"';
				if (fields[a].value != undefined) {
					content += ' value="'+fields[a].value+'"';
				}
				content += '>';
				for (var o in fields[a].options) {
					content += '<option value="'+fields[a].options[o].value+'">'+fields[a].options[o].text+'</option>';
				}
				content += '</select>';
			}
			content += '</td></tr>';
		}
		content += '</table>';
		OCdialogs.message(content, title, OCdialogs.FORM_DIALOG, OCdialogs.OK_CANCEL_BUTTONS, callback, modal);
	},
	filepicker:function(title, callback, multiselect, mimetype_filter, modal) {
		var c_name = 'oc-dialog-'+OCdialogs.dialogs_counter+'-content';
		var c_id = '#'+c_name;
		var d = '<div id="'+c_name+'" title="'+title+'"><select id="dirtree"><option value="0">'+OC.currentUser+'</option></select><div id="filelist"></div><div class="filepicker_loader"><img src="'+OC.filePath('gallery','img','loading.gif')+'"></div></div>';
		if (!modal) modal = false; // Huh..?
		if (!multiselect) multiselect = false;
		$('body').append(d);
		$(c_id + ' #dirtree').focus(function() {
			var t = $(this); 
			t.data('oldval',  t.val())
		}).change({dcid: c_id}, OC.dialogs.handleTreeListSelect);
		$(c_id).ready(function(){
			$.getJSON(OC.filePath('files', 'ajax', 'rawlist.php'), {mimetype: mimetype_filter} ,function(r) {
				OC.dialogs.fillFilePicker(r, c_id, callback)
			});
		}).data('multiselect', multiselect).data('mimetype',mimetype_filter);
		// build buttons
		var b = [{
			text: t('dialogs', 'Choose'), 
			click: function(){
				if (callback != undefined) {
					var p;
					if ($(c_id).data('multiselect') == true) {
						p = [];
						$(c_id+' .filepicker_element_selected #filename').each(function(i, elem) {
							p.push(($(c_id).data('path')?$(c_id).data('path'):'')+'/'+$(elem).text());
						});
					} else {
						var p = $(c_id).data('path');
						if (p == undefined) p = '';
						p = p+'/'+$(c_id+' .filepicker_element_selected #filename').text()
					}
					callback(p);
					$(c_id).dialog('close');
				}
			}
		},
		{
			text: t('dialogs', 'Cancel'), 
			click: function(){$(c_id).dialog('close'); }}
		];
		$(c_id).dialog({width: ((4*$('body').width())/9), height: 400, modal: modal, buttons: b});
		OCdialogs.dialogs_counter++;
	},
	// guts, dont use, dont touch
	message:function(content, title, dialog_type, buttons, callback, modal) {
		var c_name = 'oc-dialog-'+OCdialogs.dialogs_counter+'-content';
		var c_id = '#'+c_name;
		var d = '<div id="'+c_name+'" title="'+title+'">'+content+'</div>';
		if (modal == undefined) modal = false;
		$('body').append(d);
		var b = [];
		switch (buttons) {
			case OCdialogs.YES_NO_BUTTONS:
				b[1] = {text: t('dialogs', 'No'), click: function(){ if (callback != undefined) callback(false); $(c_id).dialog('close'); }};
				b[0] = {text: t('dialogs', 'Yes'), click: function(){ if (callback != undefined) callback(true); $(c_id).dialog('close');}};
			break;
			case OCdialogs.OK_CANCEL_BUTTONS:
				b[1] = {text: t('dialogs', 'Cancel'), click: function(){$(c_id).dialog('close'); }};
			case OCdialogs.OK_BUTTON: // fallthrough
				var f;
				switch(dialog_type) {
					case OCdialogs.ALERT_DIALOG:
						f = function(){$(c_id).dialog('close'); if(callback) callback();};
					break;
					case OCdialogs.PROMPT_DIALOG:
						f = function(){OCdialogs.prompt_ok_handler(callback, c_id)};
					break;
					case OCdialogs.FORM_DIALOG:
						f = function(){OCdialogs.form_ok_handler(callback, c_id)};
					break;
				}
				b[0] = {text: t('dialogs', 'Ok'), click: f};
			break;
		}
		var possible_height = ($('tr', d).size()+1)*30;
		$(c_id).dialog({width: 4*$(document).width()/9, height: possible_height + 120, modal: modal, buttons: b});
		OCdialogs.dialogs_counter++;
	},
	// dialogs buttons types
	YES_NO_BUTTONS: 70,
	OK_BUTTONS: 71,
	OK_CANCEL_BUTTONS: 72,
	// dialogs types
	ALERT_DIALOG: 80,
	INFO_DIALOG: 81,
	PROMPT_DIALOG: 82,
	FORM_DIALOG: 83,
	dialogs_counter: 0,
	determineValue: function(element) {
		switch ($(element).attr('type')) {
			case 'checkbox': return element.checked;
		}
		return $(element).val();
	},
	prompt_ok_handler: function(callback, c_id) { $(c_id).dialog('close'); if (callback != undefined) callback($(c_id + " input#oc-dialog-prompt-input").val()); },
	form_ok_handler: function(callback, c_id) {
		if (callback != undefined) {
			var r = [];
			var c = 0;
			$(c_id + ' input, '+c_id+' select').each(function(i, elem) {
				r[c] = {name: $(elem).attr('name'), value: OCdialogs.determineValue(elem)};
				c++;
			});
			$(c_id).dialog('close');
			callback(r);
		} else {
			$(c_id).dialog('close');
		}
	},
	fillFilePicker:function(r, dialog_content_id) {
		var entry_template = '<div onclick="javascript:OC.dialogs.handlePickerClick(this, \'*ENTRYNAME*\',\''+dialog_content_id+'\')" data="*ENTRYTYPE*"><img src="*MIMETYPEICON*" style="margin-right:1em;"><span id="filename">*NAME*</span><div style="float:right;margin-right:1em;">*LASTMODDATE*</div></div>';
		var names = '';
		for (var a in r.data) {
			names += entry_template.replace('*LASTMODDATE*', OC.mtime2date(r.data[a].mtime)).replace('*NAME*', r.data[a].name).replace('*MIMETYPEICON*', r.data[a].mimetype_icon).replace('*ENTRYNAME*', r.data[a].name).replace('*ENTRYTYPE*', r.data[a].type);
		}
		$(dialog_content_id + ' #filelist').html(names);
		$(dialog_content_id + ' .filepicker_loader').css('visibility', 'hidden');
	},
	handleTreeListSelect:function(event) {
		var newval = parseInt($(this).val());
		var oldval = parseInt($(this).data('oldval'));
		while (newval != oldval && oldval > 0) {
			$('option:last', this).remove();
			$('option:last', this).attr('selected','selected');
			oldval--;
		}
		var skip_first = true;
		var path = '';
		$(this).children().each(function(i, element) { 
			if (skip_first) {
				skip_first = false; 
				return; 
			}
			path += '/'+$(element).text();
		});
		$(event.data.dcid).data('path', path);
		$(event.data.dcid + ' .filepicker_loader').css('visibility', 'visible');
		$.getJSON(OC.filePath('files', 'ajax', 'rawlist.php'), {dir: path, mimetype: $(event.data.dcid).data('mimetype')}, function(r){OC.dialogs.fillFilePicker(r, event.data.dcid)});
	},
	// this function is in early development state, please dont use it unlsess you know what you are doing
	handlePickerClick:function(element, name, dcid) {
		var p = $(dcid).data('path');
		if (p == undefined) p = '';
		p = p+'/'+name;
		if ($(element).attr('data') == 'file'){
			if ($(dcid).data('multiselect') != true) {
				$(dcid+' .filepicker_element_selected').removeClass('filepicker_element_selected');
			}
			$(element).toggleClass('filepicker_element_selected');
			return;
		}
		$(dcid).data('path', p);
		$(dcid + ' #dirtree option:last').removeAttr('selected');
		var newval = parseInt($(dcid + ' #dirtree option:last').val())+1;
		$(dcid + ' #dirtree').append('<option selected="selected" value="'+newval+'">'+name+'</option>');
		$(dcid + ' .filepicker_loader').css('visibility', 'visible');
		$.getJSON(OC.filePath('files', 'ajax', 'rawlist.php'), {dir: p, mimetype: $(dcid).data('mimetype')}, function(r){OC.dialogs.fillFilePicker(r, dcid)});
	}
};