Commit 6e2a78ff authored by Laurent's avatar Laurent

SIP Loan UI

parent 38d7f19c
......@@ -100,6 +100,7 @@ Label {
}
.loan-item .title,
#novelties .title {
font-weight: bold;
}
......@@ -127,6 +128,12 @@ Label {
}
.loan-item {
text-align: center;
padding: 20dip;
}
/* forms */
.form_label { font-weight: bold; }
.error { color: red; padding:0; height: auto;}
......
......@@ -5,6 +5,7 @@ import { AccountsController } from '../controllers/accounts';
import { Database,
ItemOperation,
Item,
Loan,
Account,
Hold,
......@@ -163,34 +164,55 @@ export class LibraryController extends Controller {
})
.then(
(result) => {
setTimeout( () => { this._loanItem(result.text) }, 500);
});
return result.text;
})
.then( (barcode) => {
this._turnBusyIndicator('on');
return this._portal.fetchItem(this._account, barcode);
})
.then( (item: Item) => {
console.dir(item);
this._turnBusyIndicator('off');
this.set('item', item);
this.navigate({ moduleName: "views/library/loan_item",
backstackVisible: false,
bindingContext: this });
});
}
protected _loanItem(barcode:string) {
public confirmLoanItemAction() {
this.dialogs
.prompt({
title: L('do_loan_barcode', barcode),
title: L('do_loan'),
message: L('enter_password'),
okButtonText: L('do_loan'),
cancelButtonText: L('cancel'),
inputType: this.dialogs.inputType.password
})
.then( (result) => {
return this._manager.loan(Database.current(), this._account, result.text, barcode);
})
.then( (result) => {
if (result['success'])
return this.dialogs.alert({title: L('confirm'),
message: L('loan_title_date_due',
result['title'],
new Iso8601Date(result['date_due']).asLongDate()),
okButtonText: L('OK')});
.then( (r) => {
if (!r.result) return;
this._manager
.loan(Database.current(),
this._account,
r.text,
this.get('item').getBarcode())
.then( (result) => {
if (result['success'])
return this.dialogs.alert({title: L('confirm'),
message: L('loan_title_date_due',
result['title'],
new Iso8601Date(result['due_date']).asLongDate()),
okButtonText: L('OK')});
return this.dialogs.confirm( { title: L('error'),
message: result['message'],
okButtonText: L('OK')});
return this.dialogs.confirm( { title: L('error'),
message: result['message'],
okButtonText: L('OK')});
})
})
.then( () => {
this.goBack();
});
}
......
......@@ -15,6 +15,7 @@ export {PortalDetectionFail} from './portal/portal-detection-fail';
export {Cookies} from './cookies/cookies';
export {Manager, MBPortal} from './manager';
export {Record} from './record';
export {Item} from './item';
export {Novelties} from './novelties';
export {Card} from './card';
export {Iso8601Date} from './iso8601_date';
......
import * as PortalAdapters from './portal/index';
import {PortalAdapter} from './portal/adapter';
import {Database, Account} from '../models';
import {Database, Account, Item} from '../models';
export class Portal {
protected _adapters: Map<string, PortalAdapter> = new Map<string, PortalAdapter>();
......@@ -52,7 +52,14 @@ export class Portal {
.findAdapterIdentifiedBy(account.getAdapterIdentifier())
.fetchNovelties(account, page);
}
public fetchItem(account: Account, barcode: string): Promise<Item> {
return this
.findAdapterIdentifiedBy(account.getAdapterIdentifier())
.fetchItem(account, barcode);
}
public canSearch(account: Account): boolean {
return this
......
......@@ -4,6 +4,7 @@ import {Cookies,
Account,
Database,
Loan,
Item,
Hold} from '../../models';
export abstract class PortalAdapter {
......@@ -137,6 +138,11 @@ export abstract class PortalAdapter {
}
public fetchItem(account, barcode): Promise<Item> {
return Promise.reject(null);
}
protected abstract _signIn(account: Account): Promise<any>;
public abstract getIdentifier(): string;
......
import {PortalAdapter} from './adapter';
import {Database, Account, Hold, Loan, Record} from '../../models';
import {Database, Account, Hold, Loan, Record, Item} from '../../models';
import {OAuthTokenNotSet} from './oauth-token-not-set';
......@@ -84,6 +84,28 @@ export class Bokeh extends PortalAdapter {
}
public fetchItem(account, barcode): Promise<Item> {
return this
.request(account,
{ url: account.getUrl() + '/api/catalog/item/barcode/' + barcode })
.then( (response) => {
let datas = response.content.toJSON();
let item = new Item(datas['barcode'])
item
.setTitle(datas['title'])
.setAuthor(datas['author']);
let record = datas['record'];
if (!record)
return item;
return item
.setRecordId(record['id'])
.setThumbnailUrl(record['thumbnail']);
})
}
public searchUrl(account: Account, terms: string): Promise<string> {
return Promise.resolve(account.getUrl() + '/recherche/simple/expressionRecherche/' + terms);
}
......@@ -156,6 +178,7 @@ export class Bokeh extends PortalAdapter {
}
protected _signIn(account): Promise<any> {
if (!account.credentials['token'])
......
export class Record {
protected _url: string;
protected _author: string;
protected _title: string;
protected _doc_type: string;
protected _thumbnail_url: string;
protected _id: string = '';
protected _url: string = '';
protected _author: string = '';
protected _title: string = '';
protected _doc_type: string = '';
protected _thumbnail_url: string = '';
public setId(id: string): this {
this._id = id;
return this;
}
public setUrl(url:string): Record {
public setUrl(url:string): this {
this._url = url;
return this;
}
public setDocType(doc_type: string): Record {
public setDocType(doc_type: string): this {
this._doc_type = doc_type;
return this;
}
public setThumbnailUrl(url: string): Record {
public setThumbnailUrl(url: string): this {
this._thumbnail_url = url;
return this;
}
public setTitle(title: string): Record {
public setTitle(title: string): this {
this._title = title;
return this;
}
public setAuthor(author: string): Record {
public setAuthor(author: string): this {
this._author = author;
return this;
}
......
<Page xmlns:lv="nativescript-ui-listview" xmlns:shared="views/shared" loaded="{{ onPageLoaded }}">
<Page.actionBar>
<ActionBar title="{{ L('do_loan') }}" icon="">
<NavigationButton android.systemIcon="ic_menu_back" tap="{{ goBack }}"/>
</ActionBar>
</Page.actionBar>
<StackLayout class="loan-item">
<Image src="{{ item.thumbnail_url }}" visibility="{{ item.thumbnail_url.length ? 'visible' : 'collapsed' }}" height="200"/>
<Label text="{{ item.title }}" class="title" textWrap="true"/>
<Label text="{{ item.author }}" textWrap="true" />
<GridLayout columns="*, *" rows="auto">
<Button text="{{ L('do_loan') }}" tap="{{ confirmLoanItemAction }}" col="0" row="0"/>
<Button text="{{ L('cancel') }}" tap="{{ goBack }}" col="1" row="0"/>
</GridLayout>>
</StackLayout>
</Page>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment