Exemple #1
0
		callback : function(data) {
			var doc = Ti.XML.parseString(data).documentElement;
			var articles = doc.getElementsByTagName('article');
			
			var sitenews = [];
			
			for(var i=0; i < articles.length; i++){
				var article = articles.item(i);
				
				var snews = { day : "" };
							
				// BEST EFFORT
				try { snews.image = article.getElementsByTagName('thumb2').item(0).textContent; } catch (e) { }
				try {
					snews.date = article.getElementsByTagName('date').item(0).textContent;
					snews.hour = moment(snews.date).format("HH:mm");
					snews.day = moment(snews.date).format("DD-MM-YYYY");
				} catch (e) { }
				try { snews.category = article.getElementsByTagName('section').item(0).textContent; } catch (e) { }
				try { snews.title = article.getElementsByTagName('title').item(0).textContent; } catch (e) { }
				try { snews.id = article.getElementsByTagName('id').item(0).textContent; } catch (e) { }
				try { snews.source = article.getElementsByTagName('source').length > 0? article.getElementsByTagName('source').item(0).textContent : null; } catch (e) { }

				sitenews.push(snews);
			}
			
			//category separation
			var groups = _(_(sitenews).groupBy('category')).toArray();
			var data = [];
			
			//first category is Hard Coded "Tutte le notizie" with all news
			data.push({
				name : "Tutte le notizie",
				news : sitenews,
				count : sitenews.length,
				listed : 0
			});
			
			_(groups).each(function(group){
				data.push({
					name : group[0].category, //the category of the first
					news : group,
					count : group.length,
					listed : 0
				});
				group = _(group).groupBy('day');
			});
			
			Ti.App.fireEvent("fcinter:loadAllNewsComplete");
			Ti.App.fireEvent('fcinter.newsUpdated', {data : data});
			if(callback) callback(data);
		}
