TimeGridMediator.py :  » Ajax » pyjamas » src » examples » timesheet » view » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Ajax » pyjamas 
pyjamas » src » examples » timesheet » view » TimeGridMediator.py

# vim: set ts=4 sw=4 expandtab:

from puremvc.patterns.mediator import Mediator

from ApplicationConstants import Notification

import model
from model.TimeProxy import TimeProxy
from model.vo.TimeVO import TimeVO

from pyjamas.Cookies import setCookie
from pyjamas.Window import alert

class TimeGridMediator(Mediator):

    NAME = 'TimeGridMediator'

    def __init__(self, viewComponent):
        super(TimeGridMediator, self).__init__(TimeGridMediator.NAME, viewComponent)
        self.viewComponent.mediator = self
        self.timeProxy = self.facade.retrieveProxy(TimeProxy.NAME)

    def listNotificationInterests(self):
        return [
            Notification.CELL_SELECTED,
            Notification.CELL_UPDATED,
            Notification.DATE_SELECTED,
            Notification.EDIT_SELECTED,
            Notification.SUM_SELECTED,
            Notification.FILE_LOADED,
        ]

    def handleNotification(self, note):
        try:
            noteName = note.getName()
            nodeBody = note.getBody()
            if noteName == Notification.CELL_SELECTED:
                alert("Select cell is not implemented yet")
            elif noteName == Notification.CELL_UPDATED:
                alert("Cell changed is not implemented yet")
            elif noteName == Notification.DATE_SELECTED:
                self.onDateSelected(nodeBody)
            elif noteName == Notification.EDIT_SELECTED:
                self.onEditSelected()
            elif noteName == Notification.SUM_SELECTED:
                self.onSumSelected()
            elif noteName == Notification.FILE_LOADED:
                self.onFileLoaded(*nodeBody)
        except:
            raise

    def onDateSelected(self, date):
        if not self.viewComponent.date is None and self.viewComponent.dirty:
            self.timeProxy.setDateEntries(self.viewComponent.date, 
                                          self.viewComponent.getEntries())
        self.viewComponent.date = date
        self.viewComponent.setEntries(self.timeProxy.getDateEntries(self.viewComponent.date))

    def onEditSelected(self):
        self.viewComponent.setVisible(True)

    def onSumSelected(self):
        self.viewComponent.setVisible(False)
        self.onDateSelected(self.viewComponent.date)
        self.sendNotification(Notification.DATE_SELECTED, self.viewComponent.date)

    def onFileLoaded(self, filename, data):
        def invalid(lineno, line):
            alert("Invalid line at %s:\n%s" % (lineno, line))
            return False
        date = self.timeProxy.importData(data, invalid)
        if date:
            try:
                setCookie("fileLocation", filename, 1000000000)
            except:
                pass
            self.sendNotification(Notification.DATE_SELECTED, date)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.