It is currently Mon Sep 06, 2010 6:33 pm

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Snippets -> Profile and Anchor Snippets
PostPosted: Sun Feb 07, 2010 4:16 pm 
Offline
Site Admin

Joined: Sun Feb 15, 2009 1:33 pm
Posts: 20
Below is an example of the nuances we have explored when Dynamically creating Snippets. Enjoy!

Example Assumptions:
Let's say we are firing off a request for a list of snippets we want created stored in a JSON Object. The below code assumes we are starting with the following JSON Config and then we are calling a function once we have the information to run through and attach the widget dynamic snippets.

The JSON Snippet Configs
Code:
my_snippets = {snippets:[{name:'Snippet 1'},{name:'Snippet 2'},{name:'Snippet 3'}]}

Note: The JSON list could be coming from:
- locally stored data in currentAppData.get("name-of-snippet-list")
- a network returned list values
- a hardcoded Object in a config file

Anchor Snippets
Anchor Snippets are good because they are not automatically removed when the platform switches User Profiles. Once the Widget is started they will transfer across profiles, so they do not need to be added once each Profile is "Loaded".

Uses
- Default Snippet View as required by the build requirements
- Any Snippet that will not be remove between users


Examples
Code:
//Does not work -> Not sure why.
//The Snippets will not be added to the Dock
for ( var i = 0; i < my_snippets.snippets.length; i++ )
   {
      var snippetConf = {id: 'anchorsnippet'+i, viewClass: AnchSnippets}
      KONtx.application.addViewConfig( snippetConf );
   }

//Does Work
//The Snippets will be added to the Dock.
for ( var i = 0; i < my_snippets.snippets.length; i++ )
   {
      var snippetConf = {id: 'anchorsnippet'+i, viewClass: AnchSnippets}
      KONtx.application.addViewConfig( snippetConf );
   }
KONtx.application.setProfileSnippetViews([]);
//If we add the line above to the mix the Dock will populate with the Views we just sent to the Dock with addViewConfig


ProfileSnippets
Profile Snippets are handy because they are automatically removed when the platform switches Profiles. Therefore, Profile Snippets provide an automated user management functionality that removes only the Profile Snippets when toggling between user profiles.

Uses
- Non-Default Snippet View
- Any Snippet that will be unique to a user profile
NOTE: They must be added each time the user profile is loaded, a good time to do so is during the "getSnippetConfs" event that is fired each time a user Profile is loaded.

Examples
Code:
//Does Work, but will cause the Dock to flip through the Snippets that have just been added
//The Snippets will be added to the Dock and they will flip through the Snippets and show the last Snippet added.
for ( var i = 0; i < my_snippets.snippets.length; i++ )
   {
      var snippetConf = {id: 'profilesnippet'+i, viewClass: ProSnippets}
      KONtx.application.addViewConfig( snippetConf );
   }

//The "Correct" Way to do Profile Snippets
//This will NOT cause the Dock to flip through the Snippets we adding.  The Dock will stay on the current Snippet while the other are added below.
var snippetConfs = [];
for ( var i = 0; i < my_snippets.snippets.length; i++ )
   {
      var snippetConf = {id: 'profilesnippet'+i, viewClass: ProSnippets}
      snippetConfs.push( snippetConf );
   }
KONtx.application.setProfileSnippetViews(snippetConfs);



AnchorSnippet View Creation Example
Code:
var AnchSnippets = new KONtx.Class({
   ClassName: 'ProfileSnippets',
   Extends: KONtx.system.AnchorSnippetView,
        //Insert your createView, updateView, etc for the Snippet Class
});


ProfileSnippet View Creation Example
Code:
var ProSnippets = new KONtx.Class({
   ClassName: 'ProfileSnippets',
   Extends: KONtx.system.ProfileSnippetView,
        //Insert your createView, updateView, etc for the Snippet Class
});


I hope this helps anyone that is having troubles understanding and implementing Snippet Views outside the KONtx.application.init(). :D


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Home Contact Blog Forums Press Company Case Studies