1 /**
  2  * Sourcemap.PartEditor: Handles functionality for editing, suggesting and saving new parts.
  3  *
  4  * @version 0.8
  5  * @author sourcemap@media.mit.edu
  6  * @package sourcemap
  7  * @subpackage js
  8  */
  9 
 10 /**
 11  * Create an instance of Soucemap
 12  * @see  Sourcemap
 13  */
 14 if ( typeof(Sourcemap) == 'undefined' ) {Sourcemap = {};}
 15 
 16 
 17 
 18 Sourcemap.PartEditor = {
 19   init: function() {
 20 		$("#part-list li").each(function() {
 21 			$("div.part-box", this).heatcolor( 
 22 				function() {
 23 					return Sourcemap.Util.roundIt($("span.co2val", this).text(),0)+1;
 24 				},
 25 				{ 
 26 					maxval: 20000,
 27 					minval: 0, 
 28 					reverseOrder: true,
 29 					colorStyle: 'greentored',
 30 					lightness: 0
 31 				}
 32 			);
 33 		});
 34 		
 35 		protoComment = $.template('<li class="comment"><div class="author"> <img class="authorimage" src="http://www.gravatar.com/avatar/${email}?d=identicon&s=38&r=pg" width="38" height="38"/><br/> </div> <div class="slug"> <strong>You said</strong> </div> <div class="content">${text}</div><div class="clear"></div></li> ');	
 36 		$("#submitcommentbutton").click(Sourcemap.PartEditor.saveComment);		
 37   },
 38     /**
 39      * Do an ajax call to comments controller
 40      */	
 41     saveComment: function() {
 42 	    var newComment = {
 43 		  id: $("#partid").text(),
 44 		  type: "part",		
 45 	      text: $("#submitcommentcontent").val()
 46       };
 47 	    var saveData = "data=" + JSON.stringify(newComment) + "";	
 48 	    $.post(Sourcemap.baseurl+"comments/save", saveData, Sourcemap.PartEditor.saveCommentConfirmation );
 49     },
 50 
 51     /**
 52      * Visualization for comment
 53      */
 54     saveCommentConfirmation: function(md5email) {	
 55 		$(".commentlist").prepend( protoComment , {
 56 			email: md5email,
 57 			text:$("#submitcommentcontent").val()
 58 		});
 59 	    $("#submitcommentcontent").val("");
 60 
 61     },	
 62 };
 63 
 64 $(document).ready(function() {
 65 	Sourcemap.PartEditor.init();
 66 });
 67