summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2013-05-25 06:38:32 -0400
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2013-05-25 06:38:32 -0400
commit88c817318430e8ab6557c78215d4f3917f7d1521 (patch)
treedac35d935a47757531566205ed88693b9466bb38
parent2bd878338f92e28a0b474feac0797af3d8e17fca (diff)
downloadaskbot-88c817318430e8ab6557c78215d4f3917f7d1521.tar.gz
askbot-88c817318430e8ab6557c78215d4f3917f7d1521.tar.bz2
askbot-88c817318430e8ab6557c78215d4f3917f7d1521.zip
fixed some general js coding issues in the Groups dropdown code
-rw-r--r--askbot/media/js/utils.js140
-rw-r--r--askbot/templates/meta/bottom_scripts.html3
2 files changed, 63 insertions, 80 deletions
diff --git a/askbot/media/js/utils.js b/askbot/media/js/utils.js
index 0380e6fe..b13c21a3 100644
--- a/askbot/media/js/utils.js
+++ b/askbot/media/js/utils.js
@@ -2011,8 +2011,18 @@ SelectBox.prototype.createDom = function() {
var GroupDropdown = function(groups){
WrappedElement.call(this);
this._group_list = groups;
+};
+inherits(GroupDropdown, WrappedElement);
+
+GroupDropdown.prototype.createDom = function(){
+ this._element = this.makeElement('ul');
+ this._element.attr('class', 'dropdown-menu');
+ this._element.attr('id', 'groups-dropdown');
+ this._element.attr('role', 'menu');
+ this._element.attr('aria-labelledby', 'navGroups');
+
this._input_box = new TippedInput();
- this._input_box.setInstruction('group name');
+ this._input_box.setInstruction(gettext('group name'));
this._input_box.createDom();
this._input_box_element = this._input_box.getElement();
this._input_box_element.attr('class', 'group-name');
@@ -2021,60 +2031,36 @@ var GroupDropdown = function(groups){
this._add_link.attr('href', '#');
this._add_link.attr('class', 'group-name');
this._add_link.text(gettext('add new group'));
-};
-inherits(GroupDropdown, WrappedElement);
-GroupDropdown.prototype.createDom = function(){
- this._element = this.makeElement('ul');
- this._element.attr('class', 'dropdown-menu');
- this._element.attr('id', 'groups-dropdown');
- this._element.attr('role', 'menu');
- this._element.attr('aria-labelledby', 'navGroups');
-
- for (i=0; i<this._group_list.length; i++){
- li_element = this.makeElement('li');
- a_element = this.makeElement('a');
- a_element.text(this._group_list[i].name);
- a_element.attr('href', this._group_list[i].link);
- a_element.attr('class', 'group-name');
- li_element.append(a_element);
- this._element.append(li_element);
- }
-};
-
-GroupDropdown.prototype.decorate = function(element){
- this._element = element;
- this._element.attr('class', 'dropdown-menu');
- this._element.attr('id', 'groups-dropdown');
- this._element.attr('role', 'menu');
- this._element.attr('aria-labelledby', 'navGroups');
-
- for (i=0; i<this._group_list.length; i++){
- li_element = this.makeElement('li');
- a_element = this.makeElement('a');
- a_element.text(this._group_list[i].name);
- a_element.attr('href', this._group_list[i].link);
- a_element.attr('class', 'group-name');
- li_element.append(a_element);
- this._element.append(li_element);
- }
+ for (var i=0; i<this._group_list.length; i++){
+ var li = this.makeElement('li');
+ var a = this.makeElement('a');
+ a.text(this._group_list[i].name);
+ a.attr('href', this._group_list[i].link);
+ a.attr('class', 'group-name');
+ li.append(a);
+ this._element.append(li);
+ }
+ if (askbot['data']['userIsAdmin']) {
+ this.enableAddGroups();
+ }
};
GroupDropdown.prototype.insertGroup = function(group_name, url){
- var new_group_li = this.makeElement('li');
- new_group_a = this.makeElement('a');
- new_group_a.attr('href', url);
- new_group_a.attr('class', 'group-name');
- new_group_a.text(group_name);
- new_group_li.append(new_group_a);
- links_array = this._element.find('a')
- for (i=1; i < links_array.length; i++){
+ var li = this.makeElement('li');
+ var a = this.makeElement('a');
+ a.attr('href', url);
+ a.attr('class', 'group-name');
+ a.text(group_name);
+ li.append(a);
+ var links_array = this._element.find('a')
+ for (var i=1; i < links_array.length; i++){
var listedName = links_array[i].text;
var cleanedListedName = listedName.toLowerCase();
var cleanedNewName = group_name.toLowerCase()
- if (listedName < newName) {
- if (i == links_array.length - 1){
- new_group_li.insertAfter(this._element.find('li')[i-1])
+ if (listedName < cleanedNewName) {
+ if (i === links_array.length - 1){
+ li.insertAfter(this._element.find('li')[i-1])
break;
} else {
continue;
@@ -2087,49 +2073,49 @@ GroupDropdown.prototype.insertGroup = function(group_name, url){
notify.show(message);
return;
} else {
- new_group_li.insertAfter(this._element.find('li')[i-1])
+ li.insertAfter(this._element.find('li')[i-1])
break;
}
}
};
GroupDropdown.prototype._add_group_handler = function(group_name){
- var group_name = this._input_box_element.val();
- self = this;
- if (!group_name){
- return;
- }
+ var group_name = this._input_box_element.val();
+ var me = this;
+ if (!group_name){
+ return;
+ }
- $.ajax({
- type: 'POST',
- url: askbot['urls']['add_group'],
- data: {group: group_name},
- success: function(data){
- if (data.success){
- self.insertGroup(data.group_name, data.url);
- self._input_box_element.hide();
- self._add_link.show();
- return true;
- } else{
- return false;
- }
- },
- error: function(){console.log('error');}
- });
+ $.ajax({
+ type: 'POST',
+ url: askbot['urls']['add_group'],
+ data: {group: group_name},
+ success: function(data){
+ if (data.success){
+ me.insertGroup(data.group_name, data.url);
+ me._input_box_element.hide();
+ me._add_link.show();
+ return true;
+ } else{
+ return false;
+ }
+ },
+ error: function(){console.log('error');}
+ });
};
GroupDropdown.prototype.enableAddGroups = function(){
var self = this;
this._add_link.click(function(){
- self._add_link.hide();
- self._input_box_element.show();
- self._input_box_element.focus();
+ self._add_link.hide();
+ self._input_box_element.show();
+ self._input_box_element.focus();
});
this._input_box_element.keydown(function(event){
- if (event.which == 13 || event.keyCode==13){
- self._add_group_handler();
- self._input_box_element.val('');
- }
+ if (event.which == 13 || event.keyCode==13){
+ self._add_group_handler();
+ self._input_box_element.val('');
+ }
});
var divider = this.makeElement('li');
diff --git a/askbot/templates/meta/bottom_scripts.html b/askbot/templates/meta/bottom_scripts.html
index eec4256d..e707b29f 100644
--- a/askbot/templates/meta/bottom_scripts.html
+++ b/askbot/templates/meta/bottom_scripts.html
@@ -97,9 +97,6 @@
askbot['urls']['add_group'] = "{% url add_group %}";
var group_dropdown = new GroupDropdown({{ group_list }});
$('.dropdown').append(group_dropdown.getElement());
- if (askbot['data']['userIsAdmin']) {
- group_dropdown.enableAddGroups();
- }
}
});
if (askbot['data']['haveFlashNotifications']) {