You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wookie.apache.org by rg...@apache.org on 2011/11/04 18:34:39 UTC

svn commit: r1197684 [7/7] - in /incubator/wookie/trunk/scratchpad/widgets/walkthrough: ./ images/ legal/ lib/ lib/jqueryMobile/ lib/jqueryMobile/images/ scripts/ style/ xml/

Added: incubator/wookie/trunk/scratchpad/widgets/walkthrough/scripts/questions.js
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/scratchpad/widgets/walkthrough/scripts/questions.js?rev=1197684&view=auto
==============================================================================
--- incubator/wookie/trunk/scratchpad/widgets/walkthrough/scripts/questions.js (added)
+++ incubator/wookie/trunk/scratchpad/widgets/walkthrough/scripts/questions.js Fri Nov  4 17:34:37 2011
@@ -0,0 +1,229 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+var Controller = 
+{
+    initPage: function()
+    {
+        var question_file = "xml/questions.xml";
+        var self = this;
+        if (self.model === undefined)
+        {
+            $.get(question_file, function(xml){ // load XML - need error handling
+                self.model = $( xml ); 
+                self.setHeaderFooter();
+                var page = window.location.hash; // might be F5 on a URI with hash
+                $.mobile.changePage(page, {changeHash: false});
+            });
+        }
+    },
+
+    setHeaderFooter: function()
+    {
+        var title = this.model.find("question_set > title").text();
+        $("#title").html(title); // Also set page title
+                
+        this.setupSave();
+    },
+    
+	showQuestion: function(url, options)
+    {
+        if (url == '')
+        {
+            url = '#'+this.model.find("question:first").attr("id");
+        }
+
+        var urlObj = $.mobile.path.parseUrl(url);
+        var options = options || {};
+
+        // fill in question
+        var idQ = urlObj.hash.slice(1);
+        var question = this.model.find('question[id="'+idQ+'"]').first();
+        if (question.length == 0)
+        {
+            alert("Cannot find a question with an id of '"+idQ+"'");
+            return;
+        }
+        this.showQuestionText(question);
+        this.showAnswerText(question);
+
+        var page = $("#page");
+        page.page();
+        //var content = page.children( ":jqmData(role=content)" );
+        
+        //$("#question_body").find( ":jqmData(role=button)" )button();
+        //answers.listview('refresh');
+
+        options.dataUrl = urlObj.href;          // not page id
+        options.allowSamePageTransition = true; // so hash get's updated in browser
+        $.mobile.changePage(page, options);     // As per JQM example - doesn't recusive bomb   
+	},
+   
+    isNote: function(href)
+    {   
+        return (href.slice(0, 7).toLowerCase() != 'http://'.toLowerCase());
+    },
+      
+    showQuestionText: function (question)
+    {
+	    $("#question_title").html(question.find("title").text());
+
+        var qhtml = '';
+        // create question with link to add actions
+        question.find("body").contents().each( function() {
+            var that = $(this);
+            if (this.nodeType == 3) // text
+                qhtml += that.text();
+            else 
+            {
+                var type = that.attr('type');
+                if (type == 'TODO')
+                {
+                    var href = ''; // made up protocol we can match against - won't degrade
+                }
+                else
+                {
+                    var href = that.attr('href');
+                }
+                var text = that.text();
+                qhtml += that.attr('type')+": <a href='#' data-href='"+href+"'>"+text+"</a>";
+            }
+        });
+	    $("#question_body").html(qhtml);
+
+        var todo = $("#todo_list");
+        var self = this;
+        
+        // hook up buttons to add items to actions list.
+        var button_links = $("#question_body").find('a');
+        button_links.bind('click', function(event) 
+        {   
+            var href = $(event.target).data('href');
+            var text = event.currentTarget.textContent;
+            if (href == '') 
+            {
+                var item = "<li>TODO: "+text;
+            }
+            else
+            {
+                var target = href;
+                if (self.isNote(href))
+                {
+                    // is internal note
+                    target = 'noteviewer.html#'+href; // arguable should be ?note= and not hash
+                }
+                var item = "<li>TOREAD: <a href='"+target+"' target='_blank'>"+text+"</a>";
+            }
+            item += " <a title='Delete this action' class='action_delete' href='#'>[X]</a></li>";
+            todo.append(item);
+            
+            // add a remove link
+            var a_new = todo.find('li > a').last(); 
+            a_new.bind('click', function(event) {
+                
+                $(event.target.parentNode).remove();
+                return false;
+            });
+            
+            //todo.listview('refresh');
+            return false;
+        });
+    },
+
+    showAnswerText: function (question)
+    {
+        $("#answer_text").html(question.find("navigation > text").text());
+        
+        var answers = $("#answer_links");
+
+        // update answers
+        answers.find('li').remove();
+        question.find("navigation > answer").each( function(i, el) {
+           var next_id = $(el).attr("next");
+           var next_text = $(el).text();
+           var html = "<li><a href='#"+next_id+"'>"+next_text+"</a></li>";
+           answers.append(html);
+        });
+
+        // hook up answers to show next question
+        var answer_links = answers.find('a');
+        answer_links.bind('click', function(event) 
+        {
+            $.mobile.changePage(event.target.href, {}); 
+            return false;
+        });
+    },
+
+    setupSave: function()
+    {
+        var self = this;
+        
+        // save button action
+        $("#save").bind('click', function(event) 
+        {   
+            var todo = $("#todo_list");
+            var items = todo.find('li');
+            var text = '';
+            items.each( function(i, el)
+            {
+                var that = $(this);
+                text += '' + (i+1) + '. '+ that.text();
+                text = text.replace(/\[X\]?/g, '');
+                var href = that.find("a").first().attr('href');
+                if (href != undefined && !self.isNote(href))
+                    text += ' - ' + href;
+                if (self.isNote(href))
+                {
+                    var id = $.mobile.path.parseUrl( href ).hash;
+                    var note = self.model.find('note[id="'+id.slice(1)+'"]').first();
+                    var notetext = (note.length != 0) ? note.text() : "Cannot find a note with an id of '"+id+"'";
+                    text += "\r\n" + notetext; 
+                }
+                text += "\r\n\r\n";
+                i++;
+            });
+            if (text != '')
+            {   
+                //$('#the_actions').attr('value',text); 
+                //$('#actions_form').submit();
+                alert('Actions to copy\r\n\r\n'+text+'\r\n'); // alt that doesn't use php but requires cut n paste
+                }
+            return false;
+        });
+    }
+};
+
+$("#page").live('pagebeforecreate',function(event)
+{ 
+  // called for URL without hash or F5 on any page
+  Controller.initPage();
+});
+
+
+// update page contents
+$(document).bind( "pagebeforechange", function( e, data ) {
+	if ( typeof data.toPage === "string" ) {
+        if ($.mobile.activePage === undefined)
+            // edge condition if F5 used on URL with hash 
+            // allow default processing so get pagecreatebefore event
+            return;
+
+        var hash = $.mobile.path.parseUrl( data.toPage ).hash;
+        Controller.showQuestion( hash, data.options );
+        e.preventDefault();
+    }
+});

