From 554e4ef02efedea57b0e17629fced71b5894a735 Mon Sep 17 00:00:00 2001 From: sanj Date: Thu, 13 Jan 2011 15:38:10 +0530 Subject: [PATCH] sorting --- itf/app/models.py | 6 +- itf/static/css/itf.css | 4 ++ itf/static/js/itf/itf.js | 70 +++++++++++++++++-- .../bestpractices/BestPractice/preview.html | 1 + 4 files changed, 74 insertions(+), 7 deletions(-) diff --git a/itf/app/models.py b/itf/app/models.py index 978b074..fe00856 100644 --- a/itf/app/models.py +++ b/itf/app/models.py @@ -91,7 +91,11 @@ class ItfModel(models.Model): sort = options['sort'] if sort != []: for s in sort: - sort = s['operator'] + s['key'] + if s['operator'] == '-': + operator = '-' + else: + operator = '' + sort = operator + s['key'] qset = qset.order_by(sort) r0 = options['range'][0] r1 = options['range'][1] diff --git a/itf/static/css/itf.css b/itf/static/css/itf.css index c2610b4..aba220b 100644 --- a/itf/static/css/itf.css +++ b/itf/static/css/itf.css @@ -6,3 +6,7 @@ font-weight: bold; font-size: 1.2em; } + +.itfPreviewTitle { + font-weight: bold; +} diff --git a/itf/static/js/itf/itf.js b/itf/static/js/itf/itf.js index dc55f05..4f702e2 100644 --- a/itf/static/js/itf/itf.js +++ b/itf/static/js/itf/itf.js @@ -709,7 +709,8 @@ Ox.ItfBox = function(options, self) { var self = self || {}; var that = new Ox.Element(options, self) .defaults({ - 'title': '' + 'title': '', + 'extraButtons': [] }) .options(options); var title = self.options.title; @@ -742,9 +743,19 @@ Ox.ItfBox = function(options, self) { }); + that.search = function(word) { + $search.options("value", word); + $search.triggerEvent("submit"); + } + var $buttons = new Ox.Element().appendTo($title).css({'position': 'absolute', 'top': '1px', 'right': '16px'}); that.$loading = new Ox.LoadingIcon().appendTo($buttons); + + var $additionalButtons = self.options.extraButtons; + if ($additionalButtons.length > 0) { + $additionalButtons.appendTo($buttons); + } var $infoBtn = new Ox.Button({ id: options.id + "InfoBtn", style: 'symbold', @@ -799,10 +810,61 @@ Ox.ItfBox = function(options, self) { id: options.id + 'Menu', element: $menuBtn, items: [ - {id: 'Test', title: 'Menu Item 1'}, + { + id: 'SortBy', + title: 'Sort By', + items: [ + { + 'group': 'sortGroup', + 'min': 1, + 'max': 1, + items: [ + {'id': 'sort_added_descending', title: 'Added (Descending)', checked: true}, + {'id': 'sort_added_ascending', title: 'Added (Ascending)'}, + {'id': 'sort_title_ascending', title: 'Title (Ascending)'}, + {'id': 'sort_title_descending', title: 'Title (Descending)'}, + ] + } + ] + }, {id: 'Test2', title: 'Menu Item 2'} ] + }) + .bindEvent("change", function(e, data) { + if (data.id === 'sortGroup') { + var checked = data.checked[0]; + var checkedId = checked.id; + var checkedField = checkedId.split("_")[1]; + var operator = checkedId.split("_")[2] == "ascending" ? "+" : "-"; + $list.sortList(checkedField, operator); + } }); + +// var $menu = new Ox.Menu({ +// id: options.id + 'Menu', +// element: $menuBtn, +// items: [ +// { +// 'group': 'sortGroup', +// 'min': 1, +// 'max': 1, +// items: [ +// {'id': 'sortTitleAscending', title: 'Title (Ascending)', checked: true}, +// {'id': 'sortTitleDescending', title: 'Title (Descending)'}, +// {'id': 'sortTitleAscendingFoo', title: 'Title (Ascending)'}, +// {'id': 'sortTitleDescendingFoo', title: 'Title (Descending)'}, +// ] +// } +// ] +// }, +// {id: 'Test2', title: 'Menu Item 2'} +// ] +// }) +// .bindEvent("change", function() { +// alert("foo"); +// }); + +// $menuBtn.bindEvent("click", function() { $menu.showMenu(); @@ -860,10 +922,6 @@ Ox.ItfBox = function(options, self) { { key: 'added', operator: '-' - }, - { - key: 'id', - operator: '-' } ] }); diff --git a/itf/templates/bestpractices/BestPractice/preview.html b/itf/templates/bestpractices/BestPractice/preview.html index aa0bf98..99538bf 100644 --- a/itf/templates/bestpractices/BestPractice/preview.html +++ b/itf/templates/bestpractices/BestPractice/preview.html @@ -1,4 +1,5 @@
+ ${title}

Category: ${category}

Quick Howto: ${quick_howto}