Skip to content

Commit

Permalink
Merge pull request #395 from UNC-Libraries/custom-colls-followup2
Browse files Browse the repository at this point in the history
Added null check when setting the list of views in CollectionSettings…
  • Loading branch information
daines committed Oct 14, 2015
2 parents 466502f + 38b576d commit 66eecfc
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class EditCollectionSettingsController {
@Autowired
private SolrQueryLayerService solrQueryService;

private final String defaultDefaultTab = ContainerView.DESCRIPTION.name();
private final String defaultDefaultTab = ContainerView.STRUCTURE.name();
private final List<String> defaultTabList = Arrays.asList(ContainerView.DESCRIPTION.name(),
ContainerView.STRUCTURE.name(), ContainerView.EXPORTS.name());

Expand Down
26 changes: 22 additions & 4 deletions metadata/src/main/java/edu/unc/lib/dl/model/ContainerSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public List<String> getViews() {
}

public void setViews(List<String> views) {
if (views == null) {
this.views = null;
return;
}

this.views = new ArrayList<>(views.size());
for (ContainerView view : ContainerView.values()) {
if (views.contains(view.name())) {
Expand All @@ -87,13 +92,14 @@ public String getViewDisplayName(String view) {
return viewEnum == null? null : viewEnum.getDisplayName();
}

public Map<String, Map<String, String>> getViewInfo() {
Map<String, Map<String, String>> result = new LinkedHashMap<>();
public Map<String, Map<String, Object>> getViewInfo() {
Map<String, Map<String, Object>> result = new LinkedHashMap<>();

for (ContainerView view : ContainerView.values()) {
Map<String, String> entry = new HashMap<>();
Map<String, Object> entry = new HashMap<>();
entry.put("displayName", view.getDisplayName());
entry.put("description", view.getDescription());
entry.put("required", new Boolean(view.isRequired()));

result.put(view.name(), entry);
}
Expand All @@ -107,14 +113,22 @@ public static enum ContainerView {
LIST_CONTENTS("List Contents", "A result view of files within this collection with hierarchy flattened"),
DEPARTMENTS("Departments", "A list of the departments associated with objects in this collection"),
DESCRIPTION("Description", "An overview of the contents of the collection and descriptive metadata"),
EXPORTS("Metadata", "Export options for data associated with this collection.");
EXPORTS("Metadata", "Export options for data associated with this collection.", true);

String displayName;
String description;
boolean required;

private ContainerView(String displayName, String description) {
this.displayName = displayName;
this.description = description;
this.required = false;
}

private ContainerView(String displayName, String description, boolean required) {
this.displayName = displayName;
this.description = description;
this.required = required;
}

public String getDisplayName() {
Expand All @@ -124,5 +138,9 @@ public String getDisplayName() {
public String getDescription() {
return description;
}

public boolean isRequired() {
return required;
}
}
}
6 changes: 6 additions & 0 deletions static/css/admin/admin_forms.css
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@
margin: 0;
text-indent: 0;
color: #333;
cursor: pointer;
}

.selectable_multi li span {
Expand All @@ -295,6 +296,11 @@
.selectable_multi .selected:hover {
background-color: #f8f8ff;
}

.selectable_multi .disabled {
color: #888;
cursor: default;
}

.selectable_multi_actions {
width: 40%;
Expand Down
24 changes: 20 additions & 4 deletions static/js/admin/src/action/EditCollectionSettingsAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ define('EditCollectionSettingsAction', ['jquery', 'underscore', 'RemoteStateChan
EditCollectionSettingsAction.prototype.execute = function() {
var self = this;

this.dialog = $("<div class='containingDialog'>Loading...</div>");
this.dialog = $("<div class='containingDialog'></div>");
this.dialog.dialog({
autoOpen: true,
width: '560',
Expand All @@ -17,6 +17,13 @@ define('EditCollectionSettingsAction', ['jquery', 'underscore', 'RemoteStateChan
title: "Collection Settings"
});

var loadingOverlay = new ModalLoadingOverlay(this.dialog, {
autoOpen : false,
type : 'icon',
dialog : self.dialog
});
loadingOverlay.open();

$.ajax({
url : "editCollection/" + this.context.target.pid,
type : "GET"
Expand All @@ -27,6 +34,9 @@ define('EditCollectionSettingsAction', ['jquery', 'underscore', 'RemoteStateChan
// Recenter the dialog
self.dialog.dialog("option", "position", "center");

// Clear out the initial loading overlay
loadingOverlay.remove();

self.$form = self.dialog.first();
var defaultViewSelect = $("#full_record_default_view", self.$form);

Expand All @@ -50,6 +60,9 @@ define('EditCollectionSettingsAction', ['jquery', 'underscore', 'RemoteStateChan
}

function toggleChecked(checkbox, checked) {
if (checkbox.prop("disabled")) {
return;
}
if (checked === undefined) {
checked = !checkbox.prop("checked");
}
Expand All @@ -73,9 +86,13 @@ define('EditCollectionSettingsAction', ['jquery', 'underscore', 'RemoteStateChan
}

// Mark starting selected views
$.each(collectionSettings.viewInfo, function(viewKey) {
$.each(collectionSettings.viewInfo, function(viewKey, viewInfo) {
var checkbox = $("#full_record_views_select li[data-viewid='" + viewKey + "']", self.$form).find("input");
toggleChecked(checkbox, $.inArray(viewKey, collectionSettings.views) != -1);
var checked = viewInfo.required || $.inArray(viewKey, collectionSettings.views) != -1;
toggleChecked(checkbox, checked);
if (viewInfo.required) {
checkbox.prop("disabled", true).parent("li").first().addClass("disabled");
}
});

// Enable help text
Expand All @@ -96,7 +113,6 @@ define('EditCollectionSettingsAction', ['jquery', 'underscore', 'RemoteStateChan
var overlay = new ModalLoadingOverlay(self.$form, {
autoOpen : false,
type : 'icon',
text : 'updating...',
dialog : self.dialog
});
overlay.open();
Expand Down

0 comments on commit 66eecfc

Please sign in to comment.