Got stuff working!

This commit is contained in:
Raoul Snyman 2010-06-03 15:32:07 +02:00
parent 000469e16f
commit 11579fc604
4 changed files with 36 additions and 9 deletions

View File

@ -42,12 +42,12 @@ class MediaController(BaseController):
def __before__(self):
BaseController.__before__(self)
self._add_javascript('ScribeEngine.Media.js')
self._add_javascript(u'ScribeEngine.Media.js')
def _get_directories(self, parent=None, tree=[]):
old_root = parent
dirname = os.path.split(parent)[1]
node = {'data': dirname, u'state': u'open'}
node = {u'data': dirname, u'state': u'open'}
for root, dirs, files in os.walk(parent):
if root != old_root:
break
@ -75,6 +75,13 @@ class MediaController(BaseController):
#return pformat(c.directories, indent=2)
return render(u'/media/index.mako')
@jsonify
def get_files(self):
path = request.GET.get(u'path', u'').split(u',')
dirpath = os.path.join(config[u'paths.media'], *path)
#log.debug(dirpath)
return self._get_files(dirpath)
@jsonify
def create_directory(self):
"""

View File

@ -18,17 +18,37 @@
*****************************************************************************/
ScribeEngine.Namespace.create("ScribeEngine.Media", {
new_directory: function ()
newDirectory: function ()
{
var dirname = prompt("New Directory:", "directory");
},
get_files: function (event, data)
getFiles: function (event)
{
alert(data.inst.get_path(ScribeEngine.Events.getElement(event)));
var tree = jQuery.jstree._focused();
var path = tree.get_path(ScribeEngine.Events.getElement(event));
$.getJSON(
'/media/get-files',
{"path": path.toString()},
function (data, textStatus) {
$("#file-list > ul").html("");
$.each(data, function () {
var filename = this;
if (filename.length > 15)
{
filename = filename.substr(0, 12) + "...";
}
$("#file-list > ul").append(
$("<li>")
.append($("<div>").attr("class", "file").html("&nbsp;"))
.append($("<div>").attr("class", "caption").attr("title", filename).text(filename))
);
});
}
);
}
});
ScribeEngine.Events.load(function () {
ScribeEngine.Events.click("#new-directory", ScribeEngine.Media.new_directory);
ScribeEngine.Events.click("#new-directory", ScribeEngine.Media.newDirectory);
ScribeEngine.Events.click("#file-select", window.close);
});

View File

@ -133,7 +133,7 @@ ScribeEngine.Namespace.create("ScribeEngine.Widgets", {
},
fileBrowser: function (field_name, url, type, win)
{
alert("Field_Name: " + field_name + "\nURL: " + url + "\nType: " + type + "\nWin: " + win); // debug/testing
//alert("Field_Name: " + field_name + "\nURL: " + url + "\nType: " + type + "\nWin: " + win); // debug/testing
var cmsURL = window.location.toString(); // script URL - use an absolute path!
if (cmsURL.indexOf("?") < 0)
{
@ -180,7 +180,7 @@ ScribeEngine.Namespace.create("ScribeEngine.Widgets", {
tree: function (selector, tree_data, onselect)
{
$(selector)
.bind("set_focus.jstree", onselect)
.bind("click.jstree", onselect)
.jstree({
plugins: ["themes", "json_data"],
json_data: {data: tree_data},

View File

@ -43,7 +43,7 @@
<input type="button" id="file-select" value="Select"/>
</div>
<script type="text/javascript">
ScribeEngine.Widgets.tree("#directory-tree", ${c.directories | n}, ScribeEngine.Media.get_files);
ScribeEngine.Widgets.tree("#directory-tree", ${c.directories | n}, ScribeEngine.Media.getFiles);
</script>
</body>
</html>