source: Dev/trunk/classes/SessionCreationTool.php @ 68

Last change on this file since 68 was 68, checked in by fpvanagthoven, 14 years ago

Pipeline now gets submitted

File size: 8.4 KB
Line 
1<?php
2
3/**
4 * Description of SessionCreationTool
5 *
6 * @author fpvanagthoven
7 */
8class SessionCreationTool {
9
10    private $session;
11    private $surveys;
12
13    public function __construct($session = null) {
14        $this->session = $session;
15
16        $this->init();
17
18        $this->javascript();
19        var_dump($_POST);
20        ?>
21
22        <div class="creation">
23            <form id="sessionCreationForm" action="" onsubmit="submitPipeline()" method="post">
24                <?php
25                $this->title();
26                $this->description();
27                $this->pipeline();
28
29                $this->makeSessionButton();
30                ?>
31            </form>
32        </div>
33        <?php
34    }
35
36    private function init() {
37        $this->surveys = Loader::loadSurveys();
38    }
39
40    private function javascript() {
41        ?>
42        <script type="text/javascript" src="js/creation.js"></script>
43        <script type="text/javascript">
44            var pipelineCount = 0;
45            var surveys = new Array();
46                           
47            init();
48                                                                                                                                                                       
49            function init() {
50                loadSurveys();
51                loadApplications();
52            }
53                                                                                                                                                                       
54            function loadSurveys() {
55        <?php
56        foreach ($this->surveys as $survey) {
57            ?>
58                        var title = <?php echo "'" . $survey->title . "'"; ?>;
59                        var id = <?php echo "'" . $survey->id . "'"; ?>;
60                        var survey = new Survey(title, id);
61                        surveys.push(survey);
62            <?php
63        }
64        ?>
65            }
66                                                                                                                                                           
67            function loadApplications() {
68                                                                                                                                                               
69            }
70                                                                                                                                                           
71            function Survey(title, id)
72            {
73                this.title = title;
74                this.id = id;
75            }
76                                                                                                                                                           
77            // =============================================================
78                                                                                                                                                           
79            function addSurvey() {
80                pipelineCount++;
81                               
82                var pipeline = document.getElementById("pipeline");
83                var surveysList = document.getElementById("surveysList");
84                                                       
85                var entry = document.createElement("option");
86                entry.setAttribute("value", surveys[surveysList.selectedIndex].id);
87                entry.style.backgroundColor = "#0090ac";
88                entry.innerHTML = pipelineCount + ". " + surveys[surveysList.selectedIndex].title;
89                entry.name = pipelineCount + "s";
90                                               
91                pipeline.appendChild(entry);
92            }
93                                   
94            function addDashboard() {
95                pipelineCount++;
96                var pipeline = document.getElementById("pipeline");
97                                       
98                var entry = document.createElement("option");
99                entry.setAttribute("value", "dashboard");
100                entry.style.backgroundColor = "#555";
101                entry.style.color = "white";
102                entry.innerHTML = pipelineCount + ". " + "Dashboard";
103                entry.name = pipelineCount + "d";
104                                       
105                pipeline.appendChild(entry);
106            }
107                                                     
108            function submitPipeline()
109            {
110                var form = document.getElementById("sessionCreationForm");
111                       
112                var pipeline = document.getElementById("pipeline").options;
113                               
114                               
115                for (var i = 0; i < pipeline.length; i++)
116                {
117                    var pipelineElem = document.createElement("input");
118                    pipelineElem.name = pipeline[i].name;
119                    pipelineElem.value = pipeline[i].value;
120                    pipelineElem.type = "hidden";
121                           
122                    form.appendChild(pipelineElem);
123                }
124                               
125            }
126        </script>
127        <?php
128    }
129
130    private function title() {
131        if (isset($this->session->title))
132            $value = $this->session->title;
133        else
134            $value = 'Untitled Session';
135        ?>
136        <input type="text" id="sessionTitle" class="titleBox" name="sessionTitle" value="<?php echo $value; ?>" onblur="handleBlur(this)" onfocus="handleFocus(this)" />
137        <?php
138    }
139
140    private function description() {
141        if (isset($this->session->description))
142            $value = $this->session->description;
143        else
144            $value = 'Write a description for this session here.';
145        ?>
146        <textarea id="sessionDescription" class="descriptionBox" name="sessionDescription" onblur="handleBlur(this)" onfocus="handleFocus(this)"><?php echo $value; ?></textarea>
147        <?php
148    }
149
150    private function pipeline() {
151        ?>
152        <div id="pipelineWrapper">
153            <h2 class="pipelineHead">Pipeline</h2>
154            <?php $this->pipelineSelect(); ?>
155            <div id="pipelineOptions">
156                <?php
157                $this->addDashboardToPipelineButton();
158                ?>
159            </div>
160        </div>
161        <div id="surveysApplicationsWrapper">
162            <div id="surveysForPipelineWrapper">
163                <h2 class="pipelineHead">Surveys</h2>
164                <?php
165                $this->surveysSelect();
166                $this->addSurveyToPipelineButton()
167                ?>
168            </div>
169            <div id="applicationsForPipelineWrapper">
170                <h2 class="pipelineHead">Applications</h2>
171                <?php
172                $this->applicationsSelect();
173                $this->addApplicationToPipelineButton();
174                ?>
175            </div>
176        </div>
177        <?php
178    }
179
180    private function pipelineSelect() {
181        ?>
182        <select id="pipeline" size="1000">
183
184        </select>
185        <?php
186    }
187
188    private function surveysSelect() {
189        ?>
190        <select id="surveysList" size="5" class="width100p">
191            <?php
192            foreach ($this->surveys as $survey) {
193                ?>
194                <option value="<?php echo $survey->id; ?>">
195                    <?php echo $survey->title; ?>
196                </option>
197                <?php
198            }
199            ?>
200        </select>
201        <?php
202    }
203
204    private function applicationsSelect() {
205        ?>
206        <select id="applicationsList" size="5" class="width100p">
207        </select>
208        <?php
209    }
210
211    private function addSurveyToPipelineButton() {
212        ?>
213        <input type="button" id="surveyToPipeline" class="surveyButton pipelineButton leftAlign leftPadding1" value="<=====" onclick="addSurvey()"/>
214        <?php
215    }
216
217    private function addApplicationToPipelineButton() {
218        ?>
219        <input type="button" class="surveyButton pipelineButton leftAlign leftPadding1" value="<=====" />
220        <?php
221    }
222
223    private function addDashboardToPipelineButton() {
224        ?>
225        <input type="button" class="surveyButton nextLine pipelineButton leftAlign leftPadding1" value="+ Dashboard" onclick="addDashboard()"/>
226        <?php
227    }
228
229    private function makeSessionButton() {
230        ?>
231        <input type="submit" id="makeSessionButton" class="topRight surveyButton" value="Make session" />
232        <?php
233    }
234
235}
236?>
Note: See TracBrowser for help on using the repository browser.