Exemple #2
0
export default function getLastUpdate (date) {
    moment.updateLocale("en", {
        relativeTime : {
            future: "in %s",
            past:   "%s",
            s:  "qualche secondo fa",
            m:  "un minuto fa",
            mm: "%d minuti fa",
            h:  "un' ora fa",
            hh: "%d ore fa",
            d:  "ieri",
            dd: "%d giorni fa",
            M:  "un mese fa",
            MM: "%d mesi fa",
            y:  "un anno fa",
            yy: "%d anni fa"
        }
    });

    const momentDate = moment(date);
    if (date) {
        return momentDate.fromNow();
    }
    return "formato data errato";
}
	this.open = function(parent, appointment){
		
		Ti.App.fireEvent("vls:hideHomeButton");
		
		this.parent = parent;
		this.edited = false;
		
		//new or detail?
		if(appointment){
			Ti.API.info('Open appointment: ' + JSON.stringify(appointment));
			//buttons
			this.btnOk.title = "CHIUDI";
			this.btnDelete.title = "ELIMINA";
			
			//detail
			this.appointment = Appointment.read(appointment.ID);
			
			this.note = appointment.Info;
			this.date = moment(appointment.When).toDate();
		} else {
			Ti.API.info('Open new appointment');
			
			//new always is edited
			this.edited = true;
			
			//buttons
			this.btnOk.title = "CREA";
			this.btnDelete.title = "ANNULLA";
			
			//new
			this.appointment = null;
			
			//default value
			this.note = "";
			this.date = moment().toDate();
		}
		
		//uodate values
		this.lblDate.text = moment(this.date).format("DD/MM/YYYY[ alle ore ]HH:mm");
		this.txfNote.value = this.note;
		
		// show me
		that.me.opacity = 0; //hack
		parent.add(this.me);
				
		that.me.animate({ opacity : 1, duration : 250});
	};
	this.close = function(save){
		if(save){
			//new or detail?
			if(this.appointment) {
				if(this.edited){
					//save detail
					this.appointment.When = moment(this.date).toJSON();
					this.appointment.Info = this.txfNote.value;
					Ti.API.info('Save appointment: ' + JSON.stringify(this.appointment));
					this.appointment.save();
					Ti.App.fireEvent("vls:updateCalendarView");
				}
			} else {
				//create
				new Appointment.Appointment(this.txfNote.value, this.date).save();
				Ti.API.info('Create appointment: ' + JSON.stringify(this.appointment));
				Ti.App.fireEvent("vls:updateCalendarView");
			}
		} else if (this.appointment) {
			//it's a delete
			Ti.API.info('Delete appointment: ' + JSON.stringify(this.appointment));
			this.appointment.delete();
			Ti.App.fireEvent("vls:updateCalendarView");
		}
		
		Ti.App.fireEvent("vls:showHomeButton");
		that.me.animate({ opacity : 0, duration : 250}, function(e){
			that.parent.remove(that.me);
			if(save){
				//save
				if(that.appointment){
					if(that.edited){
						Ti.UI.createAlertDialog({
							buttonNames : ["Ok"],
							message : "L'appuntamento è stato salvato correttamente"
						}).show();
					}
				} else {
					if(that.edited){
						Ti.UI.createAlertDialog({
							buttonNames : ["Ok"],
							message : "L'appuntamento è stato creato correttamente"
						}).show();
					}
				}
			} else if(that.appointment) {
				//it's a delete
				Ti.UI.createAlertDialog({
							buttonNames : ["Ok"],
					message : "L'appuntamento è stato eliminato"
				}).show();
			}
		});
	};
    function datePickerHandler (e) {
        var dialog = new DatePickerDialog({
            config: {
                minDate: new Date(),
                maxDate: moment().add('years',4)._d,
                value: new Date()
            },
            handler: function (e) {
                alert(e.result);
            }
        });

        dialog.show();
    }
	this.open = function(parent, pillAlert){
		that.parent = parent;
		that.pillAlert = PillAlert.read(pillAlert.ID);
		
		Ti.API.info('Open pillAlert: ' + JSON.stringify(pillAlert));
		Ti.App.fireEvent("vls:hideHomeButton");
		
		that.lblPill.text = PillAlert.RemedyNames[pillAlert.PillID];
		that.lblTime.text = moment(pillAlert.When).format("[Alle ore ]HH:mm");
		that.lblInfo.text = pillAlert.Info;
		
		if(OS_IOS){
			// show me
			that.me.opacity = 0; //hack
			parent.add(this.me);
					
			that.me.animate({ opacity : 1, duration : 250});
		} else {
			parent.add(this.me);
		}
	};
            onload: function(e) {
                _this.currentlyDownloading[id] = false

                var f = Ti.Filesystem.getFile(filename)
                f.write(this.responseData)

                Ti.API.info('Downloaded and saved thumbnail ' + id)

                // Simple caching based on Expires header, no other cache control headers (if no header given, cache for 10 minutes)
                var expires = this.getResponseHeader('Expires')
                var cacheInfoFile = Ti.Filesystem.getFile(filename + '.cacheInfo')

                if(expires)
                {
                    var expiresFormatted = moment.utc(expires.slice(4, -4), 'D MMM YYYY HH:mm:ss').format()
                    Ti.API.debug('Thumbnail ' + id + ' will expire at ' + expiresFormatted)
                    cacheInfoFile.write(JSON.stringify(expiresFormatted))
                }
                else
                    cacheInfoFile.write(JSON.stringify(moment().add('minutes', 10).format()))

                if(onSuccess)
                    onSuccess()
            },
    this.downloadThumbnail = function(id, onSuccess)
    {
        if(this.currentlyDownloading[id])
        {
            Ti.API.debug('Not downloading thumbnail ' + id + ' because it is already being downloaded')
            return
        }

        var filename = Ti.Filesystem.applicationDataDirectory + id + '.jpg'
        if(Ti.Filesystem.getFile(filename).exists() && Ti.Filesystem.getFile(filename + '.cacheInfo').exists())
        {
            var expires = moment(JSON.parse(Ti.Filesystem.getFile(filename + '.cacheInfo').read().text))

            if(expires.diff(moment()) > 0)
            {
                Ti.API.debug('Cache hit for thumbnail ' + id)

                // We can still use the cached file
                if(onSuccess)
                    onSuccess()

                return
            }
            else
            {
                Ti.API.debug('Cached thumbnail ' + id + ' expired (' + expires.format() + '), deleting it')

                // File expired, try to delete it
                Ti.Filesystem.getFile(filename).deleteFile()
                Ti.Filesystem.getFile(filename + '.cacheInfo').deleteFile()
            }
        }
        else
            Ti.API.debug('Thumbnail ' + id + ' not cached')

        Ti.API.debug('Trying to download thumbnail ' + id)

        var _this = this
        var client = Ti.Network.createHTTPClient({
            onload: function(e) {
                _this.currentlyDownloading[id] = false

                var f = Ti.Filesystem.getFile(filename)
                f.write(this.responseData)

                Ti.API.info('Downloaded and saved thumbnail ' + id)

                // Simple caching based on Expires header, no other cache control headers (if no header given, cache for 10 minutes)
                var expires = this.getResponseHeader('Expires')
                var cacheInfoFile = Ti.Filesystem.getFile(filename + '.cacheInfo')

                if(expires)
                {
                    var expiresFormatted = moment.utc(expires.slice(4, -4), 'D MMM YYYY HH:mm:ss').format()
                    Ti.API.debug('Thumbnail ' + id + ' will expire at ' + expiresFormatted)
                    cacheInfoFile.write(JSON.stringify(expiresFormatted))
                }
                else
                    cacheInfoFile.write(JSON.stringify(moment().add('minutes', 10).format()))

                if(onSuccess)
                    onSuccess()
            },
            onerror: function(e) {
                _this.currentlyDownloading[id] = false

                Ti.API.error(e.error);

                Ti.UI.createNotification({
                    duration: Ti.UI.NOTIFICATION_DURATION_SHORT,
                    message: 'Error retrieving thumbnail ' + id + ': ' + e.error
                }).show()
            },
            timeout: 5000,
            cache: true // iOS only (http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Network.HTTPClient.cache-property.html)
        })

        this.currentlyDownloading[id] = true

        try
        {
            // Take Titanium points size of display as size hint
            var thumbnailSize = Math.max(5, Math.min(500, Math.max(Ti.Platform.displayCaps.getPlatformWidth(), Ti.Platform.displayCaps.getPlatformHeight())))

            client.open('GET', require('globals').webServiceBaseUri + 'picture/' + id + '/thumbnail/?size=' + thumbnailSize)
            client.send()
        }
        catch(e)
        {
            this.currentlyDownloading[id] = false
            throw e
        }
    }
		that.editDate.open(that.me, that.date, function(value){
			that.date = value;
			that.lblDate.text = moment(value).format("DD/MM/YYYY[ alle ore ]HH:mm");
		});
