7e1f0b8f70b45d4b54376b3cb17520eac1dbff91
[Packages/TYPO3.CMS.git] / typo3 / js / browse_links.js
1 /**
2 * This file is part of the TYPO3 CMS project.
3 *
4 * It is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License, either version 2
6 * of the License, or any later version.
7 *
8 * For the full copyright and license information, please read the
9 * LICENSE.txt file that was distributed with this source code.
10 *
11 * The TYPO3 project - inspiring people to share!
12 */
13
14 var BrowseLinks = {
15 elements: {},
16 addElements: function(elements) {
17 BrowseLinks.elements = $H(BrowseLinks.elements).merge(elements).toObject();
18 },
19 focusOpenerAndClose: function(close) {
20 if (close) {
21 parent.window.opener.focus();
22 parent.close();
23 }
24 }
25 };
26
27 // when selecting one or multiple files, this action is called
28 BrowseLinks.File = {
29 insertElement: function(index, close) {
30 var result = false;
31 if (typeof BrowseLinks.elements[index] !== undefined) {
32 var element = BrowseLinks.elements[index];
33
34 // insertElement takes the following parameters
35 // table, uid, type, filename,fp,filetype,imagefile,action, close
36 result = insertElement(
37 element.table,
38 element.uid,
39 element.type,
40 element.fileName,
41 element.filePath,
42 element.fileExt,
43 element.fileIcon,
44 '',
45 close
46 );
47 }
48 return result;
49 },
50 insertElementMultiple: function(list) {
51 var uidList = [];
52 list.each(function(index) {
53 if (typeof BrowseLinks.elements[index] !== undefined) {
54 var element = BrowseLinks.elements[index];
55 uidList.push(element.uid);
56 }
57 });
58 insertMultiple('sys_file', uidList);
59 return true;
60 }
61
62 };
63
64 BrowseLinks.Selector = {
65 element: 'typo3-fileList',
66 toggle: function(element) {
67 var items = this.getItems(element);
68 if (items.length) {
69 items.each(function(item) {
70 item.checked = (item.checked ? null : 'checked');
71 });
72 }
73 },
74 handle: function(element) {
75 var items = this.getItems(element);
76 var selectedItems = [];
77 if (items.length) {
78 items.each(function(item) {
79 if (item.checked && item.name) {
80 selectedItems.push(item.name);
81 }
82 });
83 if (selectedItems.length == 1) {
84 BrowseLinks.File.insertElement(selectedItems[0]);
85 } else {
86 BrowseLinks.File.insertElementMultiple(selectedItems);
87 }
88 BrowseLinks.focusOpenerAndClose(true);
89 }
90 },
91 getParentElement: function(element) {
92 element = $(element);
93 return (element ? element : $(this.element));
94 },
95 getItems: function(element) {
96 element = this.getParentElement(element);
97 return Element.select(element, '.typo3-bulk-item');
98 }
99 };