From 3c8b724f2b30281c49da87b9ca2ae5a2f508670c Mon Sep 17 00:00:00 2001 From: Sanj Date: Sat, 9 Apr 2011 01:45:51 +0530 Subject: [PATCH] added boxes.js --- itf/api/views.py | 2 + itf/boxes/models.py | 7 ++- itf/boxes/views.py | 17 ++++--- itf/static/js/itf/app.js | 2 +- itf/static/js/itf/box_types.js | 0 itf/static/js/itf/boxes.js | 83 ++++++++++++++++++++++++++++++++++ itf/static/js/itf/construct.js | 18 +++++--- 7 files changed, 115 insertions(+), 14 deletions(-) create mode 100644 itf/static/js/itf/box_types.js create mode 100644 itf/static/js/itf/boxes.js diff --git a/itf/api/views.py b/itf/api/views.py index 95709de..32ceb5e 100644 --- a/itf/api/views.py +++ b/itf/api/views.py @@ -29,6 +29,7 @@ import ox from actions import actions from user.models import get_user_json from django.views.decorators.csrf import csrf_exempt +from boxes.views import _getPageData @csrf_exempt def api(request): @@ -106,6 +107,7 @@ def init(request): 'name': 'India Theatre Forum' } } + response['data']['page'] = _getPageData(request) return render_to_json_response(response) actions.register(init) diff --git a/itf/boxes/models.py b/itf/boxes/models.py index a956a5b..a3074c8 100644 --- a/itf/boxes/models.py +++ b/itf/boxes/models.py @@ -223,4 +223,9 @@ class Panel(models.Model): 'title': self.title, 'boxes': map(lambda x: x.get_dict(), self.boxes.all()) } - + +''' +class Page(models.Model): + class Meta: + abstract = True +''' diff --git a/itf/boxes/views.py b/itf/boxes/views.py index 1f0f52e..81217cb 100644 --- a/itf/boxes/views.py +++ b/itf/boxes/views.py @@ -4,7 +4,7 @@ import ox from ox.django.decorators import login_required_json from ox.django.shortcuts import render_to_json_response, get_object_or_404_json, json_response from models import Panel - +import json def getPage(request): @@ -18,6 +18,15 @@ def getPage(request): default_model etc ''' +# data = json.loads(request.POST['data']) + panels = _getPageData(request) + response = json_response({}) + response['data'] = panels + response['status'] = {'code': 200} + return render_to_json_response(response) +actions.register(getPage) + +def _getPageData(request): data = json.loads(request.POST['data']) displayedPanels = Panel.objects.filter(enabled=True).filter(displayed=True) hiddenPanels = Panel.objects.filter(enabled=True).filter(displayed=False) @@ -28,8 +37,4 @@ def getPage(request): panels['hidden'] = [] for h in hiddenPanels: panels['hidden'].append(h.get_dict()) - response = json_response({}) - response['data'] = panels - response['status'] = {'code': 200} - return render_to_json_response(response) -actions.register(getPage) + return panels diff --git a/itf/static/js/itf/app.js b/itf/static/js/itf/app.js index eccdbd7..cc3572e 100644 --- a/itf/static/js/itf/app.js +++ b/itf/static/js/itf/app.js @@ -30,7 +30,7 @@ app.launch(function(data) { app.$ui[v] = app.construct[v](); }); */ - var wrapper = app.construct.wrapper(); + var wrapper = app.construct.wrapper(data.page); app.$body.css({'opacity': 0}); //FIXME: user handling should be cleaner? if (data.user.level != 'guest') { diff --git a/itf/static/js/itf/box_types.js b/itf/static/js/itf/box_types.js new file mode 100644 index 0000000..e69de29 diff --git a/itf/static/js/itf/boxes.js b/itf/static/js/itf/boxes.js new file mode 100644 index 0000000..831545a --- /dev/null +++ b/itf/static/js/itf/boxes.js @@ -0,0 +1,83 @@ +/* + +*/ + +Ox.ItfPage = function(page, parentPanel) { + var panelItems = []; + for (var i=0; i < page.panels.displayed.length; i++) { + var t = page.panels.displayed[i]; + var displayed = true; + var panel = new Ox.ItfPanel(t, displayed); + panelItems.push(panel); + } + var hiddenPanel = new Ox.ItfHiddenPanelContainer(); + for (var j=0; j < page.panels.hidden.length; j++) { + var t = page.panels.hidden[j]; + var displayed = false; + var panel = new Ox.ItfPanel(t, displayed); + hiddenPanel.addPanel(panel); + } + var that = app.ui['ItfPage'] = new Ox.SplitPanel({ + orientation: 'vertical', + id: 'ItfPage', + elements: panelItems + }); + return that; +} + +Ox.ItfPanel = function(panelData, displayed) { + var items = []; + var id = panelData.title; + for (var i=0; i < panelData.boxes.length; i++) { + var t = panelData.boxes[i]; + var box = new Ox.ItfBox(t); + items.push(box); + } + var that = new Ox.SplitPanel({ + orientation: 'horizontal', + id: id, + elements: items + }); + that.displayed = displayed; +}; + +Ox.HiddenPanelContainer = function() { + +}; + +Ox.ItfBox = function(boxData) { + var options = { + 'title': boxData.title, + } + var that = new Ox.Element(options, self); + var $titlebar = new Ox.Bar({ + orientation: 'horizontal', + size: '24 + }).appendTo(that); + var $title = new Ox.Element() + .addClass('OxTitle') + .html(title) + .appendTo($titlebar); + var $buttons = new Ox.Element().appendTo($title).css({'position': 'absolute', 'top': '1px', 'right': '1px'}); + var boxButtons = Ox.merge(ItfBoxTypes[boxData.type].buttons, boxData.extra_buttons); + for (var i=0; i