SlideShare una empresa de Scribd logo
1 de 24
Descargar para leer sin conexión
Lets Build Some Widgets!
Anatomy of a Widget
•   Config.xml <- W3C Widgets P&C Spec
•   icon.png
•   index.html <- HTML start file
•   JavaScript code, CSS

• Zip it up, change ext to .wgt, and you’re
  done
Widget metadata
•   Id
•   Height, Width
•   Name
•   Description
•   Version
•   Features
•   Author info
•   License
A Silly Example: config.xml
<?xml version="1.0" encoding="utf-8"?>
<widget xmlns="http://www.w3.org/ns/widgets"
   id="http://www.getwookie.org/widgets/tea"
   version="1.0” height="150” width="125">
  <name>Tea</name>
  <description>A silly Tea widget</description>
   <author>Scott Wilson</author>
</widget>
A Silly Example: index.html
<html>
  <body>
     <img src="tea.jpg" />
     <p>Time for a break, mate</p>
  </body>
</html>
Make your own basic widget
1.   Make an index.html file
2.   Make a config.xml file
3.   Zip them up, and change suffix to “.wgt”
4.   Upload to a wookie server
Uploading
•   Go to http://192.168.2.161/wookie
•   Click “admin”
•   Login with java/java
•   Click “add new widget”
•   Find your .wgt file
•   OK!
Previewing a widget
•   Go to 192.168.2.161:8080/wookie
•   Click “View Widget Gallery”
•   Click the “demo” link under your widget
•   Your widget will show
Preferences
• You can store preferences for an instance of
  a widget using:

widget.preferences.setItem(“key”, “value”)
widget.preferences.getItem(“key”)
Collaborative Widgets
• State and Participants

• State is shared across widgets with the same
  IRI in the same shared context.
• State is propagated to related widgets using
  an event callback
• State is set by submitting deltas
State example
wave.setStateCallback(stateUpdated);

stateUpdated = function(){
 var keys = wave.getState().getKeys();
 for (var i = 0; i < keys.length; i++) {
   alert(wave.getState().get(keys[i]));
 }
};

wave.getState().submitValue(“key”, “value”);
Participants
• Register callbacks with:
  wave.setParticipantCallback(myfunction);

• Methods:
   – getViewer() - get the current user
   – getParticipants() - get map of all participants

• Model:
   – getId(), getDisplayName(), getThumbnailUrl()
Making a collaborative app
•   This requires some more planning

1. Draw up a design
2. Create a working test page
3. Implement models, action handlers and
   event handlers
4. Create the config.xml, icon.png, zip it up
   and run it
Design
• Start with the view - what the widget looks
  like
• Create the model - what are the objects in
  the state model?
• Add the actions - how you interact with it
• Wire it all up…
Prototyping
• Make a regular html page to test out your
  view. Populate it with fake model, and don’t
  wire up the actions yet
• You can reuse this for the real widget - just
  take out your fake state info sections
Implementing
• Create a “Model” object for your state
  model
• Create a “Controller” object, and a method
  in it for each action
• Register the participant and state event
  handlers with an “update view” method that
  populates the view when running
Models
•       Models can be implemented in typical “bean” fashion
•       Save/Find methods need to access wave state
•       Can use JSON (e.g. with json.js) or just plain strings for storage

    function Task(id,name,status,assigned){
      this.task_id = id;
      this.name = name;
      this.status = status;
      this.assigned_to = assigned;
    }
    Task.prototype.save = function(){
    wave.getState().submitValue(this.task_id, JSON.stringify(this));
    }
Static model methods
Task.create = function(json){
      var obj = JSON.parse(json);
     var task = new Task(obj.task_id,
      obj.name,obj.status,obj.assigned_to);
    return task;
                                                                   • Typically need
}
                                                                     methods to turn state
Task.find = function(task_id){
    var keys = wave.getState().getKeys();
    for (var i = 0; i < keys.length; i++) {
                                                                     strings back into
       var key = keys[i];
       if (key == task_id){
                                                                     model instances
          return Task.create(task_id, wave.getState().get(key));

    }
       }                                                           • Also finder methods to
}
    return null;
                                                                     get a particular model