Propchange: incubator/wookie/trunk/scratchpad/widgets/walkthrough/scripts/questions.js
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/wookie/trunk/scratchpad/widgets/walkthrough/style/style.css
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/scratchpad/widgets/walkthrough/style/style.css?rev=1197684&view=auto
==============================================================================
--- incubator/wookie/trunk/scratchpad/widgets/walkthrough/style/style.css (added)
+++ incubator/wookie/trunk/scratchpad/widgets/walkthrough/style/style.css Fri Nov  4 17:34:37 2011
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+ 
+ .ui-grid-a .ui-block-a {
+  width:70%;
+}
+.ui-grid-a .ui-block-b {
+  width:28%;
+  float:right;
+}
+
+
+#page {
+/*  background: #f1f2ea url(images/background.gif) repeat-y right;*/
+  background: #f1f2ea;
+  text-shadow: none;
+}
+#header {
+  background: #d7dabd;
+  color: black;
+}
+.ui-title,
+#copyright,
+#actions {
+  text-shadow: none;
+}
+#footer {
+  background: #d7dabd;
+  margin-top: 1em;
+  padding: 0.2em;
+}
+#save {
+  margin-right: 2em;
+  float: right;
+}
+
+#content {
+  border-right:2px solid #d7dabd;
+}
+#answer_text {
+  border-top: 2px solid #d7dabd;
+  margin-top: 1em;
+  padding-top: 1em;
+}
+
+#actions {
+  background: #D7DAC3;
+  height: 100%;
+  padding-left: 1em;
+}
+
+a.action_delete {
+  color: red;
+}
+
+#note_viewer {
+  display: none;
+  background: #F1EEE9;
+}
+
+.clearing {
+  height: 0;
+  clear: both;
+}
+
+#actions_form {
+    display: hidden;
+}
\ No newline at end of file

Propchange: incubator/wookie/trunk/scratchpad/widgets/walkthrough/style/style.css
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/wookie/trunk/scratchpad/widgets/walkthrough/xml/question_set.dtd
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/scratchpad/widgets/walkthrough/xml/question_set.dtd?rev=1197684&view=auto
==============================================================================
--- incubator/wookie/trunk/scratchpad/widgets/walkthrough/xml/question_set.dtd (added)
+++ incubator/wookie/trunk/scratchpad/widgets/walkthrough/xml/question_set.dtd Fri Nov  4 17:34:37 2011
@@ -0,0 +1,40 @@
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You 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.
+-->
+
+<!ELEMENT question_set (title, question+, note+)>
+
+<!ELEMENT question (title, body, navigation)>
+<!ATTLIST question id ID #REQUIRED>
+
+<!ELEMENT title (#PCDATA)>
+
+<!ELEMENT body (#PCDATA|todo_item)*>
+
+<!ELEMENT todo_item (#PCDATA)>
+<!ATTLIST todo_item 
+                   type CDATA "TODO"
+                   href CDATA #IMPLIED>
+
+<!ELEMENT navigation (text, answer+)>
+
+<!ELEMENT text (#PCDATA)>
+
+<!ELEMENT answer (#PCDATA)>
+<!ATTLIST answer next IDREF #IMPLIED>
+
+<!ELEMENT note (#PCDATA)>
+<!ATTLIST note id ID #REQUIRED>

Propchange: incubator/wookie/trunk/scratchpad/widgets/walkthrough/xml/question_set.dtd
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/wookie/trunk/scratchpad/widgets/walkthrough/xml/questions.xml
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/scratchpad/widgets/walkthrough/xml/questions.xml?rev=1197684&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/wookie/trunk/scratchpad/widgets/walkthrough/xml/questions.xml
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/wookie/trunk/scratchpad/widgets/walkthrough/xml/questions.xml
------------------------------------------------------------------------------
    svn:mime-type = application/xml