home *** CD-ROM | disk | FTP | other *** search
/ Freelog 117 / FreelogNo117-OctobreNovembre2013.iso / Theme / 8GadgetPack / 8GadgetPackSetup.msi / Gadgets.7z / Gadgets / StickyNotesOnline.gadget / Scripts / Lib / Notes.js < prev    next >
Text File  |  2011-06-16  |  21KB  |  500 lines

  1. ∩╗┐function Notes() { }
  2.         var onNotesInit = new YAHOO.util.CustomEvent('onNotesInit');
  3.         var onNotesUpdate = new YAHOO.util.CustomEvent('onNotesUpdate');
  4.         var onNotesInfo = new YAHOO.util.CustomEvent('onNotesInfo');
  5.         var isFired = false;
  6.         /// <summary>
  7.         /// Initialize Notes Client
  8.         /// </summary>
  9.         /// <param name="initval">1 for checksync
  10.         /// 2 for GetServerVals
  11.         /// 3 for ClientUpdateNotes
  12.         /// 4 for CheckCountSync</param>
  13.         /// <returns></returns>
  14.         Notes.Init = function(initval) {
  15.             if (Notes.LoggedIn()) {
  16.                 switch (initval) {
  17.                     case 0:
  18.                         onNotesInit.fire({ Code: "1" });
  19.                         break;
  20.                     case 1:
  21.                         ClientServer.CheckSync(Global.GetGUID());
  22.  
  23.                         break;
  24.                     case 2:
  25.                         ClientServer.GetServerVals(Global.GetGUID(), Global.Client);
  26.                         break;
  27.                     case 3:
  28.                         ClientServer.ClientUpdateNotes(Global.GetGUID(),
  29.                                 Global.GetNote(1),
  30.                                 Global.GetNote(2),
  31.                                 Global.GetNote(3),
  32.                                 Global.GetNote(4),
  33.                                 Global.GetNote(5),
  34.                                 Global.GetNote(6),
  35.                                 Global.GetNote(7),
  36.                                 Global.GetNote(8),
  37.                                 Global.GetNote(9),
  38.                                 Global.GetNote(10),
  39.                                 Global.GetNotesArray(),
  40.                                 Global.GetCurrentPosition());
  41.                         break;
  42.                     case 4:
  43.                         
  44.                         if (Global.AllNotesCount() == 0) {
  45.                             ClientServer.GetServerVals(Global.GetGUID(), Global.Client);
  46.                         }
  47.                         else {
  48.                             ClientServer.GetServerNoteCount(Global.Client, Global.GetGUID());
  49.                         }
  50.                         break;
  51.                 }
  52.             }
  53.             else {
  54.                 onNotesInit.fire({ Code: "1" });
  55.             }
  56.         }
  57.  
  58.         Notes.GetServerVals = function(type, args) {
  59.             if (args[0].Code != "-1") {
  60.                 try {
  61.                     var xmlDoc = (new DOMParser()).parseFromString(args[0].Text, "text/xml");
  62.                     var n = null;
  63.                     xmlDoc = (new DOMParser()).parseFromString(xmlDoc.getElementsByTagName('GetNotesToSecResult')[0].childNodes[0].nodeValue, "text/xml");
  64.  
  65.                     for (var i = 1; i < 11; i++) {
  66.                         Global.SetNote(i, "");
  67.                         n = xmlDoc.getElementsByTagName('note' + i);
  68.                         if (n[0] != null && n[0].childNodes[0] != null) {
  69.                             Global.SetNote(i, n[0].childNodes[0].nodeValue);
  70.                         }
  71.                     }
  72.                     n = xmlDoc.getElementsByTagName('noteCurrent');
  73.                     if (n[0] != null) {
  74.                         Global.SetCurrentPosition(n[0].childNodes[0].nodeValue);
  75.                     }
  76.                     n = xmlDoc.getElementsByTagName('noteCount');
  77.                     if (n[0] != null) {
  78.                         Global.SetNotesArray(n[0].childNodes[0].nodeValue);
  79.                     }
  80.                     n = xmlDoc.getElementsByTagName('lastupdate');
  81.                     if (n[0] != null) {
  82.                         var dt = n[0].childNodes[0].nodeValue;
  83.                         try {
  84.                             dt = dt.split(".")[0];
  85.                             dt = dt.replace("T", " ");
  86.                             dt = Date.parseExact(dt, "yyyy-MM-dd HH:mm:ss");
  87.                         }
  88.                         catch (err) { }
  89.                         Global.SetClientLastUpdated(dt);
  90.                     }
  91.                     onNotesInit.fire({ Code: "1" });
  92.                 }
  93.                 catch (exp) {
  94.                     onNotesInit.fire({ Code: "-1", Text: Strings.GetServerErr() });
  95.  
  96.                 }
  97.  
  98.             }
  99.         }
  100.  
  101.         Notes.CheckCountSync = function(type, args) {
  102.             try {
  103.                 if (args[0].Code != "-1") {
  104.                     if (args[0].Text.indexOf("<op>") == -1) {
  105.                         onNotesInit.fire({ Code: "-1", Text: Strings.GetServerErr() });
  106.                     }
  107.                     else {
  108.                         var response = args[0].Text.replace("<op>", "").replace("</op>", "");
  109.                         if (response == "-1") {
  110.                             onNotesInit.fire({ Code: "-1", Text: Strings.GetServerErr() });
  111.                         }
  112.                         else {
  113.                             var servNtCnt = parseInt(response);
  114.                             
  115.                             if (servNtCnt == Global.AllNotesCount()) {
  116.                                 ClientServer.GetServerVals(Global.GetGUID(), Global.Client);
  117.                                 return;
  118.                             }
  119.                             else {
  120.                                 onNotesInit.fire({ Code: "2", Text: Strings.GetClientGreater() });
  121.                             }
  122.                         }
  123.                     }
  124.                 }
  125.             }
  126.             catch (exp) {
  127.                 onNotesInit.fire({ Code: "-1", Text: Strings.GetServerErr() });
  128.             }
  129.         }
  130.         Notes.CheckSync = function(type, args) {
  131.             try {
  132.                 if (args[0].Code != "-1") {
  133.                     var response = args[0].Text;
  134.                     if (response == "-1") {
  135.                         onNotesInit.fire({ Code: "-1", Text: Strings.GetServerErr() });
  136.                     }
  137.                     else {
  138.                         var dt = Date.parseExact(response, "M/d/yyyy H:mm:ss tt");
  139.  
  140.                         if (Global.GetClientLastUpdated() == "") {
  141.                             Notes.Init(4);
  142.                             return;
  143.                         }
  144.  
  145.                         var dt2 = new Date(Global.GetClientLastUpdated());
  146.  
  147.                         if (dt > dt2) {
  148.                             onNotesInit.fire({ Code: "2", Text: Strings.GetServerGreater() });
  149.                         }
  150.                         else {
  151.                             onNotesInit.fire({ Code: "3" });
  152.                         }
  153.                     }
  154.                 }
  155.                 else {
  156.                     onNotesInit.fire({ Code: "-1", Text: Strings.GetServerErr() });
  157.                 }
  158.             }
  159.             catch (exp) {
  160.                 onNotesInit.fire({ Code: "-1", Text: Strings.GetServerErr() });
  161.             }
  162.         }
  163.  
  164.         Notes.ClientUpdateNotes = function(type, args) {
  165.             try {
  166.                 if (args[0].Code != "-1") {
  167.                     var lastUpdate = "";
  168.                     var xmlDoc = (new DOMParser()).parseFromString(args[0].Text, "text/xml");
  169.                     var n = null;
  170.                     n = xmlDoc.getElementsByTagName('UpdateAllNotesResult');
  171.                     if (n[0] != null) {
  172.                         lastUpdate = n[0].childNodes[0].nodeValue;
  173.                     }
  174.                     if (lastUpdate.length == 0) {
  175.                         onNotesInit.fire({ Code: "-2", Text: Strings.GetServerErr() });
  176.                     }
  177.                     else {
  178.                         Global.SetClientLastUpdated(Date.parseExact(lastUpdate, "M/d/yyyy H:mm:ss tt"));
  179.                         onNotesInit.fire({ Code: "1" });
  180.                     }
  181.                 }
  182.                 else {
  183.                     onNotesInit.fire({ Code: "-2", Text: Strings.GetServerErr() });
  184.                 }
  185.             }
  186.             catch (exp) {
  187.                 onNotesInit.fire({ Code: "-2", Text: Strings.GetServerErr() });
  188.             }
  189.  
  190.         }
  191.  
  192.         Notes.UpdateSelectedNotes = function(note1, note2, note3, note4, note5, note6, note7, note8, note9, note10, SelectedNotesArray)
  193.         {
  194.             Global.setAllNotes( SelectedNotesArray, note1, note2, note3, note4, note5, note6, note7, note8, note9, note10 );
  195.             if (Notes.LoggedIn())
  196.             {
  197.                 ClientServer.ClientUpdateSelectedNotes(Global.GetGUID(), note1, note2, note3, note4, note5, note6, note7, note8, note9, note10, Global.GetNotesArray(), Global.GetCurrentPosition(), SelectedNotesArray);
  198.             }
  199.             
  200.         }
  201.         Notes.ValidateSelectedNotesUpdate = function(type, args) {
  202.             try {
  203.                 if (args[0].Code != "-1") {
  204.                     var lastUpdate = "";
  205.                     var xmlDoc = (new DOMParser()).parseFromString(args[0].Text, "text/xml");
  206.                     var n = null;
  207.                     n = xmlDoc.getElementsByTagName('UpdateSelectedNotesResult');
  208.                     if (n[0] != null) {
  209.                         lastUpdate = n[0].childNodes[0].nodeValue;
  210.                     }
  211.                     if (lastUpdate.length == 0) {
  212.                         onNotesUpdate.fire({ Code: "-1", Text: Strings.GetServerErr() });
  213.                     }
  214.                     else {
  215.                         Global.SetClientLastUpdated(Date.parseExact(lastUpdate, "M/d/yyyy H:mm:ss tt"));
  216.                         onNotesUpdate.fire({ Code: "1" });
  217.                     }
  218.                 }
  219.                 else {
  220.                     onNotesUpdate.fire({ Code: "-1", Text: Strings.GetServerErr() });
  221.                 }
  222.             }
  223.             catch (exp) {
  224.                 onNotesUpdate.fire({ Code: "-1", Text: args[0].Text });
  225.             }
  226.         }
  227.  
  228.         Notes.SendUpdateEvent = function() {
  229.            if (!Notes.LoggedIn()) {
  230.             onNotesUpdate.fire({ Code: "1" });
  231.             }
  232.         }
  233.  
  234.  
  235.         Notes.LoggedIn = function()
  236.         {
  237.             var retval = false;
  238.             if (Global.GetGUID().length > 0)
  239.             {
  240.                 retval = true;
  241.             }
  242.             return retval;
  243.         }
  244.         Notes.Filled = function()
  245.         {
  246.             return Global.GetNotesArray().length;
  247.         }
  248.         Notes.GetPosition = function()
  249.         {
  250.             return Global.GetCurrentPosition() + "/" + Notes.Filled();
  251.         }
  252.         Notes.IsFirst = function()
  253.         {
  254.             if (Global.GetCurrentPosition() == 1)
  255.             {
  256.                 return true;
  257.             }
  258.             return false;
  259.         }
  260.         Notes.IsLast = function()
  261.         {
  262.             if (Global.GetCurrentPosition() == Notes.Filled())
  263.             {
  264.                 return true;
  265.             }
  266.             return false;
  267.         }
  268.         Notes.MaxFilled = function()
  269.         {
  270.             if (10 == Notes.Filled())
  271.             {
  272.                 return true;
  273.             }
  274.             return false;
  275.         }
  276.         Notes.MinFilled = function()
  277.         {
  278.             if (1 == Notes.Filled())
  279.             {
  280.                 return true;
  281.             }
  282.             return false;
  283.         }
  284.         Notes.CurrentNoteIndex = function()
  285.         {
  286.             var temp = new Array();
  287.             temp = Global.GetNotesArray().split('');
  288.             var cd = temp[parseInt(Global.GetCurrentPosition()) - 1];
  289.             if (cd == '0') {
  290.                 cd = '10';
  291.             }
  292.             return parseInt(cd);
  293.         }
  294.         Notes.NextNoteIndex = function()
  295.         {
  296.             var temp = new Array();
  297.             temp = Global.GetNotesArray().split('');
  298.             var k = temp[parseInt(Global.GetCurrentPosition())];
  299.             if (k == '0') {
  300.                 k = '10';
  301.             }
  302.             return parseInt(k);
  303.         }
  304.         Notes.PreviousNoteIndex = function()
  305.         {
  306.             var temp = new Array();
  307.             temp = Global.GetNotesArray().split('');
  308.             var k = temp[parseInt(Global.GetCurrentPosition()) - 2];
  309.             if (k == '0') {
  310.                 k = '10';
  311.             }
  312.             return parseInt(k);
  313.         }
  314.         Notes.GetNewNoteIndex = function()
  315.         {
  316.             var retval = -1;
  317.             if (!Notes.MaxFilled()){
  318.                 retval = 10;
  319.                 for (var i = 1; i < 10; i++) {
  320.                     if (Global.GetNotesArray().indexOf(i) == -1) {
  321.                         retval = parseInt(i);
  322.                         break;
  323.                     }
  324.                 }
  325.             }
  326.             return retval;
  327.         }
  328.         
  329.         Notes.MoveForward = function()
  330.         {
  331.             if (!Notes.IsLast())
  332.             {
  333.                 Global.AddToCurrentPosition(1);
  334.             }
  335.         }
  336.         Notes.MoveBackward = function()
  337.         {
  338.             if (!Notes.IsFirst())
  339.             {
  340.                 Global.AddToCurrentPosition(-1);
  341.             }
  342.         }
  343.         Notes.AddNote = function()
  344.         {
  345.             var nInd = Notes.GetNewNoteIndex();
  346.             nInd = (nInd == 10) ? 0 : nInd;
  347.             Global.SetNotesArray(Global.GetNotesArray() + nInd);
  348.             Global.SetCurrentPosition(Notes.Filled());
  349.         }
  350.         Notes.DeleteNote = function(nInd)
  351.         {
  352.             var lst = Notes.IsLast();
  353.             nInd = (nInd == 10) ? 0 : nInd;
  354.             Global.SetNotesArray(Global.GetNotesArray().replace(nInd, ""));
  355.             if (lst)
  356.             {
  357.                 Global.AddToCurrentPosition(-1);
  358.             }
  359.         }
  360.         Notes.GetNoteValue = function(index)
  361.         {
  362.             return Global.GetNote(index);
  363.         }
  364.         Notes.GetInfo = function() {
  365.             ClientServer.GetInfo();
  366.  
  367.         }
  368.  
  369.         Notes.SetInfo = function(type, args) {
  370.             if (isFired) {
  371.                 //return;
  372.             }
  373.             else {
  374.                 isFired = true;
  375.             }
  376.             
  377.             var currClient = null;
  378.             var noShow = true;
  379.             var agg = args[0].Text;
  380.             var AllClients = agg.getElementsByTagName('Client');
  381.             var dt = null;
  382.             var gpers = null;
  383.             var url = null;
  384.             var urltxt = null;
  385.             var global = agg.getElementsByTagName('GlobalAlert')[0];
  386.             try {
  387.                 dt = global.getElementsByTagName('Date')[0].childNodes[0].nodeValue;
  388.                 gpers = global.getElementsByTagName('Persist')[0].childNodes[0].nodeValue;
  389.                 try {
  390.                     url = global.getElementsByTagName('URL')[0].childNodes[0].nodeValue;
  391.                     urltxt = global.getElementsByTagName('URLTEXT')[0].childNodes[0].nodeValue;
  392.                 }
  393.                 catch (exp) { url = null; urltxt = null; }
  394.                 if (Date.parse(dt) > Date.parse(Global.LastAlertShownDate)) {
  395.                     if (gpers == "false") {
  396.                         Global.SetLastAlertShownDate(dt);
  397.                     }
  398.                     noShow = false;
  399.                     
  400.                     onNotesInfo.fire({ Code: "1", Text: global.getElementsByTagName('Text')[0].childNodes[0].nodeValue, Url: url, UrlText: urltxt });
  401.                     return;
  402.                 }
  403.             }
  404.             catch (err) { }
  405.             if (noShow) {
  406.                 for (var i = 0; i < AllClients.length; i++) {
  407.                     if (AllClients[i].getElementsByTagName('ID')[0].childNodes[0].nodeValue == Global.Client) {
  408.                         currClient = AllClients[i];
  409.                         break;
  410.                     }
  411.                 }
  412.                 if (currClient != null) {
  413.  
  414.                     if (currClient.getElementsByTagName('Alert').length > 0) {
  415.                         var allert = currClient.getElementsByTagName('Alert')[0];
  416.                         dt = allert.getElementsByTagName('Date')[0].childNodes[0].nodeValue;
  417.                         gpers = allert.getElementsByTagName('Persist')[0].childNodes[0].nodeValue;
  418.                         var abc = allert.getElementsByTagName('URL')[0].childNodes[0].nodeValue;
  419.                         try {
  420.                             url = allert.getElementsByTagName('URL')[0].childNodes[0].nodeValue;
  421.                             urltxt = allert.getElementsByTagName('URLTEXT')[0].childNodes[0].nodeValue;
  422.                         }
  423.                         catch (exp) { url = null; urltxt = null; }
  424.  
  425.                         if (Date.parse(dt) > Date.parse(Global.LastAlertShownDate)) {
  426.                             if (gpers == "false") {
  427.                                 Global.SetLastAlertShownDate(dt);
  428.                             }
  429.                             onNotesInfo.fire({ Code: "1", Text: allert.getElementsByTagName('Text')[0].childNodes[0].nodeValue, Url: url, UrlText: urltxt });
  430.                             noShow = false;
  431.                             return;
  432.                         }
  433.                     }
  434.                     if (noShow && parseInt(currClient.getElementsByTagName('Version')[0].childNodes[0].nodeValue.replace(/\./g, ""), 10) > parseInt(Global.LastVersionShown.replace(/\./g, ""), 10)) {
  435.                         var msg = Strings.GetNewver()
  436.                                                                 + " "
  437.                                                                 + Strings.GetTitle()
  438.                                 + " "
  439.                                 + currClient.getElementsByTagName('Version')[0].childNodes[0].nodeValue
  440.                                 + " "
  441.                                 + Strings.Gethasrelease()
  442.                                 + " "
  443.                                 + currClient.getElementsByTagName('Name')[0].childNodes[0].nodeValue
  444.                                 + " "
  445.                                 + Strings.GetPleaseVisit();
  446.                         var features = currClient.getElementsByTagName('Features')[0].childNodes[0];
  447.                         if (features != null && features.nodeValue != "") {
  448.                             msg += Strings.GetFeatures()
  449.                                                                 + " "
  450.                                                                 + features.nodeValue;
  451.                         }
  452.                         try {
  453.                             url = currClient.getElementsByTagName('URL')[0].childNodes[0].nodeValue;
  454.                             urltxt = currClient.getElementsByTagName('URLTEXT')[0].childNodes[0].nodeValue;
  455.                         }
  456.                         catch (exp) { url = null; urltxt = null; }
  457.                         Global.SetLastVersionShown(currClient.getElementsByTagName('Version')[0].childNodes[0].nodeValue);
  458.                         onNotesInfo.fire({ Code: "1", Text: msg, Url: url, UrlText: urltxt });
  459.                         noShow = false;
  460.                         return;
  461.                     }
  462.                 }
  463.                 if (noShow) {
  464.  
  465.                     for (var i = 0; i < AllClients.length; i++) {
  466.                         if (Date.parse(AllClients[i].getElementsByTagName('Released')[0].childNodes[0].nodeValue) > Date.parse(Global.LastClientShownDate)) {
  467.                             currClient = AllClients[i];
  468.                             var msg = Strings.GetTitle()
  469.                                 + " "
  470.                                 + currClient.getElementsByTagName('Version')[0].childNodes[0].nodeValue
  471.                                 + Strings.Gethasrelease()
  472.                                 + currClient.getElementsByTagName('Name')[0].childNodes[0].nodeValue
  473.                                 + Strings.GetPleaseVisit();
  474.                             var features = currClient.getElementsByTagName('Features')[0].childNodes[0];
  475.                             if (features != null && features.nodeValue != "") {
  476.                                 msg += Strings.GetFeatures() + features.nodeValue;
  477.                             }
  478.                             try {
  479.                                 url = currClient.getElementsByTagName('URL')[0].childNodes[0].nodeValue;
  480.                                 urltxt = currClient.getElementsByTagName('URLTEXT')[0].childNodes[0].nodeValue;
  481.                             }
  482.                             catch (exp) { url = null; urltxt = null; }
  483.                             Global.SetLastClientShownDate(AllClients[i].getElementsByTagName('Released')[0].childNodes[0].nodeValue);
  484.                             onNotesInfo.fire({ Code: "1", Text: msg, Url: url, UrlText: urltxt });
  485.                             return;
  486.                             break;
  487.                         }
  488.                     }
  489.                 }
  490.             }
  491.         }
  492.  
  493.  
  494.     onServerNotesReceived.subscribe(Notes.GetServerVals);
  495.     onServerNotesCount.subscribe(Notes.CheckCountSync);
  496.     onSync.subscribe(Notes.CheckSync);
  497.     onClientNotesUpdated.subscribe(Notes.ClientUpdateNotes);
  498.     onClientSelectedNotesUpdated.subscribe(Notes.ValidateSelectedNotesUpdate);
  499.     onInfo.subscribe(Notes.SetInfo);
  500.     OnGlobalNoteUpdatedEvent.subscribe(Notes.SendUpdateEvent);