<% /**
* Copyright (C) 2008 10gen Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ %>
<%
Forum.root.controller();
Forum.root.data.topic();
core.content.forms();
if(! Forum.Controller.hasPermission(user, "createTopic"))
return Auth.cookie.reject(request, response);
var error = "";
var topic = new Forum.data.Topic();
if(request.newname){
var back;
topic.order = 0; //parseInt(topic.order);
topic.name = request.newname;
if(request.parent != "null" && request.parent != null ){
topic.parent = db.forum.topics.findOne({_id: request.parent});
back = "viewtopic?name="+URL.escape_queryargs(topic.parent.name);
}
else{
back = "./";
}
// Don't allow duplicate names.
if(db.forum.topics.findOne({name: topic.name}) == null){
if(topic.description != request.desc)
print(request.desc);
topic.description = request.desc;
db.forum.topics.save(topic);
// Horrible, horrible repeat of code!
// move this somewhere central
var topics = db.forum.topics.find({parent: null}).toArray();
topicActions = [];
topics = [{_id: null, name: "(Top Level)"}].concat(topics);
t = topic || topics[0];
var moveTopic = Forum.Controller.hasPermission(user, "moveTopic");
var hideTopic = Forum.Controller.hasPermission(user, "hideTopic");
if(hideTopic){
topicActions.push({title: "Hidden",
func: function(topic){
Forum.html.form.hidden(topic);
return "";
}});
}
Forum.root.html.form();
if(moveTopic){
topicActions.push({title : "Move Topic",
func : Forum.html.selectify(topics,
function(t){ return {onChange: "moveDlg('topic', moveTopic, '"+t._id+"')", id: t._id.toString()};},
{filter: function(t, option) { return t._id != option._id; } } ).wrap(function(proceed, t){
// We wrap the function so that when we get the Special Topics,
// we don't generate a <select> for you to move them.
if(parseInt(t._id.toString()) < 10)
return " ";
return proceed(t);
})
});
}
Forum.renderer.topic(topic, {actions : topicActions}, 0);
}
else {
print( "This name is already in use." );
}
}
%>