diff --git a/scribeengine/controllers/media.py b/scribeengine/controllers/media.py index 38a431a..405002c 100644 --- a/scribeengine/controllers/media.py +++ b/scribeengine/controllers/media.py @@ -22,25 +22,51 @@ import os import logging +from pprint import pprint, pformat from scribeengine.lib.base import * from scribeengine.lib import utils from scribeengine.model import MediaType, File from scribeengine.model.meta import Session +try: + import json +except ImportError: + import simplejson as json + log = logging.getLogger(__name__) class MediaController(BaseController): - def _get_directories(self, parent=None, tree={}): - if not parent: - parent = config[u'paths.media'] - for dirpath in os.listdir(parent): - if os.path.isdir(dirpath): - tree[os.path.abspath(dirpath)] = {u'path': dirpath, u'children': {}} - self._get_directories(os.path.abspath(dirpath), - tree[os.path.abspath(dirpath)][u'children']) + def __before__(self): + BaseController.__before__(self) + self._add_javascript('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', u'children': []} + for root, dirs, files in os.walk(parent): + if root != old_root: + break + for dirpath in dirs: + full_dirpath = os.path.join(root, dirpath) + self._get_directories(full_dirpath, node[u'children']) + tree.append(node) + + def _get_files(self, dirpath): + for root, dirs, files in os.walk(os.path.abspath(dirpath)): + return files + break def index(self): - c.directories = self._get_directories() - return render(u'/media/index.html') + self._add_javascript(u'jtree/jquery.tree.js') + directories = [] + path = os.path.join(config[u'paths.media'], u'user%s' % c.current_user.id) + if not os.path.exists(path): + os.makedirs(path) + self._get_directories(path, directories) + c.directories = json.dumps(directories) + c.files = self._get_files(path) + #return pformat(c.directories, indent=2) + return render(u'/media/index.mako') diff --git a/scribeengine/lib/base.py b/scribeengine/lib/base.py index 9f09ff2..af41c28 100644 --- a/scribeengine/lib/base.py +++ b/scribeengine/lib/base.py @@ -244,7 +244,7 @@ def authenticate(permission=None): session[u'redirect_url'] = request.environ[u'PATH_INFO'] session.save() h.flash.set_message(u'You need to be logged in to do that.', u'error') - h.redirect_to('/admin/login') + h.redirect_to('/account/login') return decorator(validate) diff --git a/scribeengine/public/scripts/ScribeEngine.Media.js b/scribeengine/public/scripts/ScribeEngine.Media.js new file mode 100644 index 0000000..aec6672 --- /dev/null +++ b/scribeengine/public/scripts/ScribeEngine.Media.js @@ -0,0 +1,39 @@ +/***************************************************************************** + * ScribeEngine - Open Source Blog Software * + * ------------------------------------------------------------------------- * + * Copyright (c) 2010 Raoul Snyman * + * ------------------------------------------------------------------------- * + * This program is free software; you can redistribute it and/or modify it * + * under the terms of the GNU General Public License as published by the * + * Free Software Foundation; version 2 of the License. * + * * + * This program 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 General * + * Public License for more details. * + * * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * + *****************************************************************************/ + +ScribeEngine.Namespace.create("ScribeEngine.Media", { + new_directory: function () + { + var dirname = prompt("New Directory:", "directory"); + }, + get_files: function (node, tree) + { + tree_string = ""; + while (node) + { + alert($(tree.get_node(node)).text()); + node = tree.parent(node); + } + } +}); + +ScribeEngine.Events.load(function () { + ScribeEngine.Events.click("#new-directory", ScribeEngine.Media.new_directory); + ScribeEngine.Events.click("#file-select", window.close); +}); diff --git a/scribeengine/public/scripts/ScribeEngine.Post.js b/scribeengine/public/scripts/ScribeEngine.Post.js index 9380b3a..45da5b6 100644 --- a/scribeengine/public/scripts/ScribeEngine.Post.js +++ b/scribeengine/public/scripts/ScribeEngine.Post.js @@ -23,15 +23,5 @@ ScribeEngine.Namespace.create("ScribeEngine.Post", { ScribeEngine.Events.load(function () { ScribeEngine.Widgets.tagEditor("#post-tags"); - $('textarea').tinymce({ - script_url: "/scripts/tinymce/tiny_mce.js", - theme: "advanced", - dialog_type: "modal", - theme_advanced_toolbar_location: "top", - theme_advanced_toolbar_align: "left", - theme_advanced_statusbar_location: "bottom", - theme_advanced_resizing: true, - theme_advanced_resize_horizontal: false - }); - + ScribeEngine.Widgets.tinymce("textarea"); }); diff --git a/scribeengine/public/scripts/ScribeEngine.js b/scribeengine/public/scripts/ScribeEngine.js index 4e1e3c9..c55f727 100644 --- a/scribeengine/public/scripts/ScribeEngine.js +++ b/scribeengine/public/scripts/ScribeEngine.js @@ -119,18 +119,81 @@ ScribeEngine.Namespace.create("ScribeEngine.Widgets", { /** * Adds a datepicker to an element. */ - datepicker: function (selector) - { - $(selector).datepicker({showButtonPanel: true, dateFormat: "dd/mm/yy"}); - }, - tagEditor: function (selector) - { - $(selector).tagEditor({completeOnBlur: true, initialParse: true}); - }, - elastic: function (selector) - { - $(selector).elastic(); - } + datepicker: function (selector) + { + $(selector).datepicker({showButtonPanel: true, dateFormat: "dd/mm/yy"}); + }, + tagEditor: function (selector) + { + $(selector).tagEditor({completeOnBlur: true, initialParse: true}); + }, + elastic: function (selector) + { + $(selector).elastic(); + }, + fileBrowser: function (field_name, url, type, win) + { + 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) + { + //add the type as the only query parameter + cmsURL = cmsURL + "?type=" + type; + } + else + { + //add the type as an additional query parameter + // (PHP session ID is now included if there is one at all) + cmsURL = cmsURL + "&type=" + type; + } + tinyMCE.activeEditor.windowManager.open( + { + file: "/media", + title: "Media Library", + width: 600, // Your dimensions may differ - toy around with them! + height: 400, + resizable: "yes", + inline: "yes", // This parameter only has an effect if you use the inlinepopups plugin! + close_previous: "no" + }, + { + window: win, + input: field_name + } + ); + return false; + }, + tinymce: function (selector) + { + $(selector).tinymce({ + script_url: "/scripts/tinymce/tiny_mce.js", + theme: "advanced", + dialog_type: "modal", + theme_advanced_toolbar_location: "top", + theme_advanced_toolbar_align: "left", + theme_advanced_statusbar_location: "bottom", + theme_advanced_resizing: true, + theme_advanced_resize_horizontal: false, + file_browser_callback: "ScribeEngine.Widgets.fileBrowser" + }); + }, + tree: function (selector, data, onselect) + { + $(selector).tree({ + data: + { + type: "json", + opts: + { + static: data + } + }, + callback: + { + onselect: onselect + } + }); + } }); ScribeEngine.Namespace.create("ScribeEngine.General", { diff --git a/scribeengine/public/scripts/jtree/themes/default/style.css b/scribeengine/public/scripts/jtree/themes/default/style.css index fab2676..8f58ce6 100644 --- a/scribeengine/public/scripts/jtree/themes/default/style.css +++ b/scribeengine/public/scripts/jtree/themes/default/style.css @@ -1,3 +1,4 @@ +.tree-default { font-family: "Lucida Grande", "Trebuchet MS", "Lucida Sans", "Arial", sans-serif; font-size: 80%; } /* LOCKED */ .tree-default .locked li a { color:gray; } /* DOTS */ diff --git a/scribeengine/templates/media/index.mako b/scribeengine/templates/media/index.mako new file mode 100644 index 0000000..ad302f1 --- /dev/null +++ b/scribeengine/templates/media/index.mako @@ -0,0 +1,48 @@ + + +
+ +