10gen / core-modules-forum

10gen forum module

This URL has Read+Write access

core-modules-forum / topic_new.jxp
100644 88 lines (76 sloc) 3.146 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<% /**
* 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 "&nbsp;";
                                            return proceed(t);
                                        })
                      });
}
 
 
        Forum.renderer.topic(topic, {actions : topicActions}, 0);
    }
    else {
        print( "This name is already in use." );
    }
}
%>