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 >
Wrap
Text File
|
2011-06-16
|
21KB
|
500 lines
function Notes() { }
var onNotesInit = new YAHOO.util.CustomEvent('onNotesInit');
var onNotesUpdate = new YAHOO.util.CustomEvent('onNotesUpdate');
var onNotesInfo = new YAHOO.util.CustomEvent('onNotesInfo');
var isFired = false;
/// <summary>
/// Initialize Notes Client
/// </summary>
/// <param name="initval">1 for checksync
/// 2 for GetServerVals
/// 3 for ClientUpdateNotes
/// 4 for CheckCountSync</param>
/// <returns></returns>
Notes.Init = function(initval) {
if (Notes.LoggedIn()) {
switch (initval) {
case 0:
onNotesInit.fire({ Code: "1" });
break;
case 1:
ClientServer.CheckSync(Global.GetGUID());
break;
case 2:
ClientServer.GetServerVals(Global.GetGUID(), Global.Client);
break;
case 3:
ClientServer.ClientUpdateNotes(Global.GetGUID(),
Global.GetNote(1),
Global.GetNote(2),
Global.GetNote(3),
Global.GetNote(4),
Global.GetNote(5),
Global.GetNote(6),
Global.GetNote(7),
Global.GetNote(8),
Global.GetNote(9),
Global.GetNote(10),
Global.GetNotesArray(),
Global.GetCurrentPosition());
break;
case 4:
if (Global.AllNotesCount() == 0) {
ClientServer.GetServerVals(Global.GetGUID(), Global.Client);
}
else {
ClientServer.GetServerNoteCount(Global.Client, Global.GetGUID());
}
break;
}
}
else {
onNotesInit.fire({ Code: "1" });
}
}
Notes.GetServerVals = function(type, args) {
if (args[0].Code != "-1") {
try {
var xmlDoc = (new DOMParser()).parseFromString(args[0].Text, "text/xml");
var n = null;
xmlDoc = (new DOMParser()).parseFromString(xmlDoc.getElementsByTagName('GetNotesToSecResult')[0].childNodes[0].nodeValue, "text/xml");
for (var i = 1; i < 11; i++) {
Global.SetNote(i, "");
n = xmlDoc.getElementsByTagName('note' + i);
if (n[0] != null && n[0].childNodes[0] != null) {
Global.SetNote(i, n[0].childNodes[0].nodeValue);
}
}
n = xmlDoc.getElementsByTagName('noteCurrent');
if (n[0] != null) {
Global.SetCurrentPosition(n[0].childNodes[0].nodeValue);
}
n = xmlDoc.getElementsByTagName('noteCount');
if (n[0] != null) {
Global.SetNotesArray(n[0].childNodes[0].nodeValue);
}
n = xmlDoc.getElementsByTagName('lastupdate');
if (n[0] != null) {
var dt = n[0].childNodes[0].nodeValue;
try {
dt = dt.split(".")[0];
dt = dt.replace("T", " ");
dt = Date.parseExact(dt, "yyyy-MM-dd HH:mm:ss");
}
catch (err) { }
Global.SetClientLastUpdated(dt);
}
onNotesInit.fire({ Code: "1" });
}
catch (exp) {
onNotesInit.fire({ Code: "-1", Text: Strings.GetServerErr() });
}
}
}
Notes.CheckCountSync = function(type, args) {
try {
if (args[0].Code != "-1") {
if (args[0].Text.indexOf("<op>") == -1) {
onNotesInit.fire({ Code: "-1", Text: Strings.GetServerErr() });
}
else {
var response = args[0].Text.replace("<op>", "").replace("</op>", "");
if (response == "-1") {
onNotesInit.fire({ Code: "-1", Text: Strings.GetServerErr() });
}
else {
var servNtCnt = parseInt(response);
if (servNtCnt == Global.AllNotesCount()) {
ClientServer.GetServerVals(Global.GetGUID(), Global.Client);
return;
}
else {
onNotesInit.fire({ Code: "2", Text: Strings.GetClientGreater() });
}
}
}
}
}
catch (exp) {
onNotesInit.fire({ Code: "-1", Text: Strings.GetServerErr() });
}
}
Notes.CheckSync = function(type, args) {
try {
if (args[0].Code != "-1") {
var response = args[0].Text;
if (response == "-1") {
onNotesInit.fire({ Code: "-1", Text: Strings.GetServerErr() });
}
else {
var dt = Date.parseExact(response, "M/d/yyyy H:mm:ss tt");
if (Global.GetClientLastUpdated() == "") {
Notes.Init(4);
return;
}
var dt2 = new Date(Global.GetClientLastUpdated());
if (dt > dt2) {
onNotesInit.fire({ Code: "2", Text: Strings.GetServerGreater() });
}
else {
onNotesInit.fire({ Code: "3" });
}
}
}
else {
onNotesInit.fire({ Code: "-1", Text: Strings.GetServerErr() });
}
}
catch (exp) {
onNotesInit.fire({ Code: "-1", Text: Strings.GetServerErr() });
}
}
Notes.ClientUpdateNotes = function(type, args) {
try {
if (args[0].Code != "-1") {
var lastUpdate = "";
var xmlDoc = (new DOMParser()).parseFromString(args[0].Text, "text/xml");
var n = null;
n = xmlDoc.getElementsByTagName('UpdateAllNotesResult');
if (n[0] != null) {
lastUpdate = n[0].childNodes[0].nodeValue;
}
if (lastUpdate.length == 0) {
onNotesInit.fire({ Code: "-2", Text: Strings.GetServerErr() });
}
else {
Global.SetClientLastUpdated(Date.parseExact(lastUpdate, "M/d/yyyy H:mm:ss tt"));
onNotesInit.fire({ Code: "1" });
}
}
else {
onNotesInit.fire({ Code: "-2", Text: Strings.GetServerErr() });
}
}
catch (exp) {
onNotesInit.fire({ Code: "-2", Text: Strings.GetServerErr() });
}
}
Notes.UpdateSelectedNotes = function(note1, note2, note3, note4, note5, note6, note7, note8, note9, note10, SelectedNotesArray)
{
Global.setAllNotes( SelectedNotesArray, note1, note2, note3, note4, note5, note6, note7, note8, note9, note10 );
if (Notes.LoggedIn())
{
ClientServer.ClientUpdateSelectedNotes(Global.GetGUID(), note1, note2, note3, note4, note5, note6, note7, note8, note9, note10, Global.GetNotesArray(), Global.GetCurrentPosition(), SelectedNotesArray);
}
}
Notes.ValidateSelectedNotesUpdate = function(type, args) {
try {
if (args[0].Code != "-1") {
var lastUpdate = "";
var xmlDoc = (new DOMParser()).parseFromString(args[0].Text, "text/xml");
var n = null;
n = xmlDoc.getElementsByTagName('UpdateSelectedNotesResult');
if (n[0] != null) {
lastUpdate = n[0].childNodes[0].nodeValue;
}
if (lastUpdate.length == 0) {
onNotesUpdate.fire({ Code: "-1", Text: Strings.GetServerErr() });
}
else {
Global.SetClientLastUpdated(Date.parseExact(lastUpdate, "M/d/yyyy H:mm:ss tt"));
onNotesUpdate.fire({ Code: "1" });
}
}
else {
onNotesUpdate.fire({ Code: "-1", Text: Strings.GetServerErr() });
}
}
catch (exp) {
onNotesUpdate.fire({ Code: "-1", Text: args[0].Text });
}
}
Notes.SendUpdateEvent = function() {
if (!Notes.LoggedIn()) {
onNotesUpdate.fire({ Code: "1" });
}
}
Notes.LoggedIn = function()
{
var retval = false;
if (Global.GetGUID().length > 0)
{
retval = true;
}
return retval;
}
Notes.Filled = function()
{
return Global.GetNotesArray().length;
}
Notes.GetPosition = function()
{
return Global.GetCurrentPosition() + "/" + Notes.Filled();
}
Notes.IsFirst = function()
{
if (Global.GetCurrentPosition() == 1)
{
return true;
}
return false;
}
Notes.IsLast = function()
{
if (Global.GetCurrentPosition() == Notes.Filled())
{
return true;
}
return false;
}
Notes.MaxFilled = function()
{
if (10 == Notes.Filled())
{
return true;
}
return false;
}
Notes.MinFilled = function()
{
if (1 == Notes.Filled())
{
return true;
}
return false;
}
Notes.CurrentNoteIndex = function()
{
var temp = new Array();
temp = Global.GetNotesArray().split('');
var cd = temp[parseInt(Global.GetCurrentPosition()) - 1];
if (cd == '0') {
cd = '10';
}
return parseInt(cd);
}
Notes.NextNoteIndex = function()
{
var temp = new Array();
temp = Global.GetNotesArray().split('');
var k = temp[parseInt(Global.GetCurrentPosition())];
if (k == '0') {
k = '10';
}
return parseInt(k);
}
Notes.PreviousNoteIndex = function()
{
var temp = new Array();
temp = Global.GetNotesArray().split('');
var k = temp[parseInt(Global.GetCurrentPosition()) - 2];
if (k == '0') {
k = '10';
}
return parseInt(k);
}
Notes.GetNewNoteIndex = function()
{
var retval = -1;
if (!Notes.MaxFilled()){
retval = 10;
for (var i = 1; i < 10; i++) {
if (Global.GetNotesArray().indexOf(i) == -1) {
retval = parseInt(i);
break;
}
}
}
return retval;
}
Notes.MoveForward = function()
{
if (!Notes.IsLast())
{
Global.AddToCurrentPosition(1);
}
}
Notes.MoveBackward = function()
{
if (!Notes.IsFirst())
{
Global.AddToCurrentPosition(-1);
}
}
Notes.AddNote = function()
{
var nInd = Notes.GetNewNoteIndex();
nInd = (nInd == 10) ? 0 : nInd;
Global.SetNotesArray(Global.GetNotesArray() + nInd);
Global.SetCurrentPosition(Notes.Filled());
}
Notes.DeleteNote = function(nInd)
{
var lst = Notes.IsLast();
nInd = (nInd == 10) ? 0 : nInd;
Global.SetNotesArray(Global.GetNotesArray().replace(nInd, ""));
if (lst)
{
Global.AddToCurrentPosition(-1);
}
}
Notes.GetNoteValue = function(index)
{
return Global.GetNote(index);
}
Notes.GetInfo = function() {
ClientServer.GetInfo();
}
Notes.SetInfo = function(type, args) {
if (isFired) {
//return;
}
else {
isFired = true;
}
var currClient = null;
var noShow = true;
var agg = args[0].Text;
var AllClients = agg.getElementsByTagName('Client');
var dt = null;
var gpers = null;
var url = null;
var urltxt = null;
var global = agg.getElementsByTagName('GlobalAlert')[0];
try {
dt = global.getElementsByTagName('Date')[0].childNodes[0].nodeValue;
gpers = global.getElementsByTagName('Persist')[0].childNodes[0].nodeValue;
try {
url = global.getElementsByTagName('URL')[0].childNodes[0].nodeValue;
urltxt = global.getElementsByTagName('URLTEXT')[0].childNodes[0].nodeValue;
}
catch (exp) { url = null; urltxt = null; }
if (Date.parse(dt) > Date.parse(Global.LastAlertShownDate)) {
if (gpers == "false") {
Global.SetLastAlertShownDate(dt);
}
noShow = false;
onNotesInfo.fire({ Code: "1", Text: global.getElementsByTagName('Text')[0].childNodes[0].nodeValue, Url: url, UrlText: urltxt });
return;
}
}
catch (err) { }
if (noShow) {
for (var i = 0; i < AllClients.length; i++) {
if (AllClients[i].getElementsByTagName('ID')[0].childNodes[0].nodeValue == Global.Client) {
currClient = AllClients[i];
break;
}
}
if (currClient != null) {
if (currClient.getElementsByTagName('Alert').length > 0) {
var allert = currClient.getElementsByTagName('Alert')[0];
dt = allert.getElementsByTagName('Date')[0].childNodes[0].nodeValue;
gpers = allert.getElementsByTagName('Persist')[0].childNodes[0].nodeValue;
var abc = allert.getElementsByTagName('URL')[0].childNodes[0].nodeValue;
try {
url = allert.getElementsByTagName('URL')[0].childNodes[0].nodeValue;
urltxt = allert.getElementsByTagName('URLTEXT')[0].childNodes[0].nodeValue;
}
catch (exp) { url = null; urltxt = null; }
if (Date.parse(dt) > Date.parse(Global.LastAlertShownDate)) {
if (gpers == "false") {
Global.SetLastAlertShownDate(dt);
}
onNotesInfo.fire({ Code: "1", Text: allert.getElementsByTagName('Text')[0].childNodes[0].nodeValue, Url: url, UrlText: urltxt });
noShow = false;
return;
}
}
if (noShow && parseInt(currClient.getElementsByTagName('Version')[0].childNodes[0].nodeValue.replace(/\./g, ""), 10) > parseInt(Global.LastVersionShown.replace(/\./g, ""), 10)) {
var msg = Strings.GetNewver()
+ " "
+ Strings.GetTitle()
+ " "
+ currClient.getElementsByTagName('Version')[0].childNodes[0].nodeValue
+ " "
+ Strings.Gethasrelease()
+ " "
+ currClient.getElementsByTagName('Name')[0].childNodes[0].nodeValue
+ " "
+ Strings.GetPleaseVisit();
var features = currClient.getElementsByTagName('Features')[0].childNodes[0];
if (features != null && features.nodeValue != "") {
msg += Strings.GetFeatures()
+ " "
+ features.nodeValue;
}
try {
url = currClient.getElementsByTagName('URL')[0].childNodes[0].nodeValue;
urltxt = currClient.getElementsByTagName('URLTEXT')[0].childNodes[0].nodeValue;
}
catch (exp) { url = null; urltxt = null; }
Global.SetLastVersionShown(currClient.getElementsByTagName('Version')[0].childNodes[0].nodeValue);
onNotesInfo.fire({ Code: "1", Text: msg, Url: url, UrlText: urltxt });
noShow = false;
return;
}
}
if (noShow) {
for (var i = 0; i < AllClients.length; i++) {
if (Date.parse(AllClients[i].getElementsByTagName('Released')[0].childNodes[0].nodeValue) > Date.parse(Global.LastClientShownDate)) {
currClient = AllClients[i];
var msg = Strings.GetTitle()
+ " "
+ currClient.getElementsByTagName('Version')[0].childNodes[0].nodeValue
+ Strings.Gethasrelease()
+ currClient.getElementsByTagName('Name')[0].childNodes[0].nodeValue
+ Strings.GetPleaseVisit();
var features = currClient.getElementsByTagName('Features')[0].childNodes[0];
if (features != null && features.nodeValue != "") {
msg += Strings.GetFeatures() + features.nodeValue;
}
try {
url = currClient.getElementsByTagName('URL')[0].childNodes[0].nodeValue;
urltxt = currClient.getElementsByTagName('URLTEXT')[0].childNodes[0].nodeValue;
}
catch (exp) { url = null; urltxt = null; }
Global.SetLastClientShownDate(AllClients[i].getElementsByTagName('Released')[0].childNodes[0].nodeValue);
onNotesInfo.fire({ Code: "1", Text: msg, Url: url, UrlText: urltxt });
return;
break;
}
}
}
}
}
onServerNotesReceived.subscribe(Notes.GetServerVals);
onServerNotesCount.subscribe(Notes.CheckCountSync);
onSync.subscribe(Notes.CheckSync);
onClientNotesUpdated.subscribe(Notes.ClientUpdateNotes);
onClientSelectedNotesUpdated.subscribe(Notes.ValidateSelectedNotesUpdate);
onInfo.subscribe(Notes.SetInfo);
OnGlobalNoteUpdatedEvent.subscribe(Notes.SendUpdateEvent);