Attachment 'CheckList.py'
Download 1 # -*- coding: utf-8 -*-
2 """
3 MoinMoin - CheckList
4
5 Creates an HTML checkbox as well as the HTML heading at the level you specify
6 so that you can use the wiki as a checklist for repeated tasks such as
7 OS installs, inventory checks, training etc.
8
9 CheckList utilizes the HTML5 localstorage feature for stateful storage
10 without the need for external data storage. Therefore, you must use a
11 browser that supports HTML5 which includes: ie8+, firefox 3.5+, safari 4.0+,
12 chrome 4.0+, opera 10.5+, iphone 2.0+, android 2.0+. The drawback is that
13 you must use the same browser for your checklist, but that is kindof the
14 point of this Macro.
15
16 Usage:
17 <<CheckList(id_for_checkbox, heading_level_number, heading_text_and_heading_id)>>
18 <<CheckList(js=True)>> (REQUIRED)
19 <<CheckList(clear_button=True)>> (Optional but nice)
20
21 Comments:
22 see @params list below for more info
23 Do Not use == Text == for headings. This macro creates headings for you.
24 Different than the ToDo parser (http://moinmo.in/ParserMarket/ToDo)
25 This creates a javascript src link to the Google CDN for jquery.
26 If this bothers you, let me know and I can rewrite some things.
27 Fully works with the <<TableOfContents>> macro.
28
29 @copyright: 2011 Gregory Corey <gregcorey@gmail.com>
30 @license: GNU GPL, see COPYING for details.
31 """
32 from MoinMoin import wikiutil
33 from MoinMoin.parser.text_moin_wiki import Parser as WikiParser
34
35 generates_headings = True
36
37 def macro_CheckList(macro, dom_id=None, heading=2, text=None, js=None, clear_button=None):
38 """
39 @param dom_id: The id you want for your checkbox.
40 @param heading: The Number level of the heading you are creating 2 == h2 etc
41 @param text: The text of the heading and is used to make the id of the
42 heading and is used if you use the TableOfContents macro
43 @param js: Leave all params blank except for js=True to create the necessary
44 javascript for this macro. Should be at the top of your page.
45 @param clear_button: Leave all params blank except for clear_button=True to
46 create a button to clear all Checklist items. Should be at the top of your page.
47 """
48 ret = []
49 if js:
50 return emit_js()
51
52 if clear_button:
53 return emit_button()
54
55 f = macro.request.formatter
56 # Escape HTML stuff.
57 text_h = wikiutil.escape(text)
58 text_h = text_h.strip()
59 text_id = wikiutil.escape(text)
60 text_id = text_id.replace(' ', '_')
61 text_id = text_id.strip()
62
63 ret.extend([f.heading(1,heading,id=text_id)])
64 ret.extend([f.rawHTML("<input type='checkbox' class='checklist' name='name_%s' id='id_%s'><label for='id_%s'>" % (dom_id, dom_id, dom_id))])
65 ret.extend([f.text(text_h)])
66 ret.extend([f.rawHTML("</label>")])
67 ret.extend([f.heading(0,heading)])
68
69 return ''.join(ret)
70
71 def emit_js():
72 js = """
73 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
74 <script type="text/javascript">
75 $(document).ready(function(){
76 function supports_html5_storage() {
77 try {
78 return 'localStorage' in window && window['localStorage'] !== null;
79 } catch (e) {
80 alert(e);
81 return false;
82 }
83 }
84 if(localStorage.getItem('save')){
85 $(".checklist").each(function(e){
86 var this_id = $(this).attr("id");
87 var check_val = localStorage.getItem(this_id);
88 switch(check_val){
89 case "true":
90 check_val = true;
91 break;
92 case "false":
93 check_val = false;
94 break;
95 }
96 $("#"+this_id).attr("checked", check_val);
97 if(check_val==true){
98 $("#"+this_id).parent().css({'text-decoration':'line-through'});
99 }
100 });
101 }
102 $(".checklist").change(function(){
103 var this_id = $(this).attr("id");
104 var this_val = $(this).attr("checked");
105 localStorage.setItem('save', true);
106 localStorage.setItem(this_id, this_val);
107 if(this_val==true){
108 $(this).parent().css({'text-decoration':'line-through'});
109 }
110 else{
111 $(this).parent().css({'text-decoration':'none'});
112 }
113 });
114
115 $("#clearall").click(function(){
116 $(".checklist").each(function(){
117 var this_id = $(this).attr("id");
118 $(this).attr("checked", false).parent().css({'text-decoration':'none'});
119 localStorage.setItem(this_id, false);
120 });
121 });
122 });
123 </script>
124 """
125 return js
126
127 def emit_button():
128 button = """
129 <input type="button" id="clearall" name="clearall" value="Clear All Checklist items" />
130 """
131 return button
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.