From e551dcab79263410e05a36f955512f6885f741c2 Mon Sep 17 00:00:00 2001 From: Sanj Date: Sun, 10 Apr 2011 01:15:31 +0530 Subject: [PATCH] finalize boxes models - js lists etc --- itf/boxes/models.py | 15 ++++++---- itf/static/js/itf/box_types.js | 6 ++-- itf/static/js/itf/boxes.js | 55 ++++++++++++++++++++++++---------- 3 files changed, 54 insertions(+), 22 deletions(-) diff --git a/itf/boxes/models.py b/itf/boxes/models.py index 87e0c9e..2f30f20 100644 --- a/itf/boxes/models.py +++ b/itf/boxes/models.py @@ -12,7 +12,9 @@ class ModelExtra(models.Model): friendly_name = models.CharField(max_length=255, blank=True, null=True) friendly_name_plural = models.CharField(max_length=255, blank=True, null=True) sort_options = models.ManyToManyField("ModelSort", blank=True, null=True) - + has_comments = models.BooleanField(default=False) + + def __unicode__(self): return "%d: %s" % (self.id, self.friendly_name) @@ -21,22 +23,24 @@ class ModelExtra(models.Model): 'id': self.id, 'module': self.model.model_class()._meta.app_label, 'model': self.model.model, + 'has_comments': self.has_comments, # 'info': self.info, 'friendly_name': self.friendly_name, 'friendly_name_plural': self.friendly_name_plural, 'fk_filters': self.model.model_class().fk_filters, 'fts_fields': self.model.model_class().fts_fields, - 'sort_options': map(lambda x: {'key': x.key, 'operator': x.operator}, self.sort_options.all()) + 'sort_options': map(lambda x: {'key': x.key, 'operator': x.operator, 'text': x.text}, self.sort_options.all()) } class ModelSort(models.Model): - operator = models.CharField(max_length=64) - key = models.CharField(max_length=512) + operator = models.CharField(max_length=4) + key = models.CharField(max_length=64) + text = models.CharField(max_length=256) def __unicode__(self): - return "%s: %s" % (self.operator, self.key,) + return "%s%s: %s" % (self.operator, self.key, self.text,) @@ -157,6 +161,7 @@ Abstract base-class for boxes. class Box(ItfModel): title = models.CharField(max_length=256) extra_buttons = models.ManyToManyField("ExtraButton", blank=True, null=True) + logo = models.ImageField(upload_to="upload/box_logos/", blank=True, null=True) class Meta: abstract = True diff --git a/itf/static/js/itf/box_types.js b/itf/static/js/itf/box_types.js index a7e0488..5f1f9bf 100644 --- a/itf/static/js/itf/box_types.js +++ b/itf/static/js/itf/box_types.js @@ -2,7 +2,8 @@ ItfBoxTypes = { 'StaticBox': { 'buttons': [], 'render': function(data) { - return new Ox.Element().html(data.html); + var id = data.itfId + "Content"; + return new Ox.Element({'id': id}).html(data.html); } }, @@ -20,7 +21,7 @@ ItfBoxTypes = { } ], 'render': function(data) { - var id = data.itfId + "ModelsContainer"; + var id = data.itfId + "Content"; var that = new Ox.Element({ 'id': id }); @@ -28,6 +29,7 @@ ItfBoxTypes = { var $list = new Ox.ItfList(model, data); that.empty(); that.append($list); + that.$list = $list; } that.updateView(data.default_model); return that; diff --git a/itf/static/js/itf/boxes.js b/itf/static/js/itf/boxes.js index 35831c0..bb5c744 100644 --- a/itf/static/js/itf/boxes.js +++ b/itf/static/js/itf/boxes.js @@ -91,14 +91,20 @@ Ox.ItfButton = function(buttonData, boxData) { } -Ox.ItfList = function(modelData, boxData, size) { +Ox.ItfList = function(modelData, boxData, size, self) { + var self = self || {}; var size = size || 256; var id = "ModelList" + modelData.id; var listOptions = { 'id': id, - 'width': size, //FIXME: don't hardcode width - get these figures on init and set globals or something + 'model': modelData.model, + 'module': modelData.module, + 'boxId': boxData.itfId, + 'width': size, + 'scrollbarVisible': true, + 'hasComments': modelData.has_comments || false, 'items': function(data, callback) { - app.api.find(getFindParams(modelData)); + app.api.find(getFindParams(modelData, boxData)); }, 'max': 1, 'columns': [ @@ -118,17 +124,36 @@ Ox.ItfList = function(modelData, boxData, size) { ], 'sort': modelData.sort_options } - var that = new Ox.List( + var that = new Ox.TextList(listOptions, self); + that.bindEvent("select", function(e, data) { + if (data.ids.length === 0) { + app.$ui.previewBox.$content.html(''); + return; + } +// app.$ui[options.boxId].$loading.start(); +// debugger; + app.api.preview({ + model: listOptions.model, + module: listOptions.module, + id: data.ids[0] + }, function(response) { +// alert(JSON.stringify(response.data.data)); +// app.$ui[options.boxId].$loading.stop(); +// var data = add_newlines(response['data']); + var html = $.tmpl(response['template'], response['data']); + app.$ui.previewBox.$content.html(html); + }); + }); + + return that; + + function getFindParams(modelData, boxData) { + var box = app.ui[boxData.itfId]; + return { + 'search': '', + 'model': modelData.model, + 'module': modelData.module + } + } } -/* -ItfBoxes.StaticBox = function(boxData) { - var self = {}; - var that = new Ox.Element( - -} - -ItfBoxes.ModelsBox = function(boxData) { - -} -*/