Task.findAll = function(){                                           object
  var tasks = {};
     var keys = wave.getState().getKeys();
     for (var i = 0; i < keys.length; i++) {                       • This isn’t the only way
     var key = keys[i];
     var task = Task.create(key, wave.getState().get(key));
     tasks[key] = task;
                                                                     to do this, but is an
  }
  return tasks;
                                                                     OK pattern
}
Controllers
/**
 * The Controller object
 * This is used to wire up the view and model with actions
                                                             • Methods for each
 */
var Controller = {
                                                               action, making
    // Action handlers                                         changes to the model
    // Toggle task state between completed and to-do
    toggleTask: function(task_id){
                                                             • You usually don’t
    },
                                                               need to do any code
    // Create a new task
    newTask: function(){
    },
                                                               that interacts with
    // Abandon task for someone else to do
                                                               HTML, as the event
    abandonTask: function(task_id){
    },                                                         handlers should do
    // Claim a task (assign to self)
    claimTask: function(task_id){
                                                               that
    }
}
Event Handlers
// Update the view when state has been updated               These fire whenever the state or participants
   stateUpdated: function(){                                    are updated (e.g. by another instance).
      var tasks = Task.findAll();
      if (tasks && tasks != null){
         var tasklist = "";                                  Event handlers need to be registered like so:
         for (key in tasks) {
            var task = tasks[key];                           wave.setStateCallback(Controller.stateUpdated);
                                                             wave.setParticipantCallback(Controller.participantsUpdated);
            tasklist += // the task stuff to show
         dwr.util.setValue("tasklist", tasklist, {
       escapeHtml:false });                                  Also useful to have these methods called
         var objDiv = document.getElementById("tasklist");       from onLoad() in an init() function to
         objDiv.scrollTop = objDiv.scrollHeight;                 create initial view
      }
   },
   participantsUpdated: function(){                          You can import JQuery if you like for
      Controller.updateUser();                                  setting the view content, or do it using
   }                                                            DOM
Packaging
You need to add this to your config.xml to tell
 Wookie to include the Wave Gadget API
 methods:



<feature
 name="http://wave.google.com"
 required="true"/>
Uploading, debugging and testing
• You need a             • I’ve set up a Moodle
  collaborative            instance at:
  environment to test
  your widget properly   192.168.2.XXX

                         Login as ws1,ws2,ws3,
                           or ws4
Other stuff…
• AJAX                         • Camera access
If you want to call            If you want to access the
   external sites from            user’s camera from a
   within the widget, call        widget, there is an
   myurl =
                                  example of how to do
   widget.proxify(url)
   first to call it via proxy.    this in the moodle
   Also need to add the           course (topic 3)
   site to the server
   whitelist.

Más contenido relacionado

La actualidad más candente

13 advanced-swing
13 advanced-swing13 advanced-swing
13 advanced-swing
Nataraj Dg
 

La actualidad más candente (20)

Quick start with React | DreamLab Academy #2
Quick start with React | DreamLab Academy #2Quick start with React | DreamLab Academy #2
Quick start with React | DreamLab Academy #2
 
Typescript barcelona
Typescript barcelonaTypescript barcelona
Typescript barcelona
 
"Angular.js Concepts in Depth" by Aleksandar Simović
"Angular.js Concepts in Depth" by Aleksandar Simović"Angular.js Concepts in Depth" by Aleksandar Simović
"Angular.js Concepts in Depth" by Aleksandar Simović
 
Angular In Depth
Angular In DepthAngular In Depth
Angular In Depth
 
Integrating React.js with PHP projects
Integrating React.js with PHP projectsIntegrating React.js with PHP projects
Integrating React.js with PHP projects
 
Aggregation and Awareness or How to Reduce the Amount of your FrontEnd Code ...
Aggregation and Awareness or How to Reduce the Amount of  your FrontEnd Code ...Aggregation and Awareness or How to Reduce the Amount of  your FrontEnd Code ...
Aggregation and Awareness or How to Reduce the Amount of your FrontEnd Code ...
 
13 advanced-swing
13 advanced-swing13 advanced-swing
13 advanced-swing
 
The state of hooking into Drupal - DrupalCon Dublin
The state of hooking into Drupal - DrupalCon DublinThe state of hooking into Drupal - DrupalCon Dublin
The state of hooking into Drupal - DrupalCon Dublin
 
Architectures in the compose world
Architectures in the compose worldArchitectures in the compose world
Architectures in the compose world
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testing
 
Distributing information on iOS
Distributing information on iOSDistributing information on iOS
Distributing information on iOS
 
React, Redux and es6/7
React, Redux and es6/7React, Redux and es6/7
React, Redux and es6/7
 
Basic Tutorial of React for Programmers
Basic Tutorial of React for ProgrammersBasic Tutorial of React for Programmers
Basic Tutorial of React for Programmers
 
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
 
Best Practices in Qt Quick/QML - Part IV
Best Practices in Qt Quick/QML - Part IVBest Practices in Qt Quick/QML - Part IV
Best Practices in Qt Quick/QML - Part IV
 
Hooks and Events in Drupal 8
Hooks and Events in Drupal 8Hooks and Events in Drupal 8
Hooks and Events in Drupal 8
 
Basics of AngularJS
Basics of AngularJSBasics of AngularJS
Basics of AngularJS
 
Workshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & ReduxWorkshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & Redux
 
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)
 
