mirror of
https://github.com/ascribe/onion.git
synced 2025-01-03 10:25:08 +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() {
|
||||
this.generateActions(
|
||||
'updateEditionList',
|
||||
'refreshEditionList',
|
||||
'selectEdition',
|
||||
'clearAllEditionSelections',
|
||||
'closeAllEditionLists',
|
||||
@ -16,7 +17,7 @@ class EditionListActions {
|
||||
}
|
||||
|
||||
fetchEditionList(pieceId, page, pageSize, orderBy, orderAsc) {
|
||||
if(!orderBy && typeof orderAsc == 'undefined') {
|
||||
if(!orderBy && typeof orderAsc === 'undefined') {
|
||||
orderBy = 'edition_number';
|
||||
orderAsc = true;
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import UserActions from '../../actions/user_actions';
|
||||
import UserStore from '../../stores/user_store';
|
||||
|
||||
import AclButton from '../ascribe_buttons/acl_button';
|
||||
import DeleteButton from '../ascribe_buttons/delete_button';
|
||||
|
||||
let AclButtonList = React.createClass({
|
||||
propTypes: {
|
||||
@ -73,9 +72,6 @@ let AclButtonList = React.createClass({
|
||||
pieceOrEditions={this.props.editions}
|
||||
currentUser={this.state.currentUser}
|
||||
handleSuccess={this.props.handleSuccess} />
|
||||
<DeleteButton
|
||||
handleSuccess={this.props.handleSuccess}
|
||||
editions={this.props.editions}/>
|
||||
{this.props.children}
|
||||
</div>
|
||||
);
|
||||
|
@ -9,13 +9,9 @@ import EditionDeleteForm from '../ascribe_forms/form_delete_edition';
|
||||
import EditionRemoveFromCollectionForm from '../ascribe_forms/form_remove_editions_from_collection';
|
||||
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 { getLangText } from '../../utils/lang_utils.js';
|
||||
|
||||
import EditionListActions from '../../actions/edition_list_actions';
|
||||
|
||||
let DeleteButton = React.createClass({
|
||||
propTypes: {
|
||||
@ -25,24 +21,6 @@ let DeleteButton = React.createClass({
|
||||
|
||||
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 () {
|
||||
let availableAcls = getAvailableAcls(this.props.editions);
|
||||
let btnDelete = null;
|
||||
@ -56,13 +34,13 @@ let DeleteButton = React.createClass({
|
||||
content = <EditionRemoveFromCollectionForm editions={ this.props.editions }/>;
|
||||
btnDelete = <Button bsStyle="danger" className="btn-delete" bsSize="small">{getLangText('REMOVE FROM COLLECTION')}</Button>;
|
||||
}
|
||||
else{
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<ModalWrapper
|
||||
button={ btnDelete }
|
||||
handleSuccess={ this.showNotification }
|
||||
button={btnDelete}
|
||||
handleSuccess={this.props.handleSuccess}
|
||||
title={getLangText('Remove Edition')}
|
||||
tooltip={getLangText('Click to remove edition')}>
|
||||
{ content }
|
||||
|
@ -12,6 +12,10 @@ import UserActions from '../../actions/user_actions';
|
||||
import UserStore from '../../stores/user_store';
|
||||
import CoaActions from '../../actions/coa_actions';
|
||||
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';
|
||||
|
||||
@ -24,12 +28,10 @@ import InputTextAreaToggable from './../ascribe_forms/input_textarea_toggable';
|
||||
|
||||
import EditionFurtherDetails from './further_details';
|
||||
|
||||
//import PieceExtraDataForm from './../ascribe_forms/form_piece_extradata';
|
||||
import RequestActionForm from './../ascribe_forms/form_request_action';
|
||||
import EditionActions from '../../actions/edition_actions';
|
||||
import AclButtonList from './../ascribe_buttons/acl_button_list';
|
||||
|
||||
//import ReactS3FineUploader from './../ascribe_uploader/react_s3_fine_uploader';
|
||||
import DeleteButton from '../ascribe_buttons/delete_button';
|
||||
|
||||
import GlobalNotificationModel from '../../models/global_notification_model';
|
||||
import GlobalNotificationActions from '../../actions/global_notification_actions';
|
||||
@ -38,6 +40,7 @@ import apiUrls from '../../constants/api_urls';
|
||||
import AppConstants from '../../constants/application_constants';
|
||||
|
||||
import { getLangText } from '../../utils/lang_utils';
|
||||
import { mergeOptions } from '../../utils/general_utils';
|
||||
|
||||
let Link = Router.Link;
|
||||
/**
|
||||
@ -49,8 +52,13 @@ let Edition = React.createClass({
|
||||
loadEdition: React.PropTypes.func
|
||||
},
|
||||
|
||||
mixins: [Router.Navigation],
|
||||
|
||||
getInitialState() {
|
||||
return UserStore.getState();
|
||||
return mergeOptions(
|
||||
UserStore.getState(),
|
||||
PieceListStore.getState()
|
||||
);
|
||||
},
|
||||
|
||||
componentDidMount() {
|
||||
@ -66,6 +74,20 @@ let Edition = React.createClass({
|
||||
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() {
|
||||
return (
|
||||
<Row>
|
||||
@ -82,7 +104,8 @@ let Edition = React.createClass({
|
||||
</div>
|
||||
<EditionSummary
|
||||
currentUser={this.state.currentUser}
|
||||
edition={this.props.edition} />
|
||||
edition={this.props.edition}
|
||||
handleDeleteSuccess={this.handleDeleteSuccess}/>
|
||||
|
||||
<CollapsibleParagraph
|
||||
title={getLangText('Certificate of Authenticity')}
|
||||
@ -152,7 +175,8 @@ let Edition = React.createClass({
|
||||
|
||||
let EditionSummary = React.createClass({
|
||||
propTypes: {
|
||||
edition: React.PropTypes.object
|
||||
edition: React.PropTypes.object,
|
||||
handleDeleteSuccess: React.PropTypes.func
|
||||
},
|
||||
|
||||
getTransferWithdrawData(){
|
||||
@ -173,14 +197,13 @@ let EditionSummary = React.createClass({
|
||||
status = <EditionDetailProperty label="STATUS" value={ statusStr }/>;
|
||||
if (this.props.edition.pending_new_owner && this.props.edition.acl.acl_withdraw_transfer){
|
||||
status = (
|
||||
|
||||
<EditionDetailProperty label="STATUS" value={ statusStr } />
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
return status;
|
||||
},
|
||||
|
||||
getActions(){
|
||||
let actions = null;
|
||||
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]}
|
||||
handleSuccess={this.handleSuccess}>
|
||||
{withdrawButton}
|
||||
<DeleteButton
|
||||
handleSuccess={this.props.handleDeleteSuccess}
|
||||
editions={[this.props.edition]}/>
|
||||
</AclButtonList>
|
||||
</Col>
|
||||
</Row>);
|
||||
|
@ -15,6 +15,7 @@ import PieceListActions from '../../actions/piece_list_actions';
|
||||
|
||||
import PieceListBulkModalSelectedEditionsWidget from './piece_list_bulk_modal_selected_editions_widget';
|
||||
import AclButtonList from '../ascribe_buttons/acl_button_list';
|
||||
import DeleteButton from '../ascribe_buttons/delete_button';
|
||||
|
||||
import { getAvailableAcls } from '../../utils/acl_utils';
|
||||
import { getLangText } from '../../utils/lang_utils.js';
|
||||
@ -79,11 +80,7 @@ let PieceListBulkModal = React.createClass({
|
||||
|
||||
this.fetchSelectedPieceEditionList()
|
||||
.forEach((pieceId) => {
|
||||
let editionsForPiece = this.state.editionList[pieceId];
|
||||
for(let i = 1; i <= editionsForPiece.page; i++) {
|
||||
EditionListActions.fetchEditionList(pieceId, i, editionsForPiece.pageSize, editionsForPiece.orderBy, editionsForPiece.orderAsc);
|
||||
}
|
||||
|
||||
EditionListActions.refreshEditionList(pieceId);
|
||||
});
|
||||
EditionListActions.clearAllEditionSelections();
|
||||
},
|
||||
@ -114,7 +111,11 @@ let PieceListBulkModal = React.createClass({
|
||||
availableAcls={availableAcls}
|
||||
editions={selectedEditions}
|
||||
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>
|
||||
|
@ -56,6 +56,31 @@ class EditionListStore {
|
||||
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}) {
|
||||
this.editionList[pieceId].forEach((edition) => {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user