diff options
| author | Alon Levy <alon@pobox.com> | 2015-01-21 17:29:31 +0200 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2015-01-21 17:36:59 +0200 |
| commit | f7932d4ded03ee98092882541f1fad4c055935f4 (patch) | |
| tree | e20c4baeb3febcf7c02278e315bf4027708666ee | |
| parent | 0f3649984c5dc29ef1909511bca5b9a2744fb192 (diff) | |
templates/index: move username and initials setting to server. Fixes #286
| -rw-r--r-- | res/templates/index.html | 4 | ||||
| -rw-r--r-- | src/client/main.js | 16 | ||||
| -rw-r--r-- | src/server/rz_api.py | 15 |
3 files changed, 16 insertions, 19 deletions
diff --git a/res/templates/index.html b/res/templates/index.html index 22aefcd0..ff051fdd 100644 --- a/res/templates/index.html +++ b/res/templates/index.html @@ -23,8 +23,8 @@ <div class="user-area"> <div class="username"> <div class="profile-circle"></div> - <span class="profile-initials">AN<!-- must be two letters because of css --></span> - <div class="profile-username">Welcome <span id="user_id">Anonymous</span>! <span id="logout-button" class="button">Logout</span></div> + <span class="profile-initials">{{ profileinitials }}</span> + <div class="profile-username">Welcome <span id="user_id">{{ username }}</span>! <span id="logout-button" class="button">Logout</span></div> </div> <img class="organization-logo" src="/static/img/CRI-logo.png"> </div> diff --git a/src/client/main.js b/src/client/main.js index ebf54530..0b728f95 100644 --- a/src/client/main.js +++ b/src/client/main.js @@ -8,20 +8,6 @@ function(textanalysis_ui, textanalysis, buttons, history, drag_n_drop, obj.size = Math.max(obj.savesize, obj.value.length); } - function get_user_initials() { - var words = logged_username.split(' '), - first_initial = words.length >= 1 && words[0].length >= 1 ? words[0][0] : ' ', - second_initial = words.length >= 2 && words[1].length >= 1 ? words[1][0] : (words.length >= 1 && words[0].length > 1 ? words[0][1] : '_'); - - return (first_initial + second_initial).toUpperCase(); - } - - function update_username_ui() { - // logged_username is defined in the body via a template server set variable - $('.profile-initials').html(get_user_initials()); - $('#user_id').html(logged_username); - } - this.main = function() { var json; @@ -32,8 +18,6 @@ function(textanalysis_ui, textanalysis, buttons, history, drag_n_drop, textanalysis_ui.main(); - update_username_ui(); - json = util.getParameterByName('json'); if (json) { rz_core.load_from_json(json); diff --git a/src/server/rz_api.py b/src/server/rz_api.py index 98d46136..8b7ac825 100644 --- a/src/server/rz_api.py +++ b/src/server/rz_api.py @@ -150,10 +150,23 @@ def monitor__server_info(): "time: " + dt.strftime("%H:%M:%S") + "<br>" + \ "</p></body></html>" +def username_initials(username): + """ + return two letter (always) initials of username. + we do it here rather then on the client side to avoid rendering twice, once + 'annonymous' and later the real name, because of loading delays + """ + words = username.split(' ') + first_initial = words[0][0] if len(words) >= 1 and len(words[0]) >= 1 else ' ' + second_initial = (words[1][0] if len(words) >= 2 and len(words[1]) >= 1 else + (words[0][1] if len(words) >= 1 and len(words[0]) > 1 else '_')) + return (first_initial + second_initial).upper() + def index(): session_username = session.get('username') username = escape(session_username if session_username != None else "Anonymous Stranger") - return render_template('index.html', username=username) + profileinitials = username_initials(username) + return render_template('index.html', username=username, profileinitials=profileinitials) def login(): |
