Skip to content

Commit

Permalink
All tests now passing
Browse files Browse the repository at this point in the history
  • Loading branch information
colinphanna committed May 30, 2012
1 parent b960c6a commit f67397f
Show file tree
Hide file tree
Showing 16 changed files with 728 additions and 423 deletions.
46 changes: 32 additions & 14 deletions app/assets/javascripts/forums/Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,37 @@ Talho.Forums.Controller = Ext.extend(Ext.util.Observable, {
constructor: function(config){
Ext.apply(this, config);

this.index = new Talho.Forums.view.Forums.Index({itemId: 'index'});
this.index = new Talho.Forums.view.Forums.Index();
var layout = new Talho.Forums.view.Layout({
title: this.title || "Forums",
itemId: this.itemId,
title: this.title || "Forums",
items: [
this.index
]
});

this.index.on('reload', this.index.reload, this.index);
this.index.on({
'editforum': this.newForum,
'newforum': this.newForum,
'showtopics': this.displayTopics,
'manageforum': this.manageForum,
scope: this
});

this.getPanel = function(){
return layout;
}
return layout;
}

this.index.on('reload', this.index.reload, this.index);
this.index.on({
'editforum': this.newForum,
'newforum': this.newForum,
'showtopics': this.displayTopics,
'manageforum': this.manageForum,
'newtab': this.newTab,
scope: this
});

// New Tab stuff
// if (config.panels)
// {
// var ic = this.getPanel().innerContainer;
// for(var i = 0; i < config.panels.length; i++)
// {
// ic.add(config.panels.items[i]);
// }
// }
},

newForum: function(forumId,parentId){
Expand Down Expand Up @@ -67,6 +77,8 @@ Talho.Forums.Controller = Ext.extend(Ext.util.Observable, {
'deletetopic': this.deleteTopic,
'newsubforum': this.newForum,
'movetopic': this.moveTopic,
'showtopics': this.displayTopics,
'newtab': this.newTab,
scope: this
});
},
Expand All @@ -82,6 +94,7 @@ Talho.Forums.Controller = Ext.extend(Ext.util.Observable, {
'editcomment': this.editComment,
'quotecomment': this.quoteComment,
'deletetopic': this.deleteTopic,
'newtab': this.newTab,
scope: this
});

Expand Down Expand Up @@ -152,6 +165,11 @@ Talho.Forums.Controller = Ext.extend(Ext.util.Observable, {
}
});
},

newTab: function () {
var panels = this.getPanel().innerContainer.items;
Application.fireEvent('opentab', {title: 'Forums Tab', panels: panels, initializer: 'Talho.Forums'});
},

