mirror of
https://github.com/ascribe/onion.git
synced 2025-01-05 11:25:09 +01:00
add routine to refresh specific edition list
This commit is contained in:
parent
373aa89041
commit
cc89475d0c
@ -8,6 +8,7 @@ class EditionListActions {
|
|||||||
constructor() {
|
constructor() {
|
||||||
this.generateActions(
|
this.generateActions(
|
||||||
'updateEditionList',
|
'updateEditionList',
|
||||||
|
'refreshEditionList',
|
||||||
'selectEdition',
|
'selectEdition',
|
||||||
'clearAllEditionSelections',
|
'clearAllEditionSelections',
|
||||||
'closeAllEditionLists',
|
'closeAllEditionLists',
|
||||||
@ -16,7 +17,7 @@ class EditionListActions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fetchEditionList(pieceId, page, pageSize, orderBy, orderAsc) {
|
fetchEditionList(pieceId, page, pageSize, orderBy, orderAsc) {
|
||||||
if(!orderBy && typeof orderAsc == 'undefined') {
|
if(!orderBy && typeof orderAsc === 'undefined') {
|
||||||
orderBy = 'edition_number';
|
orderBy = 'edition_number';
|
||||||
orderAsc = true;
|
orderAsc = true;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import UserActions from '../../actions/user_actions';
|
|||||||
import UserStore from '../../stores/user_store';
|
import UserStore from '../../stores/user_store';
|
||||||
|
|
||||||
import AclButton from '../ascribe_buttons/acl_button';
|
import AclButton from '../ascribe_buttons/acl_button';
|
||||||
import DeleteButton from '../ascribe_buttons/delete_button';
|
|
||||||
|
|
||||||
let AclButtonList = React.createClass({
|
let AclButtonList = React.createClass({
|
||||||
propTypes: {
|
propTypes: {
|
||||||
@ -73,9 +72,6 @@ let AclButtonList = React.createClass({
|
|||||||
pieceOrEditions={this.props.editions}
|
pieceOrEditions={this.props.editions}
|
||||||
currentUser={this.state.currentUser}
|
currentUser={this.state.currentUser}
|
||||||
handleSuccess={this.props.handleSuccess} />
|
handleSuccess={this.props.handleSuccess} />
|
||||||
<DeleteButton
|
|
||||||
handleSuccess={this.props.handleSuccess}
|
|
||||||
editions={this.props.editions}/>
|
|
||||||
{this.props.children}
|
{this.props.children}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -9,13 +9,9 @@ import EditionDeleteForm from '../ascribe_forms/form_delete_edition';
|
|||||||
import EditionRemoveFromCollectionForm from '../ascribe_forms/form_remove_editions_from_collection';
|
import EditionRemoveFromCollectionForm from '../ascribe_forms/form_remove_editions_from_collection';
|
||||||
import ModalWrapper from '../ascribe_modal/modal_wrapper';
|
import ModalWrapper from '../ascribe_modal/modal_wrapper';
|
||||||
|
|
||||||
import GlobalNotificationModel from '../../models/global_notification_model';
|
|
||||||
import GlobalNotificationActions from '../../actions/global_notification_actions';
|
|
||||||
|
|
||||||
import { getAvailableAcls } from '../../utils/acl_utils';
|
import { getAvailableAcls } from '../../utils/acl_utils';
|
||||||
import { getLangText } from '../../utils/lang_utils.js';
|
import { getLangText } from '../../utils/lang_utils.js';
|
||||||
|
|
||||||
import EditionListActions from '../../actions/edition_list_actions';
|
|
||||||
|
|
||||||
let DeleteButton = React.createClass({
|
let DeleteButton = React.createClass({
|
||||||
propTypes: {
|
propTypes: {
|
||||||
@ -25,24 +21,6 @@ let DeleteButton = React.createClass({
|
|||||||
|
|
||||||
mixins: [Router.Navigation],
|
mixins: [Router.Navigation],
|
||||||
|
|
||||||
showNotification(response) {
|
|
||||||
if (this.props.editions.constructor === Array){
|
|
||||||
this.props.editions
|
|
||||||
.forEach((edition) => {
|
|
||||||
EditionListActions.fetchEditionList(edition.parent);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
EditionListActions.fetchEditionList(this.props.editions.id);
|
|
||||||
}
|
|
||||||
EditionListActions.clearAllEditionSelections();
|
|
||||||
EditionListActions.closeAllEditionLists();
|
|
||||||
this.props.handleSuccess();
|
|
||||||
this.transitionTo('pieces');
|
|
||||||
let notification = new GlobalNotificationModel(response.notification, 'success');
|
|
||||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
|
||||||
},
|
|
||||||
|
|
||||||
render: function () {
|
render: function () {
|
||||||
let availableAcls = getAvailableAcls(this.props.editions);
|
let availableAcls = getAvailableAcls(this.props.editions);
|
||||||
let btnDelete = null;
|
let btnDelete = null;
|
||||||
@ -62,7 +40,7 @@ let DeleteButton = React.createClass({
|
|||||||
return (
|
return (
|
||||||
<ModalWrapper
|
<ModalWrapper
|
||||||
button={btnDelete}
|
button={btnDelete}
|
||||||
handleSuccess={ this.showNotification }
|
handleSuccess={this.props.handleSuccess}
|
||||||
title={getLangText('Remove Edition')}
|
title={getLangText('Remove Edition')}
|
||||||
tooltip={getLangText('Click to remove edition')}>
|
tooltip={getLangText('Click to remove edition')}>
|
||||||
{ content }
|
{ content }
|
||||||
|
@ -12,6 +12,10 @@ import UserActions from '../../actions/user_actions';
|
|||||||
import UserStore from '../../stores/user_store';
|
import UserStore from '../../stores/user_store';
|
||||||
import CoaActions from '../../actions/coa_actions';
|
import CoaActions from '../../actions/coa_actions';
|
||||||
import CoaStore from '../../stores/coa_store';
|
import CoaStore from '../../stores/coa_store';
|
||||||
|
import PieceListActions from '../../actions/piece_list_actions';
|
||||||
|
import PieceListStore from '../../stores/piece_list_store';
|
||||||
|
import EditionListActions from '../../actions/edition_list_actions';
|
||||||
|
|
||||||
|
|
||||||
import MediaContainer from './media_container';
|
import MediaContainer from './media_container';
|
||||||
|
|
||||||
@ -24,12 +28,10 @@ import InputTextAreaToggable from './../ascribe_forms/input_textarea_toggable';
|
|||||||
|
|
||||||
import EditionFurtherDetails from './further_details';
|
import EditionFurtherDetails from './further_details';
|
||||||
|
|
||||||
//import PieceExtraDataForm from './../ascribe_forms/form_piece_extradata';
|
|
||||||
import RequestActionForm from './../ascribe_forms/form_request_action';
|
import RequestActionForm from './../ascribe_forms/form_request_action';
|
||||||
import EditionActions from '../../actions/edition_actions';
|
import EditionActions from '../../actions/edition_actions';
|
||||||
import AclButtonList from './../ascribe_buttons/acl_button_list';
|
import AclButtonList from './../ascribe_buttons/acl_button_list';
|
||||||
|
import DeleteButton from '../ascribe_buttons/delete_button';
|
||||||
//import ReactS3FineUploader from './../ascribe_uploader/react_s3_fine_uploader';
|
|
||||||
|
|
||||||
import GlobalNotificationModel from '../../models/global_notification_model';
|
import GlobalNotificationModel from '../../models/global_notification_model';
|
||||||
import GlobalNotificationActions from '../../actions/global_notification_actions';
|
import GlobalNotificationActions from '../../actions/global_notification_actions';
|
||||||
@ -38,6 +40,7 @@ import apiUrls from '../../constants/api_urls';
|
|||||||
import AppConstants from '../../constants/application_constants';
|
import AppConstants from '../../constants/application_constants';
|
||||||
|
|
||||||
import { getLangText } from '../../utils/lang_utils';
|
import { getLangText } from '../../utils/lang_utils';
|
||||||
|
import { mergeOptions } from '../../utils/general_utils';
|
||||||
|
|
||||||
let Link = Router.Link;
|
let Link = Router.Link;
|
||||||
/**
|
/**
|
||||||
@ -49,8 +52,13 @@ let Edition = React.createClass({
|
|||||||
loadEdition: React.PropTypes.func
|
loadEdition: React.PropTypes.func
|
||||||
},
|
},
|
||||||
|
|
||||||
|
mixins: [Router.Navigation],
|
||||||
|
|
||||||
getInitialState() {
|
getInitialState() {
|
||||||
return UserStore.getState();
|
return mergeOptions(
|
||||||
|
UserStore.getState(),
|
||||||
|
PieceListStore.getState()
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
@ -66,6 +74,20 @@ let Edition = React.createClass({
|
|||||||
this.setState(state);
|
this.setState(state);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
handleDeleteSuccess(response) {
|
||||||
|
PieceListActions.fetchPieceList(this.state.page, this.state.pageSize, this.state.search, this.state.orderBy, this.state.orderAsc);
|
||||||
|
|
||||||
|
// we don't need to refresh the edition list for a piece here, since its reloaded from
|
||||||
|
// scatch once you click on show-editions anyway
|
||||||
|
EditionListActions.closeAllEditionLists();
|
||||||
|
EditionListActions.clearAllEditionSelections();
|
||||||
|
|
||||||
|
let notification = new GlobalNotificationModel(response.notification, 'success');
|
||||||
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||||
|
|
||||||
|
this.transitionTo('pieces');
|
||||||
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<Row>
|
<Row>
|
||||||
@ -82,7 +104,8 @@ let Edition = React.createClass({
|
|||||||
</div>
|
</div>
|
||||||
<EditionSummary
|
<EditionSummary
|
||||||
currentUser={this.state.currentUser}
|
currentUser={this.state.currentUser}
|
||||||
edition={this.props.edition} />
|
edition={this.props.edition}
|
||||||
|
handleDeleteSuccess={this.handleDeleteSuccess}/>
|
||||||
|
|
||||||
<CollapsibleParagraph
|
<CollapsibleParagraph
|
||||||
title={getLangText('Certificate of Authenticity')}
|
title={getLangText('Certificate of Authenticity')}
|
||||||
@ -152,7 +175,8 @@ let Edition = React.createClass({
|
|||||||
|
|
||||||
let EditionSummary = React.createClass({
|
let EditionSummary = React.createClass({
|
||||||
propTypes: {
|
propTypes: {
|
||||||
edition: React.PropTypes.object
|
edition: React.PropTypes.object,
|
||||||
|
handleDeleteSuccess: React.PropTypes.func
|
||||||
},
|
},
|
||||||
|
|
||||||
getTransferWithdrawData(){
|
getTransferWithdrawData(){
|
||||||
@ -173,14 +197,13 @@ let EditionSummary = React.createClass({
|
|||||||
status = <EditionDetailProperty label="STATUS" value={ statusStr }/>;
|
status = <EditionDetailProperty label="STATUS" value={ statusStr }/>;
|
||||||
if (this.props.edition.pending_new_owner && this.props.edition.acl.acl_withdraw_transfer){
|
if (this.props.edition.pending_new_owner && this.props.edition.acl.acl_withdraw_transfer){
|
||||||
status = (
|
status = (
|
||||||
|
|
||||||
<EditionDetailProperty label="STATUS" value={ statusStr } />
|
<EditionDetailProperty label="STATUS" value={ statusStr } />
|
||||||
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
},
|
},
|
||||||
|
|
||||||
getActions(){
|
getActions(){
|
||||||
let actions = null;
|
let actions = null;
|
||||||
if (this.props.edition.request_action && this.props.edition.request_action.length > 0){
|
if (this.props.edition.request_action && this.props.edition.request_action.length > 0){
|
||||||
@ -214,6 +237,9 @@ let EditionSummary = React.createClass({
|
|||||||
editions={[this.props.edition]}
|
editions={[this.props.edition]}
|
||||||
handleSuccess={this.handleSuccess}>
|
handleSuccess={this.handleSuccess}>
|
||||||
{withdrawButton}
|
{withdrawButton}
|
||||||
|
<DeleteButton
|
||||||
|
handleSuccess={this.props.handleDeleteSuccess}
|
||||||
|
editions={[this.props.edition]}/>
|
||||||
</AclButtonList>
|
</AclButtonList>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>);
|
</Row>);
|
||||||
|
@ -15,6 +15,7 @@ import PieceListActions from '../../actions/piece_list_actions';
|
|||||||
|
|
||||||
import PieceListBulkModalSelectedEditionsWidget from './piece_list_bulk_modal_selected_editions_widget';
|
import PieceListBulkModalSelectedEditionsWidget from './piece_list_bulk_modal_selected_editions_widget';
|
||||||
import AclButtonList from '../ascribe_buttons/acl_button_list';
|
import AclButtonList from '../ascribe_buttons/acl_button_list';
|
||||||
|
import DeleteButton from '../ascribe_buttons/delete_button';
|
||||||
|
|
||||||
import { getAvailableAcls } from '../../utils/acl_utils';
|
import { getAvailableAcls } from '../../utils/acl_utils';
|
||||||
import { getLangText } from '../../utils/lang_utils.js';
|
import { getLangText } from '../../utils/lang_utils.js';
|
||||||
@ -79,11 +80,7 @@ let PieceListBulkModal = React.createClass({
|
|||||||
|
|
||||||
this.fetchSelectedPieceEditionList()
|
this.fetchSelectedPieceEditionList()
|
||||||
.forEach((pieceId) => {
|
.forEach((pieceId) => {
|
||||||
let editionsForPiece = this.state.editionList[pieceId];
|
EditionListActions.refreshEditionList(pieceId);
|
||||||
for(let i = 1; i <= editionsForPiece.page; i++) {
|
|
||||||
EditionListActions.fetchEditionList(pieceId, i, editionsForPiece.pageSize, editionsForPiece.orderBy, editionsForPiece.orderAsc);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
EditionListActions.clearAllEditionSelections();
|
EditionListActions.clearAllEditionSelections();
|
||||||
},
|
},
|
||||||
@ -114,7 +111,11 @@ let PieceListBulkModal = React.createClass({
|
|||||||
availableAcls={availableAcls}
|
availableAcls={availableAcls}
|
||||||
editions={selectedEditions}
|
editions={selectedEditions}
|
||||||
handleSuccess={this.handleSuccess}
|
handleSuccess={this.handleSuccess}
|
||||||
className="text-center ascribe-button-list collapse-group"/>
|
className="text-center ascribe-button-list collapse-group">
|
||||||
|
<DeleteButton
|
||||||
|
handleSuccess={this.handleSuccess}
|
||||||
|
editions={selectedEditions}/>
|
||||||
|
</AclButtonList>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -56,6 +56,31 @@ class EditionListStore {
|
|||||||
this.editionList[pieceId].count = count;
|
this.editionList[pieceId].count = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We often just have to refresh the edition list for a certain pieceId,
|
||||||
|
* this method provides exactly that functionality without any side effects
|
||||||
|
*/
|
||||||
|
onRefreshEditionList(pieceId) {
|
||||||
|
const prevEditionListLength = this.editionList[pieceId].length;
|
||||||
|
const prevEditionListPage = this.editionList[pieceId].page;
|
||||||
|
const prevEditionListPageSize = this.editionList[pieceId].pageSize;
|
||||||
|
|
||||||
|
// to clear an array, david walsh recommends to just set it's length to zero
|
||||||
|
// http://davidwalsh.name/empty-array
|
||||||
|
this.editionList[pieceId].length = 0;
|
||||||
|
|
||||||
|
// refetch editions with adjusted page size
|
||||||
|
EditionsListActions.fetchEditionList(pieceId, 1, prevEditionListLength, this.editionList[pieceId].orderBy, this.editionList[pieceId].orderAsc)
|
||||||
|
.then(() => {
|
||||||
|
// reset back to the normal pageSize and page
|
||||||
|
this.editionList[pieceId].page = prevEditionListPage;
|
||||||
|
this.editionList[pieceId].pageSize = prevEditionListPageSize;
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
onSelectEdition({pieceId, editionId, toValue}) {
|
onSelectEdition({pieceId, editionId, toValue}) {
|
||||||
this.editionList[pieceId].forEach((edition) => {
|
this.editionList[pieceId].forEach((edition) => {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user