What's new in jQuery 1.5
What's new in jQuery 1.5What's new in jQuery 1.5
What's new in jQuery 1.5
 

Destacado

Integratsioon mat. ja loodusained
Integratsioon mat. ja loodusainedIntegratsioon mat. ja loodusained
Integratsioon mat. ja loodusained
aluojalaine
 
Consultation on Zero Waste Regulations
Consultation on Zero Waste RegulationsConsultation on Zero Waste Regulations
Consultation on Zero Waste Regulations
Christian Storstein
 
The Awaited Savior
The Awaited SaviorThe Awaited Savior
The Awaited Savior
zain
 
The Roles Of Scientists
The Roles Of ScientistsThe Roles Of Scientists
The Roles Of Scientists
griggans
 
恐龍愛玩耍 戴浩政
恐龍愛玩耍  戴浩政恐龍愛玩耍  戴浩政
恐龍愛玩耍 戴浩政
MJ7062
 
Fours And Fives
Fours And FivesFours And Fives
Fours And Fives
rwstip
 

Destacado (20)

Hayley Designers
Hayley DesignersHayley Designers
Hayley Designers
 
Wdie 8 Sem2
Wdie 8 Sem2Wdie 8 Sem2
Wdie 8 Sem2
 
Blogs For Moms
Blogs For MomsBlogs For Moms
Blogs For Moms
 
Usevertising, czyli reklama spotyka Design Thinking i co z tego wynika.
Usevertising, czyli reklama spotyka Design Thinking  i co z tego wynika.Usevertising, czyli reklama spotyka Design Thinking  i co z tego wynika.
Usevertising, czyli reklama spotyka Design Thinking i co z tego wynika.
 
Building Windmills 2009: Personal Learning Networks
Building Windmills 2009: Personal Learning NetworksBuilding Windmills 2009: Personal Learning Networks
Building Windmills 2009: Personal Learning Networks
 
Computer Games Based Learning in Schools: BETT 2010
Computer Games Based Learning in Schools: BETT 2010Computer Games Based Learning in Schools: BETT 2010
Computer Games Based Learning in Schools: BETT 2010
 
Integratsioon mat. ja loodusained
Integratsioon mat. ja loodusainedIntegratsioon mat. ja loodusained
Integratsioon mat. ja loodusained
 
$15 per Month Answering Service
$15 per Month Answering Service$15 per Month Answering Service
$15 per Month Answering Service
 
Consultation on Zero Waste Regulations
Consultation on Zero Waste RegulationsConsultation on Zero Waste Regulations
Consultation on Zero Waste Regulations
 
The Awaited Savior
The Awaited SaviorThe Awaited Savior
The Awaited Savior
 
Cit 2008 Kindle I Phone Sdk
Cit 2008 Kindle I Phone SdkCit 2008 Kindle I Phone Sdk
Cit 2008 Kindle I Phone Sdk
 
