Commits

Scott Nixon  committed f208944

Refactored to read multi-value status cookie.

  • Participants
  • Parent commits 52a1696

Comments (0)

Files changed (1)

File inbounding/dispatch/static/in.js

 	type: 'GET',
 	dataType: 'jsonp',
 	success: function(results) {
-	    console.log("results.id: " + results.id);
 	    /* We pass the id of the action to that we can check a 
 	     * cookie to see if it has been closed or completed.
 	     */
 INBOUND.close = function() {
     /* This is used to close the overlay action box. */
     $('#ck_container').hide();
+    // Value = 101 for Closed
+    INBOUND.setCookie('ck_status', INBOUND.action_id + '=' + 101, (60*60*24*365), '/', '');
+};
+
+INBOUND.completed = function() {
+    /* This is used to close the overlay action box. */
+    $('#ck_container').hide();
     // Value = 100 for Completed
-    // Value = 101 for Closed
-    INBOUND.setCookie('ck_status', INBOUND.action_id + ',' + 101, (60*60*24*365), '/', '');
+    INBOUND.setCookie('ck_status', INBOUND.action_id + '=' + 100, (60*60*24*365), '/', '');
 };
 
 INBOUND.usereval = function(rid) {
     /* Evaluate if the user has closed or completed the Action. 
      * The ck_status cookie is only for marking a Action
      * as either completed or closed.
+     *
+     * Cookie: ck_status="4=10|43=101|234534=101"
+     * 101 = Closed; 100 = Completed
      */
 
+
     var get_status = INBOUND.getCookie('ck_status');
 
     /* Check to see if a value exits and return the status number. */
     if (get_status === null && typeof get_status === 'object')
-	status = 0;
+	status = 0; /* Status is False */
     else {
-	var values_list = get_status.split(',');
-	if (values_list[0] === rid.toString()) {
-	    var status = values_list[1];
-	    console.log("USEREVAL: " + status);
-	}
+	/* Split on the Action id delimiter */
+	var al = get_status.split('|');
+	for (var i=0; i < al.length; i++) { 
+	    /* Convert the list to a string. */
+	    var b = al.toString();
+	    /* split on the key value delimitor. */
+	    var c = b.split('=');
+	    /* The returned value is used to identify whether an action
+	     * is completed or closed. Example value 4=101; (action_id)=(status) 
+	     */
+	    var status = c[1]; 
+	} 
     }
     return status;
 };
       callback function	can then retreive the text that will be added 
       to the Client's DOM.
     */
-
     INBOUND.queryAction(INBOUND.ref_url, INBOUND.host_url, INBOUND.usereval);
     INBOUND.loadcss();
-
-    // Bind Close Event to #ck_close
-    //var b = document.getElementById('#ck_close');
-    
-
 };
 
 INBOUND.css = 'http://localhost:8000/static/css/ck_main.css?v=3';
 
 /* end Tool Library */
 
+
 (function () {
 
-    var ed = document.getElementById('ck_embed');
-    console.log(typeof ed);
-    console.log(ed);
-
     /* INIT referrer and host domain values */
     var referrer = 'digg.com'; //document.referrer;
     var dom = document.URL;
     /* SESSION LOGIC */
     var get_sess = INBOUND.getCookie("ck_session");
 
-    // Check IF SESSION exists
+    /* Check IF SESSION exists */
     if (typeof chk_uid === 'string' && get_sess && typeof get_sess === 'string') {
 	
 	/* Sends ajax request to check if an action exists for the paras */
 	INBOUND.evaluate();
 
-    } 	/* NO SESSION exits */
+    } 	
+    /* NO SESSION exits */
     else if (!get_sess) {
 
-	/********************************
-         Check HTTP referer value
-	 ********************************
-         The order of the if/else if is done based on the most to
-         least number of referrals sources expected. Local referral
-         is the most likely. 
+	/**********************************
+         * Check HTTP referer value
+	 **********************************
+         * The order of the if/else if is done based on the most to
+         * least number of referrals sources expected. Local referral
+         * is the most likely. 
 	 */
 
 
 	     * do not ever display an Action.
 	     */
 	} 
+	/* EXTERNAL REFERRALS */
 	else if (ref_list[3] !== host_list[3] && typeof ref_list === typeof host_list) { 
 	    /* If we have an external referrer we always want to write a session. 
 	     */
-	    /* EXTERNAL REFERRALS */
 	    console.log("THIS IS AN EXTERNAL REFERRAL.");
 
- 	    // Create a SESSION COOKIE
+ 	    /* Create a SESSION COOKIE */
 	    var newsession = INBOUND.makeUUID();
 	    var cval = newsession + ', referral=' + ref_list[3];
 
 
 	    var get_sess = INBOUND.getCookie('ck_session');
 	    if (get_sess && typeof get_sess === 'string') {
-		// Evaluate IF ACTION exists
+		/* Evaluate IF ACTION exists */
 		/* Sends ajax request to check if an action exists for the paras */
 		INBOUND.evaluate();