Changeset 2114


Ignore:
Timestamp:
07/16/10 14:19:10 (19 months ago)
Author:
dart
Message:

LoReality?:
o Messsager is now full ajax. Can reply to a mail now.

Location:
trunk/loreality
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/loreality/loreality/config/routing.py

    r2097 r2114  
    1111    """Create, configure and return the routes Mapper""" 
    1212    map = Mapper(directory=config['pylons.paths']['controllers'], 
    13                  always_scan=config['debug']) 
     13                 always_scan=config['debug'], explicit=True) 
    1414    map.minimization = False 
    1515 
  • trunk/loreality/loreality/controllers/messager.py

    r2113 r2114  
    2121import uuid 
    2222from pylons.i18n.translation import _, ungettext 
     23from webhelpers.html.tags import literal 
    2324 
    2425class MessagerController(BaseController): 
     
    6162        return render('/derived/page/messager.html') 
    6263    #-------------------------------------------------------------- 
    63     def open(self, id): 
    64         return self.index(opened=uuid.UUID(id)) 
    65     #-------------------------------------------------------------- 
    6664    @jsonify 
    6765    def getallmsgs(self): 
     
    7775        for m in messages: 
    7876            p = pilot_q.filter_by(id=m.from_).first() 
    79             res['messages'].append({ 'date': m.date.strftime("%c"), 'from':p.name, 'subject':m.subject }) 
     77            res['messages'].append({ 
     78                'date': m.date.strftime("%c"), 
     79                'from':p.name, 
     80                'subject':m.subject, 
     81                'unread':m.unread, 
     82                'id':str(m.id), 
     83                }) 
    8084        return res 
    8185    #-------------------------------------------------------------- 
     86    @jsonify 
    8287    def getmsg(self, id): 
    8388        pilot_q = meta.Session.query(model.Pilot) 
    8489        pilot = pilot_q.filter_by(login=request.environ['REMOTE_USER']).first() 
    8590        if pilot is None: 
    86             abort(404) 
     91            return "Error" 
    8792 
    8893        message_q = meta.Session.query(model.Message) 
     
    98103            message.unread = False 
    99104            meta.Session.commit() 
    100         return "%s|%s|%s"% ( str(message.id), message.text, pilot.messages_unread ) 
     105 
     106        p = pilot_q.filter_by(id=message.from_).first() 
     107        res = {} 
     108        res['message'] = { 
     109            'unread':p.messages_unread, 
     110            'id':str(message.id), 
     111            'text':literal(message.text), 
     112            } 
     113        return res 
     114    #-------------------------------------------------------------- 
     115    def reply(self, id): 
     116        pilot_q = meta.Session.query(model.Pilot) 
     117        pilot = pilot_q.filter_by(login=request.environ['REMOTE_USER']).first() 
     118        if pilot is None: 
     119            return "Error" 
     120 
     121        message_q = meta.Session.query(model.Message) 
     122        message = message_q.filter_by(id=uuid.UUID(id)).first() 
     123        if message is None: 
     124            return "Error" 
     125         
     126        #- Be sure it is our message 
     127        if message not in pilot.messages: return "Error" 
     128 
     129        values = dict(request.params) 
     130 
     131        pilotid = message.from_ 
     132        dest_pilot = pilot_q.filter_by(id=pilotid).first() 
     133        msg = model.Message() 
     134        msg.from_ = pilot.id 
     135        msg.subject = _("Re:") + message.subject 
     136        msg.text = values["text"] 
     137        dest_pilot.send_message( msg ) 
     138        meta.Session.commit() 
     139        return "ok" 
    101140    #-------------------------------------------------------------- 
    102141    def delete(self, id): 
  • trunk/loreality/loreality/public/style.css

    r2112 r2114  
    6666 
    6767/* MESSAGER */ 
    68 div.message_box { 
    69  display: right; 
    70  font-size: x-small; 
    71 } 
    72 div.message { 
    73  display: inline; 
    74  /* border: solid black 1px; */ 
    75  width: 80%; 
    76  /* background: #AAAAAA; */ 
    77  font-size: small; 
    78 } 
    79  
    80 div.message a{ 
    81     text-decoration:none ; 
    82 } 
    83 div.message span#subject { 
    84     font-weight: bold; 
    85     font-size: large; 
    86     margin-right: 30px; 
    87 } 
    88 span.read{ 
     68.read{ 
    8969    font-weight: normal; 
    9070    background: #AAAAAA; 
    9171} 
    92 span.unread{ 
     72.unread{ 
    9373    font-weight: bold; 
    9474    color: #aa1111; 
    9575    background: #ffffff; 
    9676} 
    97 div.message_open{ 
    98  width: 80%; 
    99  border: solid black 1px; 
    100  background: #ffffff; 
    101  color: #000000; 
    102  margin-bottom: 20px; 
     77 
     78.from .subject{ 
     79    text-align: left; 
    10380} 
    104 div.message_open span{ 
    105  color: red; 
    106     font-size: large; 
     81.date{ 
     82    text-align: right; 
    10783} 
    108  
     84.message_open { 
     85    border-left: solid 3px darkGrey; 
     86    padding-left: 5px; 
     87    background: #909090;  
     88} 
     89table#message_table { 
     90    width: 100%; 
     91    margin-left: 5px; 
     92    margin-right: 5px; 
     93} 
  • trunk/loreality/loreality/templates/base/index.html

    r2113 r2114  
    1010<html> 
    1111<head> 
    12 ${ h.stylesheet_link( '/style.css') } 
    13   <style type="text/css"> 
    14       @import "dojoroot/dijit/themes/tundra/tundra.css"; 
    15       @import "dojoroot/dojo/resources/dojo.css"; 
    16   </style> 
     12${ h.stylesheet_link( '/style.css', 
     13      "/dojo/dijit/themes/tundra/tundra.css", 
     14      "/dojo/dojo/resources/dojo.css") } 
    1715 
    1816${ h.javascript_link( '/dojo/dojo/dojo.js',  djConfig="parseOnLoad: true") } 
     
    2119     dojo.require("dijit.form.Button"); 
    2220     dojo.require("dijit.Editor"); 
     21     dojo.require("dijit._editor.plugins.AlwaysShowToolbar"); 
    2322     dojo.require("dojo.fx"); 
    2423     dojo.require("dojo.html"); 
  • trunk/loreality/loreality/templates/derived/page/messager.html

    r2113 r2114  
    11<%inherit file="/base/index.html"/> 
    2  
    3 <script> 
    4 /*-------------------------------------*/ 
    5 function showMessage(data,ioArgs) { 
    6     if( data == "Error"){ 
    7         alert("Error"); 
    8         }else{ 
    9         d = data.split('|'); 
    10         dojo.fx.wipeIn({ 
    11             node:"message-" + d[0], 
    12             beforeBegin: function(n){ 
    13                 dojo.byId("message-txt-"+d[0]).innerHTML = d[1]; 
    14             } 
    15         }).play(); 
    16         dojo.byId( "nb_msg_unread").innerHTML = d[2]; 
    17     } 
    18  
    19 } 
    20 /*-------------------------------------*/ 
    21 function helloError(data, ioArgs) { 
    22     alert('Error when retrieving data from the server!'); 
    23 } 
    24 /*-------------------------------------*/ 
    25 function loadMsg() { 
    26     dojo.empty("message_table"); 
    27     dojo.xhrGet({ 
    28         url: '${h.url_for(controller='messager', action='getallmsgs') }', 
    29         load: fillMessages, 
    30         error: helloError, 
    31     }).play(); 
    32 } 
    33 dojo.addOnLoad( loadMsg ); 
    34 /*-------------------------------------*/ 
    35 function fillMessages(data,ioArgs) { 
    36     if( data == "Error"){ 
    37         alert("Error"); 
    38         }else{ 
    39         objects = dojox.json.ref.fromJson(data); 
    40         messages = objects['messages']; 
    41  
    42         var buffer = ""; 
    43         for (i = 0; i < messages.length; i += 1) { 
    44             msg = messages[i]; 
    45             buffer += "<tr><td>" + msg['date'] + '</td><td>' + msg['from'] + '</td><td>' + msg['subject'] +"</td></tr>"  
    46         } 
    47         dojo.html.set("message_table", buffer); 
    48  
    49     } 
    50 } 
    51 </script> 
    52  
     2${ h.javascript_link( '/js/messager.js') } 
    533<h2>Messager</h2> 
    54 % for message in c.messages: 
    55 <div class="message"> 
    56     <a href=${h.url_for(controller='messager', action='delete',id=message.id) } class="action">[Delete]</a> 
    57  <button dojoType="dijit.form.ToggleButton"> 
    58     <span  
    59         %if message.unread: 
    60         class="unread" 
    61         %else: 
    62         class="read" 
    63         %endif 
    64         id="span-${message.id}" >${h.msg.get_from(message)} | ${message.date.strftime("%c")} | <span id="subject"> ${message.subject}</span></span> 
    65  
    66       <script type="dojo/method" event="onChange"> 
    67           node = "span-${message.id}"; 
    68           if( this.checked ) 
    69           { 
    70               if( dojo.hasClass( node, "unread") ) 
    71               { 
    72                   dojo.removeClass( node, "unread"); 
    73                   dojo.addClass( node, "read"); 
    74               } 
    75               dojo.xhrGet({ 
    76                   url: '${h.url_for(controller='messager', action='getmsg',id=message.id) }', 
    77                   load: showMessage, 
    78                   error: helloError, 
    79                   }).play(); 
    80           }else{ 
    81           dojo.fx.wipeOut({ 
    82               node:"message-${message.id}", 
    83               }).play(); 
    84           } 
    85       </script> 
    86   </button> 
    87 </div> 
    88   <div id="message-${message.id}" class='message_open' style="display: none;"> 
    89   <button dojoType="dijit.form.Button">Reply 
    90       <script type="dojo/method" event="onClick"> 
    91       </script> 
    92   </button> 
    93   <p id="message-txt-${message.id}"></p> 
    94   </div> 
    95 <br/> 
    96 % endfor 
    97 <h2>New one</h2> 
    984<div id="message_list"> 
    995    <table id="message_table"> 
Note: See TracChangeset for help on using the changeset viewer.