AOC Personalisation
AOC PersonalisationAOC Personalisation
AOC Personalisation
 
Kokkuvõte 1
Kokkuvõte 1Kokkuvõte 1
Kokkuvõte 1
 
Jaka wartosc ma tresc blogow?
Jaka wartosc ma tresc blogow?Jaka wartosc ma tresc blogow?
Jaka wartosc ma tresc blogow?
 
The Roles Of Scientists
The Roles Of ScientistsThe Roles Of Scientists
The Roles Of Scientists
 
恐龍愛玩耍 戴浩政
恐龍愛玩耍  戴浩政恐龍愛玩耍  戴浩政
恐龍愛玩耍 戴浩政
 
LACA Foundation in El Salvador
LACA Foundation in El SalvadorLACA Foundation in El Salvador
LACA Foundation in El Salvador
 
KeyNote Ulster
KeyNote UlsterKeyNote Ulster
KeyNote Ulster
 
Fours And Fives
Fours And FivesFours And Fives
Fours And Fives
 
Mimas
MimasMimas
Mimas
 

Similar a Build Widgets

Javascript Frameworks for Joomla
Javascript Frameworks for JoomlaJavascript Frameworks for Joomla
Javascript Frameworks for Joomla
Luke Summerfield
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
洪 鹏发
 
LinkedIn TBC JavaScript 100: Functions
 LinkedIn TBC JavaScript 100: Functions LinkedIn TBC JavaScript 100: Functions
LinkedIn TBC JavaScript 100: Functions
Adam Crabtree
 

Similar a Build Widgets (20)

Writing Maintainable JavaScript
Writing Maintainable JavaScriptWriting Maintainable JavaScript
Writing Maintainable JavaScript
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
 
An Introduction to Celery
An Introduction to CeleryAn Introduction to Celery
An Introduction to Celery
 
Javascript Frameworks for Joomla
Javascript Frameworks for JoomlaJavascript Frameworks for Joomla
Javascript Frameworks for Joomla
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
 
