6 # This file is part of MaePadWeb
7 # Copyright (c) 2010 Thomas Perl <thp.io/about>
8 # http://thp.io/2010/maepad/
10 # This program is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation, either version 3 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program. If not, see <http://www.gnu.org/licenses/>.
27 <title>MaePadWeb
</title>
28 <script type=
"text/javascript" src=
"/jquery.js"></script>
29 <script type=
"text/javascript">
31 var selectedChecklistItem
= null;
32 var selectedChecklistIndex
= null;
33 var activeChecklistNodeId
= null;
35 function switchTo(selector
) {
36 var items
= Array("#nodelist", "#checklist", "#sketch", "#richtext");
37 for (i
=0; i
<items
.length
; i
++) {
38 if (items
[i
] != selector
) {
44 if (selector
!= "#nodelist") {
45 $("#backlink").css('visibility', 'visible');
47 $("#backlink").css('visibility', 'hidden');
48 $('#checklistToolbar').hide();
52 var nodeTypes
= new Array("UNKNOWN", "Text", "Sketch", "Checklist");
53 $(document
).ready(function() {
54 switchTo('#nodelist');
55 $.getJSON('/nodelist.json', function(data
) {
56 var current
= $('#nodelist_ul');
58 $.each(data
, function() {
59 current
.append('<li><a onclick="setNodeTitle(\''+this[1]+'\');open'+nodeTypes
[this[2]]+'('+this[0]+')"><span style="font-weight: bold;">'+this[1]+'</span><small style="color: #aaa;"><br>'+nodeTypes
[this[2]]+'</small></a></li>');
64 function openText(nodeid
) {
65 switchTo('#richtext');
66 $.get('/richtext.html?id='+nodeid
, function(data
) {
67 $('#richtext').html(data
);
71 function openSketch(nodeid
) {
73 $('#sketch_img').attr('src', '/sketch.png?id='+nodeid
);
76 function trueComesBack(data
) {
78 alert('A request to the web server failed.');
82 function setNodeTitle(title
) {
83 $('#nodetitle').html(title
);
86 function editChecklistItem(index
, item
) {
87 if (selectedChecklistItem
!= null) {
88 $(selectedChecklistItem
).removeClass('selectedChecklistItem');
90 selectedChecklistItem
= item
;
91 selectedChecklistIndex
= index
;
92 if (index
!= null && item
!= null) {
93 updateChecklistToolbar();
94 $(item
).addClass('selectedChecklistItem');
98 function checklistAddNew() {
99 var newItemText
= prompt('Enter text for new item:', '');
100 if (newItemText
!= null && newItemText
!= '') {
101 $.getJSON('/checklist.addItem?id='+activeChecklistNodeId
+'&text='+escape(newItemText
), function(data
) {
103 /* Reload checklist */
104 openChecklist(activeChecklistNodeId
);
106 alert('Could not save checklist item');
112 function checklistDelete() {
113 if (!confirm('Really delete this item?')) {
116 $.getJSON('/checklist.deleteItem?id='+selectedChecklistIndex
, function(data
) {
118 /* Reload checklist */
119 openChecklist(activeChecklistNodeId
);
121 alert('Could not save checklist item');
126 function checklistToggleBold() {
127 var item
= $(selectedChecklistItem
);
128 var span
= item
.find('span').first();
129 var isBold
= (span
.css('font-weight') == 'bold');
131 span
.css('font-weight', 'normal');
133 span
.css('font-weight', 'bold');
135 $.getJSON('/checklist.setBold?id='+selectedChecklistIndex
+'&bold='+(!isBold
), trueComesBack
);
136 updateChecklistToolbar();
139 function checklistToggleStrike() {
140 var item
= $(selectedChecklistItem
);
141 var span
= item
.find('span').first();
142 var isStrike
= (span
.css('text-decoration') == 'line-through');
144 span
.css('text-decoration', 'none');
146 span
.css('text-decoration', 'line-through');
148 $.getJSON('/checklist.setStrike?id='+selectedChecklistIndex
+'&strike='+(!isStrike
), trueComesBack
);
149 updateChecklistToolbar();
152 function checklistToggleCheck() {
153 var item
= $(selectedChecklistItem
);
154 var checkbox
= item
.find('img').first();
155 checkbox
.toggleClass('checked');
156 if (checkbox
.hasClass('checked')) {
157 checkbox
.attr('src', '/icons/widgets_tickmark_list');
159 checkbox
.attr('src', '/nix.gif');
161 $.getJSON('/checklist.setCheck?id='+selectedChecklistIndex
+'&check='+checkbox
.hasClass('checked'), trueComesBack
);
162 updateChecklistToolbar();
165 function checklistEditText() {
166 var item
= $(selectedChecklistItem
);
167 var span
= item
.find('span').first();
168 newValue
= prompt('Edit this node:', span
.html());
169 if (newValue
== null) {
171 } else if (newValue
== '') {
176 $.getJSON('/checklist.setText?id='+selectedChecklistIndex
+'&text='+escape(newValue
), trueComesBack
);
180 function updateChecklistToolbar()
182 var item
= $(selectedChecklistItem
);
183 var span
= item
.find('span').first();
184 var checkbox
= item
.find('img').first();
185 var isBold
= (span
.css('font-weight') == 'bold');
186 var isStrike
= (span
.css('text-decoration') == 'line-through');
187 var isChecked
= checkbox
.hasClass('checked');
189 $('#checklistToolbar #boldButton').addClass('selected');
191 $('#checklistToolbar #boldButton').removeClass('selected');
194 $('#checklistToolbar #strikeButton').addClass('selected');
196 $('#checklistToolbar #strikeButton').removeClass('selected');
199 $('#checklistToolbar #checkButton').addClass('selected');
201 $('#checklistToolbar #checkButton').removeClass('selected');
205 function openChecklist(nodeid
) {
206 activeChecklistNodeId
= nodeid
;
207 $('#checklistToolbar').fadeIn();
209 switchTo('#checklist');
210 $('#checklist_ul').html('');
211 $.getJSON('/checklist.json?id='+nodeid
, function(data
) {
212 var current
= $('#checklist_ul');
213 $.each(data
, function() {
219 if (color
!= '000000') {
220 spanStyle
+= 'color: #'+color
+';';
223 spanStyle
+= 'text-decoration:line-through;';
226 spanStyle
+= 'font-weight:bold;';
228 current
.append('<li><a ondblclick="checklistEditText();" onclick="editChecklistItem('+index
+', this)"><img class="checklistBox '+((style
&(1<<0))?"checked":"")+'" src="'+((style
&(1<<0))?"/icons/widgets_tickmark_list":"/nix.gif")+'" onclick="editChecklistItem('+index
+', $(this).parent());checklistToggleCheck();"><span style="'+spanStyle
+'">'+name
+'</span></a></li>');
234 <style type=
"text/css">
237 background-color: black
;
239 font-family: sans-serif
;
248 vertical-align: middle
;
250 background-image: url
(/theme/title_bg);
253 border-bottom: 1px solid black
;
258 #nodelist ul
, #checklist ul
{
263 #nodelist li
, #checklist li
{
264 background-color: #000;
268 #nodelist li:nth-child
(2n+1), #checklist
li:nth-child
(2n+1) {
269 background-color: #080808;
275 text-decoration: none
;
276 text-shadow: 0px 0px 3px black
;
282 text-decoration: none
;
283 text-shadow: 0px 0px 3px black
;
285 #checklist li a
.selectedChecklistItem
{
286 background-image: url
(/theme/toolbar_hi);
287 background-color: #666; /* FIXME: take from theme */
292 text-decoration: none
;
297 padding-bottom: 40px;
301 vertical-align: middle
;
308 #checklistToolbar img
{
319 background-image: url
(/theme/toolbar_bg);
320 background-color: black
;
323 #checklistToolbar .selected
{
324 background-image: url
(/theme/toolbar_hi);
325 background-color: #666; /* FIXME: take from theme */
328 #checklistToolbar a
{
338 <h1 id=
"x"><img src=
"/logo.png" style=
"vertical-align: middle; border-right: 1px solid black; padding: 14px;" alt=
"MaePadWeb"> <span style=
"font-weight: normal; padding: 4px; font-size: 20px;" id=
"nodetitle"></span>
339 <span id=
"backlink" style=
"float: right;">
340 <a onclick=
"setNodeTitle('');switchTo('#nodelist')"><img src=
"/theme/title_btn" alt=
"back" style=
"border-left: 1px solid black;"></a>
342 </h1><div style=
"padding-top: 56px; padding-bottom: 30px;">
344 <ul id=
"nodelist_ul"></ul>
347 <ul id=
"checklist_ul"></ul>
350 <img id=
"sketch_img" style=
"border: 1px solid black;">
352 <p id=
"richtext" style=
"border: 1px solid black; background-color: white;"></p>
354 <div id=
"checklistToolbar">
355 <a id=
"checkButton" onclick=
"checklistToggleCheck();"><img src=
"/icons/widgets_tickmark_list" alt=
"CHECK" title=
""></a>
356 <a id=
"boldButton" onclick=
"checklistToggleBold();"><img src=
"/icons/general_bold" alt=
"BOLD" title=
""></a>
357 <a id=
"strikeButton" onclick=
"checklistToggleStrike();"><img src=
"/icons/strike" alt=
"STRIKE" title=
""></a>
358 <a id=
"colorButton" onclick=
"alert('Not yet implemented.');"><img src=
"/icons/palette" alt=
"COLOR" title=
""></a>
359 <a style=
"border-left: 1px solid white; margin: 10px; padding: 0px; height: 32px;"></a>
360 <a id=
"addButton" onclick=
"checklistAddNew();"><img src=
"/icons/general_add" alt=
"ADD" title=
""></a>
361 <a id=
"editButton" onclick=
"checklistEditText();"><img src=
"/icons/sketch" alt=
"EDIT" title=
""></a>
362 <a id=
"deleteButton" onclick=
"checklistDelete();"><img src=
"/icons/general_delete" alt=
"DEL" title=
""></a>
365 <!-- image preloading -->
366 <img src=
"/theme/toolbar_hi" style=
"display: none;">
367 <img src=
"/nix.gif" style=
"display: none;">