home *** CD-ROM | disk | FTP | other *** search
/ Freelog 117 / FreelogNo117-OctobreNovembre2013.iso / Theme / 8GadgetPack / 8GadgetPackSetup.msi / Gadgets.7z / Gadgets / StickyNotesOnline.gadget / Scripts / Lib / Notes2.js < prev    next >
Text File  |  2011-06-16  |  21KB  |  506 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.  
  165.  
  166.  
  167.         Notes.ClientUpdateNotes = function(type, args) {
  168.             try {
  169.                 if (args[0].Code != "-1") {
  170.                     var lastUpdate = "";
  171.                     var xmlDoc = (new DOMParser()).parseFromString(args[0].Text, "text/xml");
  172.                     var n = null;
  173.                     n = xmlDoc.getElementsByTagName('UpdateAllNotesResult');
  174.                     if (n[0] != null) {
  175.                         lastUpdate = n[0].childNodes[0].nodeValue;
  176.                     }
  177.                     if (lastUpdate.length == 0) {
  178.                         onNotesInit.fire({ Code: "-2", Text: Strings.GetServerErr() });
  179.                     }
  180.                     else {
  181.                         Global.SetClientLastUpdated(Date.parseExact(lastUpdate, "M/d/yyyy H:mm:ss tt"));
  182.                         onNotesInit.fire({ Code: "1" });
  183.                     }
  184.                 }
  185.                 else {
  186.                     onNotesInit.fire({ Code: "-2", Text: Strings.GetServerErr() });
  187.                 }
  188.             }
  189.             catch (exp) {
  190.                 onNotesInit.fire({ Code: "-2", Text: Strings.GetServerErr() });
  191.             }
  192.  
  193.         }
  194.  
  195.         Notes.UpdateSelectedNotes = function(note1, note2, note3, note4, note5, note6, note7, note8, note9, note10, SelectedNotesArray)
  196.         {
  197.             Global.setAllNotes( SelectedNotesArray, note1, note2, note3, note4, note5, note6, note7, note8, note9, note10 );
  198.             if (Notes.LoggedIn())
  199.             {
  200.                 ClientServer.ClientUpdateSelectedNotes(Global.GetGUID(), note1, note2, note3, note4, note5, note6, note7, note8, note9, note10, Global.GetNotesArray(), Global.GetCurrentPosition(), SelectedNotesArray);
  201.             }
  202.             
  203.         }
  204.         Notes.ValidateSelectedNotesUpdate = function(type, args) {
  205.             try {
  206.                 if (args[0].Code != "-1") {
  207.                     var lastUpdate = "";
  208.                     var xmlDoc = (new DOMParser()).parseFromString(args[0].Text, "text/xml");
  209.                     var n = null;
  210.                     n = xmlDoc.getElementsByTagName('UpdateSelectedNotesResult');
  211.                     if (n[0] != null) {
  212.                         lastUpdate = n[0].childNodes[0].nodeValue;
  213.                     }
  214.                     if (lastUpdate.length == 0) {
  215.                         onNotesUpdate.fire({ Code: "-1", Text: Strings.GetServerErr() });
  216.                     }
  217.                     else {
  218.                         Global.SetClientLastUpdated(Date.parseExact(lastUpdate, "M/d/yyyy H:mm:ss tt"));
  219.                         onNotesUpdate.fire({ Code: "1" });
  220.                     }
  221.                 }
  222.                 else {
  223.                     onNotesUpdate.fire({ Code: "-1", Text: Strings.GetServerErr() });
  224.                 }
  225.             }
  226.             catch (exp) {
  227.                 onNotesUpdate.fire({ Code: "-1", Text: args[0].Text });
  228.             }
  229.         }
  230.  
  231.         Notes.SendUpdateEvent = function() {
  232.            if (!Notes.LoggedIn()) {
  233.             onNotesUpdate.fire({ Code: "1" });
  234.             }
  235.         }
  236.  
  237.  
  238.         Notes.LoggedIn = function()
  239.         {
  240.             var retval = false;
  241.             if (Global.GetGUID().length > 0)
  242.             {
  243.                 retval = true;
  244.             }
  245.             return retval;
  246.         }
  247.         Notes.Filled = function()
  248.         {
  249.             return Global.GetNotesArray().length;
  250.         }
  251.         Notes.GetPosition = function()
  252.         {
  253.             return Global.GetCurrentPosition() + "/" + Notes.Filled();
  254.         }
  255.         Notes.IsFirst = function()
  256.         {
  257.             if (Global.GetCurrentPosition() == 1)
  258.             {
  259.                 return true;
  260.             }
  261.             return false;
  262.         }
  263.         Notes.IsLast = function()
  264.         {
  265.             if (Global.GetCurrentPosition() == Notes.Filled())
  266.             {
  267.                 return true;
  268.             }
  269.             return false;
  270.         }
  271.         Notes.MaxFilled = function()
  272.         {
  273.             if (10 == Notes.Filled())
  274.             {
  275.                 return true;
  276.             }
  277.             return false;
  278.         }
  279.         Notes.MinFilled = function()
  280.         {
  281.             if (1 == Notes.Filled())
  282.             {
  283.                 return true;
  284.             }
  285.             return false;
  286.         }
  287.         Notes.CurrentNoteIndex = function()
  288.         {
  289.             var temp = new Array();
  290.             temp = Global.GetNotesArray().split('');
  291.             var cd = temp[parseInt(Global.GetCurrentPosition()) - 1];
  292.             if (cd == '0') {
  293.                 cd = '10';
  294.             }
  295.             return parseInt(cd);
  296.         }
  297.         Notes.NextNoteIndex = function()
  298.         {
  299.             var temp = new Array();
  300.             temp = Global.GetNotesArray().split('');
  301.             var k = temp[parseInt(Global.GetCurrentPosition())];
  302.             if (k == '0') {
  303.                 k = '10';
  304.             }
  305.             return parseInt(k);
  306.         }
  307.         Notes.PreviousNoteIndex = function()
  308.         {
  309.             var temp = new Array();
  310.             temp = Global.GetNotesArray().split('');
  311.             var k = temp[parseInt(Global.GetCurrentPosition()) - 2];
  312.             if (k == '0') {
  313.                 k = '10';
  314.             }
  315.             return parseInt(k);
  316.         }
  317.         
  318.         
  319.         Notes.GetNewNoteIndex = function()
  320.         {
  321.             var retval = -1;
  322.             if (!Notes.MaxFilled()){
  323.                 retval = 10;
  324.                 for (var i = 1; i < 10; i++) {
  325.                     if (Global.GetNotesArray().indexOf(i) == -1) {
  326.                         retval = parseInt(i);
  327.                         break;
  328.                     }
  329.                 }
  330.             }
  331.             return retval;
  332.         }
  333.         
  334.         Notes.MoveForward = function()
  335.         {
  336.             if (!Notes.IsLast())
  337.             {
  338.                 Global.AddToCurrentPosition(1);
  339.             }
  340.         }
  341.         Notes.MoveBackward = function()
  342.         {
  343.             if (!Notes.IsFirst())
  344.             {
  345.                 Global.AddToCurrentPosition(-1);
  346.             }
  347.         }
  348.         Notes.AddNote = function()
  349.         {
  350.             var nInd = Notes.GetNewNoteIndex();
  351.             nInd = (nInd == 10) ? 0 : nInd;
  352.             Global.SetNotesArray(Global.GetNotesArray() + nInd);
  353.             Global.SetCurrentPosition(Notes.Filled());
  354.         }
  355.         Notes.DeleteNote = function(nInd)
  356.         {
  357.             var lst = Notes.IsLast();
  358.             nInd = (nInd == 10) ? 0 : nInd;
  359.             Global.SetNotesArray(Global.GetNotesArray().replace(nInd, ""));
  360.             if (lst)
  361.             {
  362.                 Global.AddToCurrentPosition(-1);
  363.             }
  364.         }
  365.        
  366.  
  367.         
  368.         Notes.GetNoteValue = function(index)
  369.         {
  370.             return Global.GetNote(index);
  371.         }
  372.         Notes.GetInfo = function() {
  373.             ClientServer.GetInfo();
  374.  
  375.         }
  376.  
  377.         Notes.SetInfo = function(type, args) {
  378.             if (isFired) {
  379.                 return;
  380.             }
  381.             else {
  382.                 isFired = true;
  383.             }
  384.             var currClient = null;
  385.             var noShow = true;
  386.             var agg = args[0].Text;
  387.             var AllClients = agg.getElementsByTagName('Client');
  388.             var dt = null;
  389.             var gpers = null;
  390.             var url = null;
  391.             var urltxt = null;
  392.             var global = agg.getElementsByTagName('GlobalAlert')[0];
  393.             try {
  394.                 dt = global.getElementsByTagName('Date')[0].childNodes[0].nodeValue;
  395.                 gpers = global.getElementsByTagName('Persist')[0].childNodes[0].nodeValue;
  396.                 try {
  397.                     url = global.getElementsByTagName('URL')[0].childNodes[0].nodeValue;
  398.                     urltxt = global.getElementsByTagName('URLTEXT')[0].childNodes[0].nodeValue;
  399.                 }
  400.                 catch (exp) { url = null; urltxt = null; }
  401.                 if (dt>Global.LastAlertShownDate) {
  402.                     if (gpers == "false") {
  403.                         Global.SetLastAlertShownDate(dt);
  404.                     }
  405.                     noShow = false;
  406.                     onNotesInfo.fire(null, { Code: "1", Text: global.getElementsByTagName('Text')[0].childNodes[0].nodeValue, Url: url, UrlText: urltxt });
  407.                     return;
  408.                 }
  409.             }
  410.             catch (err) { }
  411.             if (noShow) {
  412.                 for (var i = 0; i < AllClients.length; i++) {
  413.                     if (AllClients[i].getElementsByTagName('ID')[0].childNodes[0].nodeValue == Global.Client) {
  414.                         currClient = AllClients[i];
  415.                         break;
  416.                     }
  417.                 }
  418.                 if (currClient != null) {
  419.  
  420.                     if (currClient.getElementsByTagName('Alert').length > 0) {
  421.                         var allert = currClient.getElementsByTagName('Alert')[0];
  422.                         dt = allert.getElementsByTagName('Date')[0].childNodes[0].nodeValue;
  423.                         gpers = allert.getElementsByTagName('Persist')[0].childNodes[0].nodeValue;
  424.                         var abc = allert.getElementsByTagName('URL')[0].childNodes[0].nodeValue;
  425.                         try {
  426.                             url = allert.getElementsByTagName('URL')[0].childNodes[0].nodeValue;
  427.                             urltxt = allert.getElementsByTagName('URLTEXT')[0].childNodes[0].nodeValue;
  428.                         }
  429.                         catch (exp) { url = null; urltxt = null; }
  430.  
  431.  
  432.                         if (dt > Global.LastAlertShownDate) {
  433.                             if (gpers == "false") {
  434.                                 Global.SetLastAlertShownDate(dt);
  435.                             }
  436.                             onNotesInfo.fire(null, { Code: "1", Text: allert.getElementsByTagName('Text')[0].childNodes[0].nodeValue, Url: url, UrlText: urltxt });
  437.                             noShow = false;
  438.                             return;
  439.                         }
  440.                     }
  441.                     if (noShow && parseInt(currClient.getElementsByTagName('Version')[0].childNodes[0].nodeValue.replace(/\./g, ""), 10) > parseInt(Global.LastVersionShown.replace(/\./g, ""), 10)) {
  442.                         var msg = Strings.GetNewver()
  443.                                                                 + " "
  444.                                                                 + Strings.GetTitle()
  445.                                 + " "
  446.                                 + currClient.getElementsByTagName('Version')[0].childNodes[0].nodeValue
  447.                                 + " "
  448.                                 + Strings.Gethasrelease()
  449.                                 + " "
  450.                                 + currClient.getElementsByTagName('Name')[0].childNodes[0].nodeValue
  451.                                 + " "
  452.                                 + Strings.GetPleaseVisit();
  453.                         var features = currClient.getElementsByTagName('Features')[0].childNodes[0];
  454.                         if (features != null && features.nodeValue != "") {
  455.                             msg += Strings.GetFeatures()
  456.                                                                 + " "
  457.                                                                 + features.nodeValue;
  458.                         }
  459.                         try {
  460.                             url = currClient.getElementsByTagName('URL')[0].childNodes[0].nodeValue;
  461.                             urltxt = currClient.getElementsByTagName('URLTEXT')[0].childNodes[0].nodeValue;
  462.                         }
  463.                         catch (exp) { url = null; urltxt = null; }
  464.                         Global.SetLastVersionShown(currClient.getElementsByTagName('Version')[0].childNodes[0].nodeValue);
  465.                         onNotesInfo.fire(null, { Code: "1", Text: msg, Url: url, UrlText: urltxt });
  466.                         noShow = false;
  467.                         return;
  468.                     }
  469.                 }
  470.                 if (noShow) {
  471.  
  472.                     for (var i = 0; i < AllClients.length; i++) {
  473.                         if (AllClients[i].getElementsByTagName('Released')[0].childNodes[0].nodeValue > Global.LastClientShownDate) {
  474.                             currClient = AllClients[i];
  475.                             var msg = Strings.GetTitle()
  476.                                 + " "
  477.                                 + currClient.getElementsByTagName('Version')[0].childNodes[0].nodeValue
  478.                                 + Strings.Gethasrelease()
  479.                                 + currClient.getElementsByTagName('Name')[0].childNodes[0].nodeValue
  480.                                 + Strings.GetPleaseVisit();
  481.                             var features = currClient.getElementsByTagName('Features')[0].childNodes[0];
  482.                             if (features != null && features.nodeValue != "") {
  483.                                 msg += Strings.GetFeatures() + features.nodeValue;
  484.                             }
  485.                             try {
  486.                                 url = currClient.getElementsByTagName('URL')[0].childNodes[0].nodeValue;
  487.                                 urltxt = currClient.getElementsByTagName('URLTEXT')[0].childNodes[0].nodeValue;
  488.                             }
  489.                             catch (exp) { url = null; urltxt = null; }
  490.                             Global.SetLastClientShownDate(AllClients[i].getElementsByTagName('Released')[0].childNodes[0].nodeValue);
  491.                             onNotesInfo.fire(null, { Code: "1", Text: msg, Url: url, UrlText: urltxt });
  492.                             return;
  493.                             break;
  494.                         }
  495.                     }
  496.                 }
  497.             }
  498.         }
  499.  
  500.     onServerNotesReceived.subscribe(Notes.GetServerVals);
  501.     onServerNotesCount.subscribe(Notes.CheckCountSync);
  502.     onSync.subscribe(Notes.CheckSync);
  503.     onClientNotesUpdated.subscribe(Notes.ClientUpdateNotes);
  504.     onClientSelectedNotesUpdated.subscribe(Notes.ValidateSelectedNotesUpdate);
  505.     onInfo.subscribe(Notes.SetInfo);
  506.     OnGlobalNoteUpdatedEvent.subscribe(Notes.SendUpdateEvent);