[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless
 
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practices
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
Secrets of JavaScript Libraries
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Libraries
 
JavaScript Fundamentals with Angular and Lodash
JavaScript Fundamentals with Angular and LodashJavaScript Fundamentals with Angular and Lodash
JavaScript Fundamentals with Angular and Lodash
 
Clean Javascript
Clean JavascriptClean Javascript
Clean Javascript
 
2. Design patterns. part #2
2. Design patterns. part #22. Design patterns. part #2
2. Design patterns. part #2
 
meet.js - QooXDoo
meet.js - QooXDoomeet.js - QooXDoo
meet.js - QooXDoo
 
Art of Javascript
Art of JavascriptArt of Javascript
Art of Javascript
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
 
Gephi Toolkit Tutorial
Gephi Toolkit TutorialGephi Toolkit Tutorial
Gephi Toolkit Tutorial
 
Introduction to Spring MVC
Introduction to Spring MVCIntroduction to Spring MVC
Introduction to Spring MVC
 
LinkedIn TBC JavaScript 100: Functions
 LinkedIn TBC JavaScript 100: Functions LinkedIn TBC JavaScript 100: Functions
LinkedIn TBC JavaScript 100: Functions
 
Ngrx meta reducers
Ngrx meta reducersNgrx meta reducers
Ngrx meta reducers
 

Más de scottw

How to engage students in real open source projects
How to engage students in real open source projectsHow to engage students in real open source projects
How to engage students in real open source projects
scottw
 
Creating mobile web apps
Creating mobile web appsCreating mobile web apps
Creating mobile web apps
scottw
 
Dissemination beyond academic circles
Dissemination beyond academic circlesDissemination beyond academic circles
Dissemination beyond academic circles
scottw
 
Wookie Meetup
Wookie MeetupWookie Meetup
Wookie Meetup
scottw
 
Wookie Meetup
Wookie MeetupWookie Meetup
Wookie Meetup
scottw
 
CRM & HE
CRM & HECRM & HE
CRM & HE
scottw
 

Más de scottw (20)

Getting the Maximum Benefit from Free and Open Source Software
Getting the Maximum Benefit from Free and Open Source SoftwareGetting the Maximum Benefit from Free and Open Source Software
Getting the Maximum Benefit from Free and Open Source Software
 
How to engage students in real open source projects
How to engage students in real open source projectsHow to engage students in real open source projects
How to engage students in real open source projects
 
Free, Libre and Open Source Software and Further Education
Free, Libre and Open Source Software and Further EducationFree, Libre and Open Source Software and Further Education
Free, Libre and Open Source Software and Further Education
 
Open Forges and App Stores
Open Forges and App StoresOpen Forges and App Stores
Open Forges and App Stores
 
Delivering Web To Mobile
Delivering Web To MobileDelivering Web To Mobile
Delivering Web To Mobile
 
Creating mobile web apps
Creating mobile web appsCreating mobile web apps
Creating mobile web apps
 
Widgets and Mashups for Personal and Institutional Technologies
Widgets and Mashups for Personal and Institutional Technologies Widgets and Mashups for Personal and Institutional Technologies
Widgets and Mashups for Personal and Institutional Technologies
 
Open Source Junction: Apache Wookie and W3C Widgets
Open Source Junction: Apache Wookie and W3C WidgetsOpen Source Junction: Apache Wookie and W3C Widgets
Open Source Junction: Apache Wookie and W3C Widgets
 
Dissemination beyond academic circles
Dissemination beyond academic circlesDissemination beyond academic circles
Dissemination beyond academic circles
 
Android
AndroidAndroid
Android
 
Wookie Intro
Wookie IntroWookie Intro
Wookie Intro
 
Wookie Meetup
Wookie MeetupWookie Meetup
Wookie Meetup
 
Wookie Meetup
Wookie MeetupWookie Meetup
Wookie Meetup
 
Life of a Wookie
Life of a WookieLife of a Wookie
Life of a Wookie
 
CRM & HE
CRM & HECRM & HE
CRM & HE
 
Presence
PresencePresence
Presence
 
FeedForward at RSP
FeedForward at RSPFeedForward at RSP
FeedForward at RSP
 
Boxcri
BoxcriBoxcri
Boxcri
 
Widgets And Wookies
Widgets And WookiesWidgets And Wookies
Widgets And Wookies
 
Widgets - the Wookie project
Widgets - the Wookie projectWidgets - the Wookie project
Widgets - the Wookie project
 

Último

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Último (20)

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

Build Widgets

  • 1. Lets Build Some Widgets!
  • 2. Anatomy of a Widget • Config.xml <- W3C Widgets P&C Spec • icon.png • index.html <- HTML start file • JavaScript code, CSS • Zip it up, change ext to .wgt, and you’re done
  • 3. Widget metadata • Id • Height, Width • Name • Description • Version • Features • Author info • License
  • 4. A Silly Example: config.xml <?xml version="1.0" encoding="utf-8"?> <widget xmlns="http://www.w3.org/ns/widgets" id="http://www.getwookie.org/widgets/tea" version="1.0” height="150” width="125"> <name>Tea</name> <description>A silly Tea widget</description> <author>Scott Wilson</author> </widget>
  • 5. A Silly Example: index.html <html> <body> <img src="tea.jpg" /> <p>Time for a break, mate</p> </body> </html>
  • 6. Make your own basic widget 1. Make an index.html file 2. Make a config.xml file 3. Zip them up, and change suffix to “.wgt” 4. Upload to a wookie server
  • 7. Uploading • Go to http://192.168.2.161/wookie • Click “admin” • Login with java/java • Click “add new widget” • Find your .wgt file • OK!
  • 8. Previewing a widget • Go to 192.168.2.161:8080/wookie • Click “View Widget Gallery” • Click the “demo” link under your widget • Your widget will show
  • 9. Preferences • You can store preferences for an instance of a widget using: widget.preferences.setItem(“key”, “value”) widget.preferences.getItem(“key”)
  • 10. Collaborative Widgets • State and Participants • State is shared across widgets with the same IRI in the same shared context. • State is propagated to related widgets using an event callback • State is set by submitting deltas
  • 11. State example wave.setStateCallback(stateUpdated); stateUpdated = function(){ var keys = wave.getState().getKeys(); for (var i = 0; i < keys.length; i++) { alert(wave.getState().get(keys[i])); } }; wave.getState().submitValue(“key”, “value”);
  • 12. Participants • Register callbacks with: wave.setParticipantCallback(myfunction); • Methods: – getViewer() - get the current user – getParticipants() - get map of all participants • Model: – getId(), getDisplayName(), getThumbnailUrl()
  • 13. Making a collaborative app • This requires some more planning 1. Draw up a design 2. Create a working test page 3. Implement models, action handlers and event handlers 4. Create the config.xml, icon.png, zip it up and run it
  • 14. Design • Start with the view - what the widget looks like • Create the model - what are the objects in the state model? • Add the actions - how you interact with it • Wire it all up…
  • 15.
  • 16. Prototyping • Make a regular html page to test out your view. Populate it with fake model, and don’t wire up the actions yet • You can reuse this for the real widget - just take out your fake state info sections
  • 17. Implementing • Create a “Model” object for your state model • Create a “Controller” object, and a method in it for each action • Register the participant and state event handlers with an “update view” method that populates the view when running
  • 18. Models • Models can be implemented in typical “bean” fashion • Save/Find methods need to access wave state • Can use JSON (e.g. with json.js) or just plain strings for storage function Task(id,name,status,assigned){ this.task_id = id; this.name = name; this.status = status; this.assigned_to = assigned; } Task.prototype.save = function(){ wave.getState().submitValue(this.task_id, JSON.stringify(this)); }
  • 19. Static model methods Task.create = function(json){ var obj = JSON.parse(json); var task = new Task(obj.task_id, obj.name,obj.status,obj.assigned_to); return task; • Typically need } methods to turn state Task.find = function(task_id){ var keys = wave.getState().getKeys(); for (var i = 0; i < keys.length; i++) { strings back into var key = keys[i]; if (key == task_id){ model instances return Task.create(task_id, wave.getState().get(key)); } } • Also finder methods to } return null; get a particular model Task.findAll = function(){ object var tasks = {}; var keys = wave.getState().getKeys(); for (var i = 0; i < keys.length; i++) { • This isn’t the only way var key = keys[i]; var task = Task.create(key, wave.getState().get(key)); tasks[key] = task; to do this, but is an } return tasks; OK pattern }
  • 20. Controllers /** * The Controller object * This is used to wire up the view and model with actions • Methods for each */ var Controller = { action, making // Action handlers changes to the model // Toggle task state between completed and to-do toggleTask: function(task_id){ • You usually don’t }, need to do any code // Create a new task newTask: function(){ }, that interacts with // Abandon task for someone else to do HTML, as the event abandonTask: function(task_id){ }, handlers should do // Claim a task (assign to self) claimTask: function(task_id){ that } }
  • 21. Event Handlers // Update the view when state has been updated These fire whenever the state or participants stateUpdated: function(){ are updated (e.g. by another instance). var tasks = Task.findAll(); if (tasks && tasks != null){ var tasklist = ""; Event handlers need to be registered like so: for (key in tasks) { var task = tasks[key]; wave.setStateCallback(Controller.stateUpdated); wave.setParticipantCallback(Controller.participantsUpdated); tasklist += // the task stuff to show dwr.util.setValue("tasklist", tasklist, { escapeHtml:false }); Also useful to have these methods called var objDiv = document.getElementById("tasklist"); from onLoad() in an init() function to objDiv.scrollTop = objDiv.scrollHeight; create initial view } }, participantsUpdated: function(){ You can import JQuery if you like for Controller.updateUser(); setting the view content, or do it using } DOM
  • 22. Packaging You need to add this to your config.xml to tell Wookie to include the Wave Gadget API methods: <feature name="http://wave.google.com" required="true"/>
  • 23. Uploading, debugging and testing • You need a • I’ve set up a Moodle collaborative instance at: environment to test your widget properly 192.168.2.XXX Login as ws1,ws2,ws3, or ws4
  • 24. Other stuff… • AJAX • Camera access If you want to call If you want to access the external sites from user’s camera from a within the widget, call widget, there is an myurl = example of how to do widget.proxify(url) first to call it via proxy. this in the moodle Also need to add the course (topic 3) site to the server whitelist.