1 |
85ad3d82
|
Assos Assos
|
|
2 |
|
|
(function($) {
|
3 |
|
|
|
4 |
|
|
imce.hooks.load.push(function () {
|
5 |
|
|
if (!(imce.mkdirForm = imce.el('imce-mkdir-form'))) return;
|
6 |
|
|
var form = $(imce.mkdirForm);
|
7 |
|
|
|
8 |
|
|
form.find('fieldset').each(function() {
|
9 |
|
|
this.removeChild(this.firstChild);
|
10 |
|
|
$(this).after(this.childNodes);
|
11 |
|
|
}).remove();
|
12 |
|
|
imce.mkdirOps = {};
|
13 |
|
|
form.find('input:submit').each(function(i) {
|
14 |
|
|
var dop = this.id.substr(5);
|
15 |
|
|
$(imce.mkdirOps[dop] = this).click(function() {imce.dopSubmit(dop); return false;});
|
16 |
|
|
});
|
17 |
|
|
imce.opAdd({name: 'mngdir', title: Drupal.t('Directory'), content: form});
|
18 |
|
|
imce.mkdirRefreshOps();
|
19 |
|
|
|
20 |
|
|
imce.hooks.navigate.push(function (data, olddir, cached) {
|
21 |
|
|
imce.mkdirRefreshOps();
|
22 |
|
|
});
|
23 |
|
|
|
24 |
|
|
imce.mkdirSubSelector();
|
25 |
|
|
});
|
26 |
|
|
|
27 |
|
|
|
28 |
|
|
imce.mkdirRefreshOps = function () {
|
29 |
|
|
var perm, func = 'opDisable';
|
30 |
|
|
for (var op in imce.mkdirOps) {
|
31 |
|
|
if (perm = imce.conf.perm[op]) func = 'opEnable';
|
32 |
|
|
$(imce.mkdirOps[op])[perm ? 'show' : 'hide']();
|
33 |
|
|
}
|
34 |
|
|
imce[func]('mngdir');
|
35 |
|
|
};
|
36 |
|
|
|
37 |
|
|
|
38 |
|
|
imce.mkdirSuccess = function (response) {
|
39 |
|
|
if (response.data) {
|
40 |
|
|
if (response.data.diradded) imce.dirSubdirs(imce.conf.dir, response.data.diradded);
|
41 |
|
|
if (response.data.dirremoved) imce.rmdirSubdirs(imce.conf.dir, response.data.dirremoved);
|
42 |
|
|
imce.mkdirSSBuild && imce.mkdirSSBuild();
|
43 |
|
|
}
|
44 |
|
|
if (response.messages) imce.resMsgs(response.messages);
|
45 |
|
|
};
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
imce.dopValidate = function(dop) {
|
49 |
|
|
var dirname = imce.el('edit-dirname').value, dir = imce.conf.dir, branch = imce.tree[dir], newdir = (dir == '.' ? '' : dir +'/') + dirname;
|
50 |
|
|
switch (dop) {
|
51 |
|
|
case 'mkdir':
|
52 |
|
|
if (imce.conf.mkdirnum && branch.ul && branch.ul.childNodes.length >= imce.conf.mkdirnum) {
|
53 |
|
|
return imce.setMessage(Drupal.t('You are not alllowed to create more than %num directories.', {'%num': imce.conf.mkdirnum}), 'error');
|
54 |
|
|
}
|
55 |
|
|
if (dirname.search(/^[A-Za-z0-9_\-]+$/) == -1) {
|
56 |
|
|
return imce.setMessage(Drupal.t('%dirname is not a valid directory name. It should contain only alphanumeric characters, hyphen and underscore.', {'%dirname': dirname}), 'error');
|
57 |
|
|
}
|
58 |
|
|
if (imce.tree[newdir]) {
|
59 |
|
|
return imce.setMessage(Drupal.t('Subdirectory %dir already exists.', {'%dir': dirname}), 'error');
|
60 |
|
|
}
|
61 |
|
|
return true;
|
62 |
|
|
case 'rmdir':
|
63 |
|
|
if (!imce.tree[newdir]) {
|
64 |
|
|
return imce.setMessage(Drupal.t('Subdirectory %dir does not exist.', {'%dir': dirname}), 'error');
|
65 |
|
|
}
|
66 |
|
|
return confirm(Drupal.t('Are you sure want to delete this subdirectory with all directories and files in it?'));
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
var func = dop +'DopValidate';
|
70 |
|
|
if (imce[func]) return imce[func](dop);
|
71 |
|
|
return true;
|
72 |
|
|
};
|
73 |
|
|
|
74 |
|
|
|
75 |
|
|
imce.dopSubmit = function(dop) {
|
76 |
|
|
if (!imce.dopValidate(dop)) return false;
|
77 |
|
|
var func = dop +'DopSubmit';
|
78 |
|
|
if (imce[func]) return imce[func](dop);
|
79 |
|
|
imce.fopLoading(dop, true);
|
80 |
|
|
$.ajax(imce.dopSettings(dop));
|
81 |
|
|
};
|
82 |
|
|
|
83 |
|
|
|
84 |
|
|
imce.dopSettings = function (dop) {
|
85 |
|
|
return {url: imce.ajaxURL(dop), type: 'POST', dataType: 'json', success: imce.mkdirSuccess, complete: function (response) {imce.fopLoading(dop, false); imce.mkdirForm.reset();}, data: $(imce.mkdirForm).serialize()};
|
86 |
|
|
};
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
imce.rmdirSubdirs = function(dir, subdirs) {
|
90 |
|
|
var branch = imce.tree[dir];
|
91 |
|
|
if (branch.ul && subdirs && subdirs.length) {
|
92 |
|
|
var prefix = dir == '.' ? '' : dir +'/';
|
93 |
|
|
for (var i in subdirs) {
|
94 |
|
|
var subdir = prefix + subdirs[i];
|
95 |
|
|
if (imce.tree[subdir]) {
|
96 |
|
|
$(imce.tree[subdir].li).remove();
|
97 |
|
|
delete imce.tree[subdir];
|
98 |
|
|
if (imce.cache[subdir]) {
|
99 |
|
|
$(imce.cache[subdir].files).remove();
|
100 |
|
|
delete imce.cache[subdir];
|
101 |
|
|
}
|
102 |
|
|
}
|
103 |
|
|
}
|
104 |
|
|
if (!$('li', branch.ul).size()) {
|
105 |
|
|
$(branch.ul).remove();
|
106 |
|
|
$(branch.li).removeClass('expanded').addClass('leaf');
|
107 |
|
|
delete branch.ul;
|
108 |
|
|
}
|
109 |
|
|
}
|
110 |
|
|
};
|
111 |
|
|
|
112 |
|
|
|
113 |
|
|
imce.mkdirSubSelector = function () {
|
114 |
|
|
var ie7 = $('html').is('.ie-7');
|
115 |
|
|
var $inp = $(imce.el('edit-dirname'));
|
116 |
|
|
|
117 |
|
|
var $subsel = $(imce.newEl('div')).attr({id: 'subdir-selector'}).css('display', 'none').appendTo(document.body);
|
118 |
|
|
|
119 |
|
|
var $button = $(imce.newEl('a')).attr({id: 'subdir-selector-button', href: '#'}).click(function() {
|
120 |
|
|
var offset = $inp.offset();
|
121 |
|
|
offset.top += $inp.outerHeight();
|
122 |
|
|
$subsel.css(offset).slideDown('normal', itemfocus);
|
123 |
|
|
$(document).mouseup(hide);
|
124 |
|
|
ie7 && $subsel.css('width', 'auto') && $subsel.width($subsel[0].offsetWidth);
|
125 |
|
|
return false;
|
126 |
|
|
}).insertAfter($inp[0]);
|
127 |
|
|
|
128 |
|
|
var itemfocus = function(){$subsel.children().eq(0).focus()};
|
129 |
|
|
|
130 |
|
|
var hide = function(e){
|
131 |
|
|
if (e.target != $subsel[0]) {
|
132 |
|
|
$subsel.hide();
|
133 |
|
|
$(document).unbind('mouseup', hide);
|
134 |
|
|
}
|
135 |
|
|
};
|
136 |
|
|
|
137 |
|
|
var newdir = imce.el('edit-newdirname');
|
138 |
|
|
newdir && $(newdir).css('marginRight', parseFloat($(newdir).css('marginRight')) + parseFloat($button.css('width')));
|
139 |
|
|
|
140 |
|
|
var subclick = function() {
|
141 |
|
|
$inp.val(this.title.substr(this.title.lastIndexOf('/') + 1)).focus();
|
142 |
|
|
$subsel.hide();
|
143 |
|
|
return false;
|
144 |
|
|
};
|
145 |
|
|
|
146 |
|
|
var subproc = function(i, a) {
|
147 |
|
|
$(imce.newEl('a')).attr({href: '#', title: a.title}).html(a.innerHTML).click(subclick).appendTo($subsel[0]);
|
148 |
|
|
};
|
149 |
|
|
|
150 |
|
|
var navhook = imce.mkdirSSBuild = function() {
|
151 |
|
|
var branch = imce.tree[imce.conf.dir];
|
152 |
|
|
$subsel.empty();
|
153 |
|
|
if (branch.ul && branch.ul.firstChild) {
|
154 |
|
|
$(branch.ul).children('li').children('a').each(subproc);
|
155 |
|
|
$button.css('visibility', 'visible');
|
156 |
|
|
}
|
157 |
|
|
else {
|
158 |
|
|
$button.css('visibility', 'hidden');
|
159 |
|
|
}
|
160 |
|
|
};
|
161 |
|
|
imce.hooks.navigate.push(navhook);
|
162 |
|
|
navhook();
|
163 |
|
|
};
|
164 |
|
|
|
165 |
|
|
})(jQuery); |