Changeset 6544


Ignore:
Timestamp:
Sep 30, 2014, 12:23:36 PM (8 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #1852: Use AJAX to update footnote instead of page reloading

Location:
branches/3.3-stable/www
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • branches/3.3-stable/www/footnote.js

    r6530 r6544  
    3838    Buttons.addClickHandler('multiMessages', footnote.showAllMessages);
    3939   
    40     // Reload the footnote in 60 seconds
    41     Footnote.startReloadTimer();
    42   }
    43  
    44   /**
    45     Start the reload timer. Timeout parameter (in seconds) is optional.
    46     If not given, the default timout is used (60 seconds).
    47   */
    48   footnote.startReloadTimer = function(timeout)
    49   {
    50     setTimeout(Footnote.reload, (timeout || pAutoReload) * 1000);
     40    Footnote.loadMessages();
    5141  }
    5242 
     
    5444    Reload the footnote page.
    5545  */
    56   footnote.reload = function()
     46  footnote.loadMessages = function()
    5747  {
    58     location.reload(false);
     48    var url = 'ajax.jsp?ID='+App.getSessionId();
     49    url += '&cmd=GetFootnoteMessages';
     50    var request = Ajax.getXmlHttpRequest();
     51    request.open("GET", url, true);
     52    Ajax.setReadyStateHandler(request, footnote.messagesLoaded);
     53    request.send(null);
    5954  }
     55 
     56  footnote.messagesLoaded = function(request)
     57  {
     58    var messages = JSON.parse(request.responseText);
     59   
     60    Doc.hide('broadcast');
     61    Doc.hide('credit');
     62    Doc.hide('singleMessage');
     63    Doc.hide('multiMessages');
     64    if (messages.broadcast)
     65    {
     66      Doc.show('broadcast');
     67      Doc.element('broadcast-title').innerHTML = Strings.encodeTags(messages.broadcast);
     68    }
     69    else if (messages.newMessages > 1)
     70    {
     71      Doc.show('multiMessages');
     72      Doc.element('num-messages').innerHTML = messages.newMessages;
     73    }
     74    else if (messages.newMessages == 1)
     75    {
     76      var msg = messages.message;
     77      Doc.show('singleMessage');
     78      Data.set('singleMessage', 'message-id', msg.id);
     79      Doc.element('message-name').innerHTML = Strings.encodeTags(msg.name);
     80      Doc.element('message-from').innerHTML = Strings.encodeTags(msg.from);
     81    }
     82    else
     83    {
     84      Doc.show('credit');
     85    }
     86   
     87    setTimeout(footnote.loadMessages, pAutoReload * 1000);
     88  }
     89
    6090 
    6191  /**
  • branches/3.3-stable/www/footnote.jsp

    r6167 r6544  
    4545<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
    4646<%
    47 String broadcastTitle = (String)application.getAttribute("broadcast.title");
    4847SessionControl sc = Base.getSessionControl(pageContext, false);
    4948String ID = "";
     
    5655  serverAdminName = Values.getStringOrNull(sc.getClientDefaultSetting("server.admin.name"));
    5756  serverAdminEmail = Values.getStringOrNull(sc.getClientDefaultSetting("server.admin.email"));
    58   dc = sc.newDbControl();
    5957}
    60 long numNewMessages = 0;
    6158try
    6259{
    63   if (sc != null && sc.isLoggedIn()) numNewMessages = Message.countUnreadMessages(dc, null, false);
    6460  %>
    6561  <base:page type="iframe" title="">
     
    6864  <div class="footer">
    6965  <table style="width: 100%; height: 100%;"><tr><td>
    70   <%
    71   if (broadcastTitle != null)
    72   {
    73     String broadcastMessage = (String)application.getAttribute("broadcast.message");
    74     %>
    75     <div class="message">
     66
     67    <div class="message" id="broadcast" style="display: none;">
    7668    <base:icon id="broadcast" image="warning.png" tooltip="Read more&hellip;"
    77       style="font-weight: bold;">&nbsp;<%=HTML.encodeTags(broadcastTitle) %></base:icon>
     69      style="font-weight: bold;">
     70      <span id="broadcast-title"></span>
     71    </base:icon>
    7872    </div>
    79     <%
    80   }
    81   else if (numNewMessages == 0)
    82   {
    83     %>
    84     <div class="credit">
     73   
     74    <div class="credit" id="credit">
    8575      The development of BASE is currently supported by Lund
    8676      University through SCIBLU. Previous patrons of the BASE project
     
    10898      %>
    10999    </div>
    110     <%
    111   }
    112   else if (numNewMessages == 1)
    113   {
    114     User user = User.getById(dc, sc.getLoggedInUserId());
    115     ItemQuery<Message> query = Message.getQuery(user);
    116     query.restrict(
    117       Restrictions.eq(
    118         Hql.property("read"),
    119         Expressions.parameter("read")
    120       )
    121     );
    122     query.setParameter("read", false, Type.BOOLEAN);
    123     ItemResultList<Message> messages = query.list(dc);
    124     Message message = messages.get(0);
    125     %>
    126     <base:icon id="singleMessage" image="message.png" tooltip="Read the message"
    127       data-message-id="<%=message.getId()%>"
    128       >&nbsp;<%=HTML.encodeTags(message.getName())%> (From: <%=HTML.encodeTags(message.getFrom())%>)
     100
     101    <base:icon id="singleMessage" style="display: none;" image="message.png" tooltip="Read the message">
     102      <span id="message-name"></span> (From: <span id="message-from"></span>)
    129103    </base:icon>
    130     <%
    131   }
    132   else
    133   {
    134     %>
    135     <base:icon id="multiMessages" image="message.png" tooltip="Read the messages"
    136       >&nbsp;<b>You have <%=numNewMessages%> new messages</b></base:icon>
    137     <%
    138   }
    139   %>
     104    <base:icon id="multiMessages" style="display: none;" image="message.png" tooltip="Read the messages">
     105      <b>You have <span id="num-messages"></span> new messages</b>
     106    </base:icon>
    140107  </td></tr></table>
    141108  </div>
Note: See TracChangeset for help on using the changeset viewer.