_removePanel: function(panel){
var ic = this.getPanel().innerContainer;
Expand Down
3 changes: 1 addition & 2 deletions app/assets/javascripts/forums/view/Layout.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
Ext.ns("Talho.Forums.view");

Talho.Forums.view.Layout = Ext.extend(Ext.Panel, {
layout: 'border',
closable: true,
id: 'ForumPanel',
initComponent: function(){
Expand All @@ -10,7 +9,7 @@ Talho.Forums.view.Layout = Ext.extend(Ext.Panel, {
{itemId: 'container', width: 940, layout: 'card', style: 'margin: auto;', activeItem: 0, items: items}
);
this.items = [{xtype: 'bootstrapbreadcrumb', region: 'north', panel: card_panel},
{xtype: 'panel', border: false, autoScroll: true, itemId: 'centering', region: 'center', items: [card_panel]}
{xtype: 'panel', border: false, itemId: 'centering', region: 'center', items: [card_panel]}
];

Talho.Forums.view.Layout.superclass.initComponent.apply(this, arguments);
Expand Down
140 changes: 95 additions & 45 deletions app/assets/javascripts/forums/view/forums/Index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
Ext.ns("Talho.Forums.view.Forums");

Talho.Forums.view.Forums.Index = Ext.extend(Ext.Panel, {
layout: 'fit',
height: 400,
autoHeight: true,
constructor: function(){
this.addEvents('showtopic', 'editforum');
this.on('activate', this.reload, this);
this.on('reload', this.reload, this);
Talho.Forums.view.Forums.Index.superclass.constructor.apply(this, arguments);
},
initComponent: function(){
initComponent: function(){
if (!this.items){
this.items = [];
}
Expand All @@ -24,58 +25,107 @@ Talho.Forums.view.Forums.Index = Ext.extend(Ext.Panel, {
restful: true,
idProperty: 'id',
fields: ['name', {name:'hidden_at', type: 'date'}, {name:'created_at', type:'date', dateFormat: 'Y-m-d\\Th:i:sP'}, {name:'updated_at', type:'date', dateFormat: 'Y-m-d\\Th:i:sP'},
'lock_version', 'id', {name: 'is_moderator', type: 'boolean'}, {name: 'is_super_admin', type: 'boolean'}, {name: 'is_forum_admin', type: 'boolean'}, 'threads'],
baseParams: {per_page: 20},
autoLoad: {params: {start: 0}}
'lock_version', 'id', {name: 'is_moderator', type: 'boolean'}, {name: 'is_super_admin', type: 'boolean'}, {name: 'is_forum_admin', type: 'boolean'}, 'threads', 'subforums'],
autoLoad: true
});

this.items.push({xtype: 'grid', itemId: 'grid', header: false, border: true,
store: store,
columns: [
{header: 'Name', cls: 'forum-name', dataIndex: 'name', id: 'name', sortable: false},
{header: 'Topics', cls: 'forum-topic-count', dataIndex: 'threads', align: 'center', sortable: false},
{xtype: 'actioncolumn', align: 'center', width: 30, iconCls: 'edit_forum', sortable: false,
icon: '/assets/images/pencil.png',
getClass: function (v,meta,record) {
if (record.get('is_super_admin') || record.get('is_forum_admin')) {
return 'x-action-col-cell'} else {
Ext.ComponentMgr.get('newForumButton').addClass('x-hide-display'); return 'x-hide-display';} },
handler: function (grid,i) {
this.fireEvent('editforum', grid.getStore().getAt(i).get('id')) },
scope: this, tooltip: 'Edit'},
{xtype: 'actioncolumn', align: 'center', sortable: false,
icon: '/assets/images/pencil.png',
iconCls: 'manage_forum',
width: 30,
getClass: function (v,meta,record) {
if (record.get('is_super_admin') || record.get('is_forum_admin')) {
return 'x-action-col-cell'} else {
Ext.ComponentMgr.get('newForumButton').addClass('x-hide-display'); return 'x-hide-display';} },
handler: function (grid,i) {
this.fireEvent('manageforum', grid.getStore().getAt(i).get('id')) },
scope: this, tooltip: 'Manage Forum'}
],
loadMask: true,
autoExpandColumn: 'name',
listeners: {
scope: this,
'rowclick': function(grid,i,e) {
var target = e.getTarget(null, null, true);

if (target.hasClass('x-action-col-icon')) {
return;
var forumTpl = new Ext.XTemplate(
'<div class="forum-wrap" forumid="{id}">',
'<div class="forum-left" forumid="{id}"><table>',
'<tr>',
'<td><span class="forum-title" forum_name="{name}" forumid="{id}">{name}</span></td>',
'</tr>',
'<tr>',
'<td>',
'<tpl if="this.canEdit(values)">',
'<span class="forum-edit forum-actions" forum_name="{name}" forumid="{id}">&laquo;Edit</span>',
'</tpl>',
'<tpl if="this.canManage(values)">',
'<span class="forum-manage forum-actions" forum_name="{name}" forumid="{id}" alt="Manage Forum">&laquo;Manage</span>',
'</tpl>',
'<td>',
'</tr>',
'</table></div>',
'<div class="forum-reply-count">{threads}</div>',
'<div class="forum-clear"></div>' ,
'</div>',
{
canEdit: function(values){
return (this.isAdmin(values) || values.is_owner);
},
canManage: function(values){
return this.isAdmin(values);
},
isAdmin: function (values){
if (values.is_super_admin || values.is_forum_admin)
{
return true;
}
var store = grid.getStore();
this.fireEvent('showtopics',store.getAt(i).get('id'), store.getAt(i).get('name'));
Ext.ComponentMgr.get('newForumButton').addClass('x-hide-display');
return false;
}
}
);

var forumIndexTpl = new Ext.XTemplate(
'<div class="forum-header">',
'<span class="forum-header-title">My Forums</span>',
'<span class="forum-header-threads">Threads</span>',
'</div>',
'<div class="forum-divider">&nbsp;</div>',
'<ul class="forum-list">',
'<tpl for=".">',
'<li class="forum-index-selector" forumid="{id}">',
'{[ this.renderForum(values) ]}',
'</li>',
'</tpl>',
'</ul>',
{
renderForum: function(values){
return forumTpl.apply(values);
}
}
);

var indexView = new Ext.DataView({
id: 'forumsIndex',
store: store,
tpl: forumIndexTpl,
emptyText: "No forums created",
listeners: {
'click': {
fn: function(div, index, node, e) {
if (node.classList.contains('forum-edit')) {
this.fireEvent('editforum', parseInt(node.attributes['forumid'].value), null);
}
else if (node.classList.contains('forum-manage')) {
this.fireEvent('manageforum', parseInt(node.attributes['forumid'].value));
}
else if (node.attributes['forumid']) {
var forumId = node.attributes['forumid'].value;
var forumName = Ext.DomQuery.selectValue(".forum-title[forumId=" + forumId + "]");
this.fireEvent('showtopics', parseInt(forumId), forumName);
}
},
scope: this }
}
});

this.items.push(indexView);

Talho.Forums.view.Forums.Index.superclass.initComponent.apply(this, arguments);
},
reload: function () {
this.getComponent('grid').getStore().load();
},
if (this.activated)
{
for (i=0; i < this.items.getCount(); i++)
{
this.items.get(i).getStore().load();
this.items.get(i).refresh();
}
}
this.activated = true;
},
border: false,
title: 'Forums',
header: false
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/forums/view/topics/Edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Talho.Forums.view.Topics.Edit = Ext.extend(Ext.form.FormPanel, {
height : 400,
constructor : function(config) {
this.addEvents('cancel, savecomplete');
config.url = String.format('forums/{0}/topics/{1}.json', config.forumId, config.topicId);
config.url = String.format('/forums/{0}/topics/{1}.json', config.forumId, config.topicId);
config.method = 'PUT'
config.waitMsgTarget = true;

Expand Down
Loading

0 comments on commit f67397f

Please sign in to comment.