Skip to content
This repository has been archived by the owner on Feb 25, 2021. It is now read-only.

Commit

Permalink
Require map publisher on publish, and add to map footer and panel.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=45024901
  • Loading branch information
zestyping committed Sep 26, 2013
1 parent 98ebae5 commit c3a4753
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 32 deletions.
7 changes: 6 additions & 1 deletion js/footer_view.js
Expand Up @@ -42,9 +42,10 @@ var REPORT_ABUSE_BASE_URL =
* @param {Element} popupContainer The DOM element on which to center the
* "Help" popup window.
* @param {cm.MapModel} mapModel The map model.
* @param {?string} publisherName The display name of the map publisher.
* @constructor
*/
cm.FooterView = function(parentElem, popupContainer, mapModel) {
cm.FooterView = function(parentElem, popupContainer, mapModel, publisherName) {
/**
* @type cm.MapModel
* @private
Expand All @@ -57,6 +58,10 @@ cm.FooterView = function(parentElem, popupContainer, mapModel) {
*/
this.footerSpan_ = cm.ui.create('span');

if (publisherName) {
cm.ui.append(parentElem, cm.ui.create('span', {},
'Published by ' + publisherName, cm.ui.SEPARATOR_DOT));
}
cm.ui.append(parentElem, this.footerSpan_);

if (window != window.top) {
Expand Down
3 changes: 2 additions & 1 deletion js/initialize.js
Expand Up @@ -267,7 +267,8 @@ function initialize(mapRoot, frame, jsBaseUrl, opt_menuItems,
panelView.enableMapPicker(new cm.MapPicker(panelView.getHeader(),
opt_menuItems));
}
var footerView = new cm.FooterView(footerElem, mapWrapperElem, mapModel);
var footerView = new cm.FooterView(footerElem, mapWrapperElem, mapModel,
config['publisher_name']);
goog.style.setElementShown(footerElem, !config['hide_footer'] && !preview);

new cm.BuildInfoView(mapElem);
Expand Down
5 changes: 4 additions & 1 deletion js/panel_view.js
Expand Up @@ -166,6 +166,7 @@ cm.PanelView = function(frameElem, parentElem, mapContainer,

// Create the elements for the map title and description.
var setDefaultViewLink, resetLink;
var publisherName = this.config_['publisher_name'];
cm.ui.append(parentElem,
this.panelInner_ = cm.ui.create('div', {'class': cm.css.PANEL_INNER},
this.panelOuterHeader_ = cm.ui.create(
Expand All @@ -178,7 +179,9 @@ cm.PanelView = function(frameElem, parentElem, mapContainer,
'title': MSG_DRAFT_TOOLTIP},
MSG_DRAFT_LABEL) : null,
this.titleElem_ = cm.ui.create('h1',
{'class': cm.css.MAP_TITLE})),
{'class': cm.css.MAP_TITLE}),
publisherName ? cm.ui.create('div', {},
'Published by ' + publisherName) : null),
this.descElem_ = cm.ui.create(
'div', {'class': cm.css.MAP_DESCRIPTION})),
this.panelLinks_ = cm.ui.create('div', {'class': cm.css.PANEL_LINKS},
Expand Down
1 change: 1 addition & 0 deletions maps.py
Expand Up @@ -249,6 +249,7 @@ def GetConfig(request, map_object=None, catalog_entry=None):
result['map_root'] = json.loads(catalog_entry.maproot_json)
result['map_id'] = catalog_entry.map_id
result['label'] = catalog_entry.label
result['publisher_name'] = catalog_entry.publisher_name,
key = catalog_entry.map_version_key
elif map_object: # draft map
result['map_root'] = json.loads(map_object.GetCurrentJson())
Expand Down
12 changes: 10 additions & 2 deletions model.py
Expand Up @@ -158,6 +158,10 @@ class CatalogEntryModel(db.Model):
# The displayed title (in the crisis picker). Set from the map_object.
title = db.StringProperty()

# The publisher name to display in the footer and below the map
# title, in view-mode only.
publisher_name = db.StringProperty()

# The key_name of the map_version's parent MapModel (this is redundant with
# map_version, but broken out as a property so queries can filter on it).
map_id = db.StringProperty()
Expand Down Expand Up @@ -341,8 +345,8 @@ def GetMaprootJson(self):
maproot_json = property(GetMaprootJson)

# Make the other properties of the CatalogEntryModel visible on CatalogEntry.
for x in ['domain', 'label', 'map_id', 'title', 'creator', 'created',
'last_updated', 'last_updater']:
for x in ['domain', 'label', 'map_id', 'title', 'publisher_name',
'creator', 'created', 'last_updated', 'last_updater']:
locals()[x] = property(lambda self, x=x: getattr(self.model, x))

def SetMapVersion(self, map_object):
Expand All @@ -351,6 +355,10 @@ def SetMapVersion(self, map_object):
self.model.map_version = map_object.GetCurrent().key
self.model.title = map_object.title

def SetPublisherName(self, publisher_name):
"""Sets the publisher name to be displayed in the map viewer."""
self.model.publisher_name = publisher_name

def Put(self):
"""Saves any modifications to the datastore."""
domain = str(self.domain) # accommodate Unicode strings
Expand Down
5 changes: 4 additions & 1 deletion publish.py
Expand Up @@ -26,13 +26,14 @@ class Publish(base_handler.BaseHandler):
def Post(self, domain, user): # pylint: disable=unused-argument
"""Creates, updates, or removes a catalog entry."""
label = self.request.get('label').strip()
publisher_name = self.request.get('publisher_name').strip()
if self.request.get('remove'):
model.CatalogEntry.Delete(domain, label)
self.redirect('.maps')
else:
if not re.match(r'^[\w-]+$', label): # Valid if alphanumeric, -, _
raise base_handler.Error(
400, 'Valid labels may contain letters, digits, "-", and "_".')
400, 'Valid labels may only contain letters, digits, "-", and "_".')
map_object = model.Map.Get(self.request.get('map'))
if not map_object:
raise base_handler.Error(400, 'No such map.')
Expand All @@ -41,5 +42,7 @@ def Post(self, domain, user): # pylint: disable=unused-argument
entry = (model.CatalogEntry.Get(domain, label) or
model.CatalogEntry.Create(domain, label, map_object))
entry.SetMapVersion(map_object)
if publisher_name:
entry.SetPublisherName(publisher_name)
entry.Put()
self.redirect('.maps')
60 changes: 41 additions & 19 deletions static/popups.js
Expand Up @@ -22,24 +22,6 @@ function $(id) {
return document.getElementById(id);
}

/** Update the UI of the popup. */
function updateCreatePopup() {
$('create-popup-submit').removeAttribute('disabled');
// Require organization name only if the acceptable_org checkbox is checked.
if ($('acceptable-org').checked) {
$('organization-name').style.display = 'block';
if ($('organization-input').value.replace(/^\s*/g, '') === '') {
$('create-popup-submit').setAttribute('disabled', 'disabled');
}
} else {
$('organization-name').style.display = 'none';
}
// Require at least one use-case checkbox to be selected.
if (!$('acceptable-purpose').checked && !$('acceptable-org').checked) {
$('create-popup-submit').setAttribute('disabled', 'disabled');
}
}

/**
* Hide an element.
* @param {Element} element A DOM element to hide.
Expand All @@ -60,6 +42,24 @@ function showPopup(popup) {
popup.style.top = Math.round(y) + 'px';
}

/** Update the UI of the map create popup. */
function updateCreatePopup() {
$('create-popup-submit').removeAttribute('disabled');
// Require organization name only if the acceptable_org checkbox is checked.
if ($('acceptable-org').checked) {
$('organization-name').style.display = 'block';
if ($('organization-input').value.replace(/^\s*/g, '') === '') {
$('create-popup-submit').setAttribute('disabled', 'disabled');
}
} else {
$('organization-name').style.display = 'none';
}
// Require at least one use-case checkbox to be selected.
if (!$('acceptable-purpose').checked && !$('acceptable-org').checked) {
$('create-popup-submit').setAttribute('disabled', 'disabled');
}
}

/** Display the popup required before creating a map. */
function showCreatePopup() {
showPopup($('create-popup'));
Expand All @@ -71,7 +71,7 @@ function showCreatePopup() {
updateCreatePopup();
}

/** Handle clicking on 'Create Map' in the popup. */
/** Handle clicking on 'Create map' in the popup. */
function submitCreatePopup() {
$('create-popup-domain').value = $('domain').value;
}
Expand All @@ -80,3 +80,25 @@ function submitCreatePopup() {
function showCreateDomainPopup() {
showPopup($('create-domain-popup'));
}

/** Update the UI of the publish popup. */
function updatePublishPopup() {
$('publish-popup-submit').removeAttribute('disabled');
if ($('publisher-name').value.replace(/^\s*/g, '') === '') {
$('publish-popup-submit').setAttribute('disabled', 'disabled');
}
}

/**
* Display the popup required before publishing a map.
* @param {string} mapid The map ID.
*/
function showPublishPopup(mapid) {
showPopup($('publish-popup'));
$('publish-popup-map').value = mapid;
$('publisher-name').addEventListener('change', updatePublishPopup);
$('publisher-name').addEventListener('keyup', updatePublishPopup);
$('publish-popup-domain').value = $('domain-' + mapid).value;
$('publish-popup-label').value = $('label-' + mapid).value;
updatePublishPopup();
}
4 changes: 2 additions & 2 deletions templates/create.html
Expand Up @@ -14,7 +14,7 @@
<script src="{{root}}/.static/popups.js"></script>
<div class="cm-popup" id="create-popup" style="display:none">
<h2>Acceptable use</h2>
<form method="post" action=".create" id="create-popup-form">
<form method="post" action="{{root}}/.create" id="create-popup-form">
<input type="hidden" name="domain" id="create-popup-domain">
<div class="cm-section">
<div class="cm-p">
Expand Down Expand Up @@ -69,7 +69,7 @@ <h2>Acceptable use</h2>
</div>
{% endif %}
<div class="cm-button-area">
<input type="submit" class="cm-submit cm-button" value="Create Map"
<input type="submit" class="cm-submit cm-button" value="Create map"
id="create-popup-submit" onclick="submitCreatePopup()">
<a href="{{login_url}}">
<input type="button" class="cm-button" value="Cancel"
Expand Down
12 changes: 7 additions & 5 deletions templates/map_list.html
Expand Up @@ -14,6 +14,7 @@
{% endcomment %}

{% block content %}
{% include "publish.html" %}
<table class="cm-map-list">
<tr>
<th colspan=5 class="cm-map-list-header">{{title}}</th>
Expand Down Expand Up @@ -71,15 +72,16 @@
</div>
{% endfor %}
{% if catalog_domains %}
<form action=".publish" method="post">
<select name="domain">
<form>
<select id="domain-{{m.id}}" name="domain">
{% for domain in catalog_domains %}
<option value="{{domain}}">{{domain}}</option>
{% endfor %}
</select>
<input name="label" size=20>
<input name="map" type=hidden value="{{m.id}}">
<input type=submit value="Publish">
<input id="label-{{m.id}}" name="label" size=20>
<input id="map-{{m.id}}" name="map" type=hidden value="{{m.id}}">
<input type="button" onclick="showPublishPopup('{{m.id}}')"
title="Publish map" value="Publish">
</form>
{% endif %}
</tr>
Expand Down
41 changes: 41 additions & 0 deletions templates/publish.html
@@ -0,0 +1,41 @@
{% comment %}
Copyright 2013 Google Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy
of the License at: http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distrib-
uted under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
OR CONDITIONS OF ANY KIND, either express or implied. See the License for
specific language governing permissions and limitations under the License.
{% endcomment %}

<script type="text/javascript" src="{{root}}/.static/popups.js"></script>
<div class="cm-popup" id="publish-popup" style="display:none">
<h2>Publisher name</h2>
<form method="post" action="{{root}}/.publish">
<input name="domain" id="publish-popup-domain" type=hidden>
<input name="label" id="publish-popup-label" type=hidden>
<input name="map" id="publish-popup-map" type=hidden>
<div class="cm-section">
<div class="cm-p">
Please enter a name for the attribution that will appear on the published map.
</div>
<div>
Map published by
<input type="text" id="publisher-name" name="publisher_name" size=60
placeholder="Required: Name of the publishing organization or individual">
</div>
<div class="cm-p">
To change the publisher name, you must click on 'Unpublish' and then click on 'Publish' again.
</div>
</div>
<div class="cm-button-area">
<input type="submit" class="cm-submit cm-button" value="Publish"
id="publish-popup-submit">
<input type="button" class="cm-button" value="Cancel"
onclick="hide($('publish-popup'))">
</div>
</form>
</div>

0 comments on commit c3a4753

Please sign in to comment.