wowRemoteResponse = function() {
    var json, mounts, hasTLPD, vyra_output, vyra_array, vyra_loot, vyra_count, row, ii,  j, k, nickLabel;

    hasTLPD = false;
    vyra_loot = 44732;  // Azure Dragonleather Helm ID
    vyra_array = [];    // Array storing Vyragosa kills   
    vyra_count = '';    // String indentifying number of Vyragosa kills.
    vyra_output = 'Vyragosa has not been kill recently';         // String output for array    

    json = JSON.parse(this.responseText);  // Parse response
	mounts = json.mounts.collected;        // Store collected mounts array

    // Announce Player Name, response, mounts, and feed
    Ti.API.info(json.name);
    Ti.API.info('-----');
    Ti.API.info('Response text: ' + this.responseText);
    Ti.API.info('Mounts collected: ' + json.mounts.collected);
	Ti.API.info('Player feed: ' + json.feed);
    Ti.API.info('-----');
	
	// Check player feed for recent Vyragosa loot
    for(j=0;j<json.feed.length; j++){        
    	if(json.feed[j].type === "LOOT" && json.feed[j].itemId === vyra_loot) {
    		vyra_array.push("Has looted Vyragosa: " + moment(json.feed[j].timestamp).format('lll'));	
    	}
    }
       
    // Ready Vyragosa data
    if (vyra_array.length > 0) {
        // If Vyragosa has been recently looted..
        Ti.API.info(json.name + ' has killed Vyragosa recently:');
        
        vyra_output = ''; //Clear out Vyragosa Output
        
        // Loop through array of Vyragosa loot data
        for(k=0;k<vyra_array.length;k++){
            Ti.API.info(vyra_array[k]);
            
            // For each Vyragosa loot, add loot data to string output;
            vyra_output += vyra_array[k] + '\n'; 
        }
        
        // Set label for number of Vyragosa loots
        vyra_count = 'has recently looted Vyragosa ' + vyra_array.length + ' time(s).';
    }
    
    Ti.API.info(vyra_count);
    Ti.API.info(vyra_output);

    // Check to see if player already has TLPD
    for(ii=0;ii<mounts.length;ii++) {
        if(mounts[ii].creatureId === 32153) {
            Ti.API.info('Has Time-Lost Proto-Drake');
            hasTLPD = true; // Set boolean TRUE if they do
        } 
    }
    
    Ti.API.info('===============================');
    
    for(r=0;r<table.data[0].rows.length;r++){
        var thisRow = table.data[0].rows[r];
        
        if(thisRow['character_name'] == json.name && thisRow['character_realm'] == json.realm){
            if(hasTLPD) { thisRow.setRightImage('tlpd.png'); };   // If player has TLPD, update right-side image
            
            thisRow.children[1].setText = vyra_count;

            thisRow.info = {
                name: json.name,
                feed: vyra_output
            };

            thisRow.addEventListener("click", function(e){
                alert(e.source.info.name + "\n" + e.source.info.feed);
            });  
        }
    }
   
    Ti.API.info('Row pushed for ' + json.name);
};