Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't show share tab when selected workflow doesn't allow it. #3138

Merged
merged 2 commits into from
Mar 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ engines:
config:
extensions:
- .es6
ignore_warnings: true
fixme:
enabled: false
rubocop:
Expand Down
11 changes: 6 additions & 5 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ecmaFeatures:
modules: true
jsx: true
parserOptions:
sourceType: module
ecmaFeatures:
jsx: true

env:
amd: true
Expand Down Expand Up @@ -61,7 +62,7 @@ rules:
no-empty-pattern: 2
no-eq-null: 2
no-eval: 2
no-extend-native: 2
no-extend-native: 1
no-extra-bind: 2
no-fallthrough: 2
no-floating-decimal: 0
Expand All @@ -78,7 +79,7 @@ rules:
no-native-reassign: 2
no-new-func: 2
no-new-wrappers: 2
no-new: 2
no-new: 1
no-octal-escape: 2
no-octal: 2
no-proto: 2
Expand Down
4 changes: 3 additions & 1 deletion app/assets/javascripts/sufia.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
//= require sufia/batch_select_all
//= require sufia/browse_everything
//= require sufia/search
//= require sufia/editor
//= require sufia/content_blocks
//= require sufia/ga_events
//= require sufia/select_submit
//= require sufia/tabs
Expand All @@ -55,6 +55,8 @@
//= require sufia/admin/admin_set_controls
//= require sufia/admin/admin_set/participants
//= require sufia/admin/admin_set/visibility
//= require sufia/editor
//= require sufia/editor/admin_set_widget
//= require sufia/save_work
//= require sufia/permissions
//= require sufia/notifications
Expand Down
25 changes: 7 additions & 18 deletions app/assets/javascripts/sufia/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
Sufia = {
initialize: function () {
this.autocomplete();
this.saveWorkControl();
this.saveWorkFixed();
this.popovers();
this.permissions();
this.notifications();
this.transfers();
this.relationshipsTable();
this.editor();
this.fileManager();
this.selectWorkType();
this.datatable();
Expand Down Expand Up @@ -40,16 +38,14 @@ Sufia = {
autocomplete.setup();
},

saveWorkControl: function () {
var sw = require('sufia/save_work/save_work_control');
var control = new sw.SaveWorkControl($("#form-progress"))
editor: function () {
var element = $("[data-behavior='work-form']")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon.

if (element.length > 0) {
var Editor = require('sufia/editor');
new Editor(element)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon.

}
},

saveWorkFixed: function () {
// Setting test to false to skip native and go right to polyfill
FixedSticky.tests.sticky = false;
$('#savewidget').fixedsticky();
},

// initialize popover helpers
popovers: function () {
Expand Down Expand Up @@ -82,13 +78,6 @@ Sufia = {
$("#proxy_deposit_request_transfer_to").userSearch();
},

relationshipsTable: function () {
var rel = require('sufia/relationships/table');
$('table.relationships-ajax-enabled').each(function () {
new rel.RelationshipsTable($(this));
});
},

selectWorkType: function () {
var selectWork = require('sufia/select_work_type');
$("[data-behavior=select-work]").each(function () {
Expand Down
116 changes: 59 additions & 57 deletions app/assets/javascripts/sufia/autocomplete.es6
Original file line number Diff line number Diff line change
@@ -1,66 +1,68 @@
import Location from 'sufia/autocomplete/location'
import Subject from 'sufia/autocomplete/subject'
import Language from 'sufia/autocomplete/language'
import Work from 'sufia/autocomplete/work'


export class Autocomplete {
constructor() {
}
constructor() {
}

// This is the initial setup for the form.
setup() {
$('[data-autocomplete]').each((index, value) => {
let selector = $(value)
switch (selector.data('autocomplete')) {
case "subject":
this.autocompleteSubject(selector);
break;
case "language":
this.autocompleteLanguage(selector);
break;
case "based_near":
this.autocompleteLocation(selector);
break;
case "work":
var user = selector.data('user');
var id = selector.data('id');
this.autocompleteWork(selector, user, id);
break;
}
});
}
// This is the initial setup for the form.
setup() {
$('[data-autocomplete]').each((index, value) => {
let selector = $(value)
switch (selector.data('autocomplete')) {
case "subject":
this.autocompleteSubject(selector);
break;
case "language":
this.autocompleteLanguage(selector);
break;
case "based_near":
this.autocompleteLocation(selector);
break;
case "work":
var user = selector.data('user');
var id = selector.data('id');
this.autocompleteWork(selector, user, id);
break;
}
});
}

// attach an auto complete based on the field
fieldAdded(cloneElem) {
var $cloneElem = $(cloneElem);
// FIXME this code (comparing the id) depends on a bug. Each input has an id and
// the id is duplicated when you press the plus button. This is not valid html.
if (/_based_near$/.test($cloneElem.attr("id"))) {
this.autocompleteLocation($cloneElem);
} else if (/_language$/.test($cloneElem.attr("id"))) {
this.autocompleteLanguage($cloneElem);
} else if (/_subject$/.test($cloneElem.attr("id"))) {
this.autocompleteSubject($cloneElem);
// attach an auto complete based on the field
fieldAdded(cloneElem) {
var $cloneElem = $(cloneElem);
// FIXME this code (comparing the id) depends on a bug. Each input has an id and
// the id is duplicated when you press the plus button. This is not valid html.
if (/_based_near$/.test($cloneElem.attr("id"))) {
this.autocompleteLocation($cloneElem);
} else if (/_language$/.test($cloneElem.attr("id"))) {
this.autocompleteLanguage($cloneElem);
} else if (/_subject$/.test($cloneElem.attr("id"))) {
this.autocompleteSubject($cloneElem);
}
}
}

autocompleteLocation(field) {
var loc = require('sufia/autocomplete/location');
new loc.Location(field, field.data('autocomplete-url'))
}
autocompleteLocation(field) {
new Location(field, field.data('autocomplete-url'))
}

autocompleteSubject(field) {
var subj = require('sufia/autocomplete/subject');
new subj.Subject(field, field.data('autocomplete-url'))
}
autocompleteSubject(field) {
new Subject(field, field.data('autocomplete-url'))
}

autocompleteLanguage(field) {
var lang = require('sufia/autocomplete/language');
new lang.Language(field, field.data('autocomplete-url'))
}
autocompleteLanguage(field) {
new Language(field, field.data('autocomplete-url'))
}

autocompleteWork(field, user, id) {
var work = require('sufia/autocomplete/work')
new work.Work(
field,
field.data('autocomplete-url'),
user,
id
)
}
autocompleteWork(field, user, id) {
new Work(
field,
field.data('autocomplete-url'),
user,
id
)
}
}
3 changes: 1 addition & 2 deletions app/assets/javascripts/sufia/autocomplete/language.es6
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export class Language {
export default class Language {
constructor(element, url) {
this.url = url
element.autocomplete(this.options());
Expand All @@ -22,4 +22,3 @@ export class Language {
};
}
}

2 changes: 1 addition & 1 deletion app/assets/javascripts/sufia/autocomplete/location.es6
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export class Location {
export default class Location {
constructor(element, url) {
this.url = url
element.autocomplete(this.options());
Expand Down
4 changes: 1 addition & 3 deletions app/assets/javascripts/sufia/autocomplete/subject.es6
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export class Subject {
export default class Subject {
constructor(element, url) {
this.url = url
element.autocomplete(this.options());
Expand All @@ -22,5 +22,3 @@ export class Subject {
};
}
}


2 changes: 1 addition & 1 deletion app/assets/javascripts/sufia/autocomplete/work.es6
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export class Work {
export default class Work {
// Autocomplete for finding possible related works (child and parent).
constructor(element, url, user, id) {
this.url = url;
Expand Down
47 changes: 47 additions & 0 deletions app/assets/javascripts/sufia/editor.es6
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import RelationshipsTable from 'sufia/relationships/table'
import SaveWorkControl from 'sufia/save_work/save_work_control'
import AdminSetWidget from 'sufia/editor/admin_set_widget'

export default class {
constructor(element) {
this.element = element
this.adminSetWidget = new AdminSetWidget(element.find('select[id$="_admin_set_id"]'))
this.sharingTabElement = $('#tab-share')

this.sharingTab()
this.relationshipsTable()
this.saveWorkControl()
this.saveWorkFixed()
}

// Display the sharing tab if they select an admin set that permits sharing
sharingTab() {
if(this.adminSetWidget) {
console.log("admin set selected")
this.adminSetWidget.on('change', (data) => this.sharingTabVisiblity(data))
this.sharingTabVisiblity(this.adminSetWidget.data())
}
}

sharingTabVisiblity(data) {
console.log("Data " + data["sharing"])
if (data["sharing"])
this.sharingTabElement.removeClass('hidden')
else
this.sharingTabElement.addClass('hidden')
}

relationshipsTable() {
new RelationshipsTable(this.element.find('table.relationships-ajax-enabled'))
}

saveWorkControl() {
new SaveWorkControl(this.element.find("#form-progress"), this.adminSetWidget)
}

saveWorkFixed() {
// Setting test to false to skip native and go right to polyfill
FixedSticky.tests.sticky = false
this.element.find('#savewidget').fixedsticky()
}
}
28 changes: 28 additions & 0 deletions app/assets/javascripts/sufia/editor/admin_set_widget.es6
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export default class {
// takes a jquery selector for a select field
// create a custom change event with the data when it changes
constructor(element) {
this.changeHandlers = []
this.element = element
element.on('change', (e) => {
this.change(this.data())
})
}

data() {
return this.element.find(":selected").data()
}

on(eventName, handler) {
switch (eventName) {
case "change":
return this.changeHandlers.push(handler);
}
}

change(data) {
for (let fn of this.changeHandlers) {
setTimeout(function() { fn(data) }, 0);
}
}
}
26 changes: 13 additions & 13 deletions app/assets/javascripts/sufia/notifications.es6
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@ export class Notifications {
}

poller(interval, url) {
setInterval(() => { this.fetchUpdates(url) }, interval);
setInterval(() => { this.fetchUpdates(url) }, interval);
}

fetchUpdates(url) {
$.getJSON( url, (data) => this.updatePage(data))
$.getJSON( url, (data) => this.updatePage(data))
}

updatePage(data) {
let notification = $('.notify_number')
notification.find('.count').html(data.notify_number)
if (data.notify_number == 0) {
notification.addClass('label-default')
notification.removeClass('label-danger')
} else {
notification.addClass('label-danger')
notification.removeClass('label-default')
}
let notification = $('.notify_number')
notification.find('.count').html(data.notify_number)
if (data.notify_number === 0) {
notification.addClass('label-default')
notification.removeClass('label-danger')
} else {
notification.addClass('label-danger')
notification.removeClass('label-default')
}
}

getIntervalSeconds(default_interval) {
var seconds = parseInt(this.queryStringParam("notification_seconds"));
return seconds || default_interval;
var seconds = parseInt(this.queryStringParam("notification_seconds"), 10);
return seconds || default_interval;
}

// During development allow the frequency of the notifications check to
Expand Down