find
This commit is contained in:
parent
a9c5fb43fe
commit
e41942ea99
28 changed files with 240 additions and 84 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,5 +1,7 @@
|
||||||
env
|
env
|
||||||
*.pyc
|
*.pyc
|
||||||
|
*.pyo
|
||||||
|
*.pyd
|
||||||
*.gz
|
*.gz
|
||||||
*.swp
|
*.swp
|
||||||
*.min.js
|
*.min.js
|
||||||
|
|
6
ctl
6
ctl
|
@ -37,7 +37,7 @@ if [ "$1" == "start" ]; then
|
||||||
echo openmedialibrary already running
|
echo openmedialibrary already running
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
python oml server PID &
|
python2 oml server PID &
|
||||||
exit $?
|
exit $?
|
||||||
fi
|
fi
|
||||||
if [ "$1" == "debug" ]; then
|
if [ "$1" == "debug" ]; then
|
||||||
|
@ -47,7 +47,7 @@ if [ "$1" == "debug" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
shift
|
shift
|
||||||
python oml server $@
|
python2 oml server $@
|
||||||
exit $?
|
exit $?
|
||||||
fi
|
fi
|
||||||
if [ "$1" == "stop" ]; then
|
if [ "$1" == "stop" ]; then
|
||||||
|
@ -75,5 +75,5 @@ if [ "$1" == "open" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd $BASE/$NAME
|
cd $BASE/$NAME
|
||||||
python oml $@
|
python2 oml $@
|
||||||
exit $?
|
exit $?
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# vi:si:et:sw=4:sts=4:ts=4
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
|
from __future__ import division
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# vi:si:et:sw=4:sts=4:ts=4
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
|
from __future__ import division
|
||||||
|
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
from flask.ext.script import Manager
|
from flask.ext.script import Manager
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# vi:si:et:sw=4:sts=4:ts=4
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
|
from __future__ import division
|
||||||
|
|
||||||
import json
|
import json
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# vi:si:et:sw=4:sts=4:ts=4
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
|
from __future__ import division
|
||||||
|
|
||||||
from flask.ext.script import Command
|
from flask.ext.script import Command
|
||||||
|
|
||||||
|
@ -10,7 +11,10 @@ class Setup(Command):
|
||||||
"""
|
"""
|
||||||
def run(self):
|
def run(self):
|
||||||
import setup
|
import setup
|
||||||
|
import settings
|
||||||
setup.create_default_lists()
|
setup.create_default_lists()
|
||||||
|
settings.db.session.connection().execute("PRAGMA journal_mode=WAL")
|
||||||
|
settings.db.session.commit()
|
||||||
|
|
||||||
class UpdateStatic(Command):
|
class UpdateStatic(Command):
|
||||||
"""
|
"""
|
||||||
|
@ -28,8 +32,8 @@ class UpdateStatic(Command):
|
||||||
oxjs = os.path.join(settings.static_path, 'oxjs')
|
oxjs = os.path.join(settings.static_path, 'oxjs')
|
||||||
if not os.path.exists(oxjs):
|
if not os.path.exists(oxjs):
|
||||||
r('git', 'clone', 'https://git.0x2620.org/oxjs.git', oxjs)
|
r('git', 'clone', 'https://git.0x2620.org/oxjs.git', oxjs)
|
||||||
r('python', os.path.join(oxjs, 'tools', 'build', 'build.py'))
|
r('python2', os.path.join(oxjs, 'tools', 'build', 'build.py'))
|
||||||
r('python', os.path.join(settings.static_path, 'py', 'build.py'))
|
r('python2', os.path.join(settings.static_path, 'py', 'build.py'))
|
||||||
|
|
||||||
class Release(Command):
|
class Release(Command):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# vi:si:et:sw=4:sts=4:ts=4
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
|
from __future__ import division
|
||||||
|
|
||||||
# DHT placeholder
|
# DHT placeholder
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
|
from __future__ import division
|
||||||
|
|
||||||
import ed25519
|
import ed25519
|
||||||
ENCODING='base64'
|
ENCODING='base64'
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# vi:si:et:sw=4:sts=4:ts=4
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
|
from __future__ import division
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
import models
|
import models
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# vi:si:et:sw=4:sts=4:ts=4
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
|
from __future__ import division
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from flask import json
|
from flask import json
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# vi:si:et:sw=4:sts=4:ts=4
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
|
from __future__ import division
|
||||||
|
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import Image
|
import Image
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
|
from __future__ import division
|
||||||
|
|
||||||
import models
|
import models
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# vi:si:et:sw=4:sts=4:ts=4
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
|
from __future__ import division
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
@ -198,6 +199,8 @@ class Item(db.Model):
|
||||||
if value:
|
if value:
|
||||||
value = unicode(value)
|
value = unicode(value)
|
||||||
value = ox.sort_string(value).lower()
|
value = ox.sort_string(value).lower()
|
||||||
|
elif isinstance(value, list): #empty list
|
||||||
|
value = ''
|
||||||
setattr(self, 'sort_%s' % key['id'], value)
|
setattr(self, 'sort_%s' % key['id'], value)
|
||||||
|
|
||||||
def update_find(self):
|
def update_find(self):
|
||||||
|
@ -295,11 +298,14 @@ class Item(db.Model):
|
||||||
|
|
||||||
def update_cover(self):
|
def update_cover(self):
|
||||||
cover = None
|
cover = None
|
||||||
if 'cover' in self.meta:
|
if 'cover' in self.meta and self.meta['cover']:
|
||||||
cover = ox.cache.read_url(self.meta['cover'])
|
cover = ox.cache.read_url(self.meta['cover'])
|
||||||
#covers[self.id] = requests.get(self.meta['cover']).content
|
#covers[self.id] = requests.get(self.meta['cover']).content
|
||||||
if cover:
|
if cover:
|
||||||
covers[self.id] = cover
|
covers[self.id] = cover
|
||||||
|
else:
|
||||||
|
if covers[self.id]:
|
||||||
|
del covers[self.id]
|
||||||
path = self.get_path()
|
path = self.get_path()
|
||||||
if not cover and path:
|
if not cover and path:
|
||||||
cover = self.extract_cover()
|
cover = self.extract_cover()
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# vi:si:et:sw=4:sts=4:ts=4
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
|
from __future__ import division
|
||||||
|
|
||||||
import unicodedata
|
import unicodedata
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# vi:si:et:sw=4:sts=4:ts=4
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
|
from __future__ import division
|
||||||
|
|
||||||
import settings
|
import settings
|
||||||
import models
|
import models
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# vi:si:et:sw=4:sts=4:ts=4
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
|
from __future__ import division
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
@ -77,7 +78,7 @@ def cover(id, size=None):
|
||||||
if not 'coverRatio' in item.meta:
|
if not 'coverRatio' in item.meta:
|
||||||
#img = Image.open(StringIO(str(covers[id])))
|
#img = Image.open(StringIO(str(covers[id])))
|
||||||
img = Image.open(StringIO(data))
|
img = Image.open(StringIO(data))
|
||||||
item.meta['coverRatio'] = float(img.size[0])/img.size[1]
|
item.meta['coverRatio'] = img.size[0]/img.size[1]
|
||||||
db.session.add(item)
|
db.session.add(item)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
resp = make_response(data)
|
resp = make_response(data)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# vi:si:et:sw=4:sts=4:ts=4
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
|
from __future__ import division
|
||||||
|
|
||||||
import socket
|
import socket
|
||||||
import thread
|
import thread
|
||||||
|
|
|
@ -7,6 +7,7 @@ import loc
|
||||||
import lookupbyisbn
|
import lookupbyisbn
|
||||||
import openlibrary
|
import openlibrary
|
||||||
import worldcat
|
import worldcat
|
||||||
|
import google
|
||||||
|
|
||||||
providers = [
|
providers = [
|
||||||
('openlibrary', 'olid'),
|
('openlibrary', 'olid'),
|
||||||
|
@ -17,9 +18,12 @@ providers = [
|
||||||
]
|
]
|
||||||
|
|
||||||
def find(title, author=None, publisher=None, date=None):
|
def find(title, author=None, publisher=None, date=None):
|
||||||
|
results = google.find(title=title, author=author, publisher=publisher, date=date)
|
||||||
|
'''
|
||||||
results = openlibrary.find(title=title, author=author, publisher=publisher, date=date)
|
results = openlibrary.find(title=title, author=author, publisher=publisher, date=date)
|
||||||
for r in results:
|
for r in results:
|
||||||
r['mainid'] = 'olid'
|
r['mainid'] = 'olid'
|
||||||
|
'''
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def lookup(key, value):
|
def lookup(key, value):
|
||||||
|
|
38
oml/meta/google.py
Normal file
38
oml/meta/google.py
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
|
from __future__ import division
|
||||||
|
|
||||||
|
import ox.web.google
|
||||||
|
import stdnum.isbn
|
||||||
|
|
||||||
|
from .utils import find_isbns
|
||||||
|
|
||||||
|
|
||||||
|
def find(title, author=None, publisher=None, date=None):
|
||||||
|
print 'google.find', title, author, publisher, date
|
||||||
|
query = title
|
||||||
|
if author:
|
||||||
|
if isinstance(author, list):
|
||||||
|
author = ' '.join(author)
|
||||||
|
query += ' ' + author
|
||||||
|
query += ' isbn'
|
||||||
|
isbns = []
|
||||||
|
for r in ox.web.google.find(query):
|
||||||
|
isbns += find_isbns(' '.join(r))
|
||||||
|
|
||||||
|
results = []
|
||||||
|
done = set()
|
||||||
|
for isbn in isbns:
|
||||||
|
if isbn not in done:
|
||||||
|
key = 'isbn%d'%len(isbn)
|
||||||
|
#r = lookup(key, isbn)
|
||||||
|
#r['mainid'] = key
|
||||||
|
r = {
|
||||||
|
key: isbn,
|
||||||
|
'mainid': key
|
||||||
|
}
|
||||||
|
results.append(r)
|
||||||
|
done.add(isbn)
|
||||||
|
if len(isbn) == 10:
|
||||||
|
done.add(stdnum.isbn.to_isbn13(isbn))
|
||||||
|
return results
|
|
@ -33,7 +33,10 @@ def lookup(id):
|
||||||
info = {
|
info = {
|
||||||
'lccn': id
|
'lccn': id
|
||||||
}
|
}
|
||||||
info['title'] = ''.join([e.text for e in mods.findall(ns + 'titleInfo')[0]])
|
title = mods.findall(ns + 'titleInfo')
|
||||||
|
if not title:
|
||||||
|
return {}
|
||||||
|
info['title'] = ''.join([e.text for e in title[0]])
|
||||||
origin = mods.findall(ns + 'originInfo')
|
origin = mods.findall(ns + 'originInfo')
|
||||||
if origin:
|
if origin:
|
||||||
info['place'] = []
|
info['place'] = []
|
||||||
|
|
|
@ -14,6 +14,8 @@ def get_ids(key, value):
|
||||||
if m:
|
if m:
|
||||||
asin = m[0].split('/')[-3]
|
asin = m[0].split('/')[-3]
|
||||||
ids.append(('asin', asin))
|
ids.append(('asin', asin))
|
||||||
|
if key == 'isbn10':
|
||||||
|
ids.append(('isbn13', stdnum.isbn.to_isbn13(value)))
|
||||||
if key == 'asin':
|
if key == 'asin':
|
||||||
if stdnum.isbn.is_valid(value):
|
if stdnum.isbn.is_valid(value):
|
||||||
ids.append(('isbn10', value))
|
ids.append(('isbn10', value))
|
||||||
|
@ -47,14 +49,16 @@ def lookup(id):
|
||||||
r[key] = int(r[key])
|
r[key] = int(r[key])
|
||||||
desc = find_re(data, '<h2>Description:<\/h2>(.*?)<div ')
|
desc = find_re(data, '<h2>Description:<\/h2>(.*?)<div ')
|
||||||
desc = desc.replace('<br /><br />', ' ').replace('<br /> ', ' ').replace('<br />', ' ')
|
desc = desc.replace('<br /><br />', ' ').replace('<br /> ', ' ').replace('<br />', ' ')
|
||||||
r['description'] = desc
|
r['description'] = decode_html(strip_tags(desc))
|
||||||
if r['description'] == u'Description of this item is not available at this time.':
|
|
||||||
r['description'] = ''
|
|
||||||
r['cover'] = find_re(data, '<img src="(.*?)" alt="Book cover').replace('._SL160_', '')
|
r['cover'] = find_re(data, '<img src="(.*?)" alt="Book cover').replace('._SL160_', '')
|
||||||
for key in r:
|
for key in r:
|
||||||
if isinstance(r[key], basestring):
|
if isinstance(r[key], basestring):
|
||||||
r[key] = decode_html(strip_tags(r[key])).strip()
|
r[key] = decode_html(strip_tags(r[key])).strip()
|
||||||
if 'author' in r and isinstance(r['author'], basestring):
|
if 'author' in r and isinstance(r['author'], basestring) and r['author']:
|
||||||
r['author'] = [r['author']]
|
r['author'] = [r['author']]
|
||||||
|
else:
|
||||||
|
r['author'] = []
|
||||||
|
if r['description'].lower() == u'Description of this item is not available at this time.'.lower():
|
||||||
|
r['description'] = ''
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,16 @@
|
||||||
|
import re
|
||||||
|
import stdnum.isbn
|
||||||
|
|
||||||
def normalize_isbn(value):
|
def normalize_isbn(value):
|
||||||
return ''.join([s for s in value if s.isdigit() or s == 'X'])
|
return ''.join([s for s in value if s.isdigit() or s == 'X'])
|
||||||
|
|
||||||
|
def find_isbns(text):
|
||||||
|
matches = re.compile('\d[\d\-X\ ]+').findall(text)
|
||||||
|
matches = [normalize_isbn(value) for value in matches]
|
||||||
|
return [isbn for isbn in matches if stdnum.isbn.is_valid(isbn)
|
||||||
|
and len(isbn) in (10, 13)
|
||||||
|
and isbn not in (
|
||||||
|
'0' * 10,
|
||||||
|
'0' * 13,
|
||||||
|
)]
|
||||||
|
|
||||||
|
|
12
oml/utils.py
12
oml/utils.py
|
@ -8,7 +8,7 @@ import stdnum.isbn
|
||||||
|
|
||||||
import ox
|
import ox
|
||||||
|
|
||||||
from meta.utils import normalize_isbn
|
from meta.utils import normalize_isbn, find_isbns
|
||||||
|
|
||||||
def valid_olid(id):
|
def valid_olid(id):
|
||||||
return id.startswith('OL') and id.endswith('M')
|
return id.startswith('OL') and id.endswith('M')
|
||||||
|
@ -76,16 +76,6 @@ def sort_title(title):
|
||||||
title = re.sub(u'[\'!¿¡,\.;\-"\:\*\[\]]', '', title)
|
title = re.sub(u'[\'!¿¡,\.;\-"\:\*\[\]]', '', title)
|
||||||
return title.strip()
|
return title.strip()
|
||||||
|
|
||||||
def find_isbns(text):
|
|
||||||
matches = re.compile('\d[\d\-X\ ]+').findall(text)
|
|
||||||
matches = [normalize_isbn(value) for value in matches]
|
|
||||||
return [isbn for isbn in matches if stdnum.isbn.is_valid(isbn)
|
|
||||||
and len(isbn) in (10, 13)
|
|
||||||
and isbn not in (
|
|
||||||
'0' * 10,
|
|
||||||
'0' * 13,
|
|
||||||
)]
|
|
||||||
|
|
||||||
def get_position_by_id(list, key):
|
def get_position_by_id(list, key):
|
||||||
for i in range(0, len(list)):
|
for i in range(0, len(list)):
|
||||||
if list[i]['id'] == key:
|
if list[i]['id'] == key:
|
||||||
|
|
|
@ -37,8 +37,8 @@ oml.ui.appDialog = function() {
|
||||||
.css({
|
.css({
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
left: '16px',
|
left: '16px',
|
||||||
right: '24px',
|
right: '16px',
|
||||||
top: '24px',
|
top: '16px',
|
||||||
overflowY: 'auto'
|
overflowY: 'auto'
|
||||||
})
|
})
|
||||||
.html(
|
.html(
|
||||||
|
|
|
@ -34,7 +34,7 @@ oml.ui.identifyDialog = function(data) {
|
||||||
|
|
||||||
originalData = Ox.clone(data, true),
|
originalData = Ox.clone(data, true),
|
||||||
|
|
||||||
editedData,
|
idValue, titleValue,
|
||||||
|
|
||||||
$idInputs, $idButtons = {},
|
$idInputs, $idButtons = {},
|
||||||
|
|
||||||
|
@ -125,12 +125,17 @@ oml.ui.identifyDialog = function(data) {
|
||||||
var edit = Ox.extend(
|
var edit = Ox.extend(
|
||||||
{id: data.id},
|
{id: data.id},
|
||||||
$innerPanel.options('selected') == 'id'
|
$innerPanel.options('selected') == 'id'
|
||||||
? Ox.extend({}, 'foo', 'bar')
|
? idValue
|
||||||
: {olid: $list.value($list.options('selected'), 'olid')}
|
: titleValue
|
||||||
);
|
);
|
||||||
that.options({content: Ox.LoadingScreen().start()});
|
that.options({content: Ox.LoadingScreen().start()});
|
||||||
oml.api.edit(edit, function() {
|
that.disableButtons();
|
||||||
|
oml.api.edit(edit, function(result) {
|
||||||
that.close();
|
that.close();
|
||||||
|
Ox.Request.clearCache('find');
|
||||||
|
oml.$ui.browser.reloadList(true);
|
||||||
|
Ox.Request.clearCache(data.id);
|
||||||
|
oml.$ui.infoView.update(result.data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -227,7 +232,7 @@ oml.ui.identifyDialog = function(data) {
|
||||||
var value = $idInputs[index].options('elements')[1].value();
|
var value = $idInputs[index].options('elements')[1].value();
|
||||||
if (data.value) {
|
if (data.value) {
|
||||||
if (value) {
|
if (value) {
|
||||||
editedData = Ox.extend({}, id.id, value);
|
idValue = Ox.extend({}, id.id, value);
|
||||||
$idInputs.forEach(function($input, i) {
|
$idInputs.forEach(function($input, i) {
|
||||||
if (i != index) {
|
if (i != index) {
|
||||||
$input.options('elements')[0].value(false);
|
$input.options('elements')[0].value(false);
|
||||||
|
@ -251,7 +256,7 @@ oml.ui.identifyDialog = function(data) {
|
||||||
.bindEvent({
|
.bindEvent({
|
||||||
submit: function(data) {
|
submit: function(data) {
|
||||||
if (data.value) {
|
if (data.value) {
|
||||||
editedData = Ox.extend({}, id.id, data.value);
|
idValue = Ox.extend({}, id.id, data.value);
|
||||||
$idInputs.forEach(function($input, i) {
|
$idInputs.forEach(function($input, i) {
|
||||||
$input.options('elements')[0].options({
|
$input.options('elements')[0].options({
|
||||||
disabled: true,
|
disabled: true,
|
||||||
|
@ -336,54 +341,53 @@ oml.ui.identifyDialog = function(data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderResults(items) {
|
function renderResults(items) {
|
||||||
items = [Ox.extend({index: '0'}, data)].concat(items);
|
|
||||||
Ox.print('LIST ITEMS::::', items);
|
Ox.print('LIST ITEMS::::', items);
|
||||||
var $list = Ox.TableList({
|
var $list = Ox.TableList({
|
||||||
columns: [{
|
columns: [
|
||||||
format: function(value, data) {
|
{
|
||||||
return (data.title || '') + (
|
format: function(value) {
|
||||||
data.author
|
return Ox.getObjectById(ids, value).title;
|
||||||
? ' <span class="OxLight">'
|
},
|
||||||
+ data.author.join(', ') + '</span>'
|
id: 'mainid',
|
||||||
: ''
|
visible: true,
|
||||||
);
|
width: 64
|
||||||
},
|
},
|
||||||
id: 'index',
|
{
|
||||||
visible: true,
|
format: function(value, data) {
|
||||||
width: 192 - Ox.UI.SCROLLBAR_SIZE
|
return data[data.mainid];
|
||||||
}],
|
},
|
||||||
|
id: 'index',
|
||||||
|
visible: true,
|
||||||
|
width: 128 - Ox.UI.SCROLLBAR_SIZE
|
||||||
|
}
|
||||||
|
],
|
||||||
items: items,
|
items: items,
|
||||||
keys: ['author', 'title', 'olid'],
|
keys: ['mainid', 'isbn10', 'isbn13'],
|
||||||
min: 1,
|
min: 1,
|
||||||
max: 1,
|
max: 1,
|
||||||
scrollbarVisible: true,
|
scrollbarVisible: true,
|
||||||
selected: ['0'],
|
sort: [{key: 'mainid', operator: '+'}],
|
||||||
sort: [{key: 'index', operator: '+'}],
|
|
||||||
unique: 'index'
|
unique: 'index'
|
||||||
})
|
})
|
||||||
.bindEvent({
|
.bindEvent({
|
||||||
select: function(data) {
|
select: function(data) {
|
||||||
var index = data.ids[0], olid;
|
var index = data.ids[0], mainid;
|
||||||
if (index == '0') {
|
mainid = $list.value(index, 'mainid');
|
||||||
$results.replaceElement(1, oml.ui.infoView(data));
|
Ox.print('MAINID', mainid)
|
||||||
} else {
|
titleValue = Ox.extend({}, mainid, $list.value(index, mainid));
|
||||||
olid = $list.value(index, 'olid');
|
$results.replaceElement(1, Ox.LoadingScreen().start());
|
||||||
editedData = {olid: olid};
|
oml.api.getMetadata(titleValue, function(result) {
|
||||||
$results.replaceElement(1, Ox.LoadingScreen().start());
|
if (index == $list.options('selected')[0]) {
|
||||||
oml.api.getMetadata({olid: olid}, function(result) {
|
$results.replaceElement(1, oml.ui.infoView(result.data));
|
||||||
if (index == $list.options('selected')[0]) {
|
that.options('buttons')[1].options({disabled: false});
|
||||||
$results.replaceElement(1, oml.ui.infoView(result.data));
|
}
|
||||||
that.options('buttons')[1].options({disabled: false});
|
});
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
$results = Ox.SplitPanel({
|
$results = Ox.SplitPanel({
|
||||||
elements: [
|
elements: [
|
||||||
{element: $list, size: 192},
|
{element: $list, size: 192},
|
||||||
{element: oml.ui.infoView(items[0])}
|
{element: Ox.Element()}
|
||||||
],
|
],
|
||||||
orientation: 'horizontal'
|
orientation: 'horizontal'
|
||||||
});
|
});
|
||||||
|
@ -480,7 +484,7 @@ oml.ui.identifyDialog = function(data) {
|
||||||
$idButtons.clear.options({disabled: empty});
|
$idButtons.clear.options({disabled: empty});
|
||||||
$idButtons.reset.options({disabled: original});
|
$idButtons.reset.options({disabled: original});
|
||||||
$idButtons.find.options({disabled: empty});
|
$idButtons.find.options({disabled: empty});
|
||||||
that.options('buttons')[1].options({disabled: original});
|
that[original ? 'disableButton' : 'enableButton']('update');
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateTitleButtons() {
|
function updateTitleButtons() {
|
||||||
|
@ -493,7 +497,7 @@ oml.ui.identifyDialog = function(data) {
|
||||||
$titleButtons.clear.options({disabled: empty});
|
$titleButtons.clear.options({disabled: empty});
|
||||||
$titleButtons.reset.options({disabled: original});
|
$titleButtons.reset.options({disabled: original});
|
||||||
$titleButtons.find.options({disabled: empty});
|
$titleButtons.find.options({disabled: empty});
|
||||||
that.options('buttons')[1].options({disabled: original});
|
that[original ? 'disableButton' : 'enableButton']('update');
|
||||||
}
|
}
|
||||||
|
|
||||||
return that;
|
return that;
|
||||||
|
|
|
@ -66,6 +66,12 @@ oml.ui.infoView = function(identifyData) {
|
||||||
return '<span class="OxLight">' + str + '</span>';
|
return '<span class="OxLight">' + str + '</span>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatKey(key) {
|
||||||
|
var item = Ox.getObjectById(oml.config.itemKeys, key);
|
||||||
|
return '<span style="font-weight: bold">'
|
||||||
|
+ Ox._(Ox.toTitleCase(key)) + ': </span> ';
|
||||||
|
}
|
||||||
|
|
||||||
function formatValue(value, key) {
|
function formatValue(value, key) {
|
||||||
return (Ox.isArray(value) ? value : [value]).map(function(value) {
|
return (Ox.isArray(value) ? value : [value]).map(function(value) {
|
||||||
return key ?
|
return key ?
|
||||||
|
@ -234,6 +240,7 @@ oml.ui.infoView = function(identifyData) {
|
||||||
$elements = $elements
|
$elements = $elements
|
||||||
? Ox.makeArray($elements)
|
? Ox.makeArray($elements)
|
||||||
: [$cover, $info, $data];
|
: [$cover, $info, $data];
|
||||||
|
Ox.print('DEBUG, $ELEMENTS', $elements);
|
||||||
|
|
||||||
(data ? Ox.noop : oml.api.get)({
|
(data ? Ox.noop : oml.api.get)({
|
||||||
id: id,
|
id: id,
|
||||||
|
@ -308,8 +315,9 @@ oml.ui.infoView = function(identifyData) {
|
||||||
Ox.EditableContent({
|
Ox.EditableContent({
|
||||||
clickLink: oml.clickLink,
|
clickLink: oml.clickLink,
|
||||||
editable: isEditable,
|
editable: isEditable,
|
||||||
|
placeholder: formatLight(Ox._('Unknown Title')),
|
||||||
tooltip: isEditable ? oml.getEditTooltip() : '',
|
tooltip: isEditable ? oml.getEditTooltip() : '',
|
||||||
value: data.title
|
value: data.title || ''
|
||||||
})
|
})
|
||||||
.css({
|
.css({
|
||||||
fontSize: '13px',
|
fontSize: '13px',
|
||||||
|
@ -330,7 +338,9 @@ oml.ui.infoView = function(identifyData) {
|
||||||
clickLink: oml.clickLink,
|
clickLink: oml.clickLink,
|
||||||
editable: isEditable,
|
editable: isEditable,
|
||||||
format: function(value) {
|
format: function(value) {
|
||||||
return formatValue(value.split(', '), 'author');
|
return !identifyData
|
||||||
|
? formatValue(value.split(', '), 'author')
|
||||||
|
: value;
|
||||||
},
|
},
|
||||||
placeholder: formatLight(Ox._('Unknown Author')),
|
placeholder: formatLight(Ox._('Unknown Author')),
|
||||||
tooltip: isEditable ? oml.getEditTooltip() : '',
|
tooltip: isEditable ? oml.getEditTooltip() : '',
|
||||||
|
@ -340,23 +350,65 @@ oml.ui.infoView = function(identifyData) {
|
||||||
fontSize: '13px',
|
fontSize: '13px',
|
||||||
fontWeight: 'bold'
|
fontWeight: 'bold'
|
||||||
})
|
})
|
||||||
|
.bindEvent({
|
||||||
|
// ...
|
||||||
|
})
|
||||||
)
|
)
|
||||||
.appendTo($info);
|
.appendTo($info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isEditable) {
|
||||||
|
$('<div>')
|
||||||
|
.css({
|
||||||
|
marginTop: '8px'
|
||||||
|
})
|
||||||
|
.text(
|
||||||
|
(data.place || '')
|
||||||
|
+ (data.place && (data.publisher || data.date) ? ' : ' : '')
|
||||||
|
+ (data.publisher || '')
|
||||||
|
+ (data.publisher && data.date ? ', ' : '')
|
||||||
|
+ (data.date || '')
|
||||||
|
)
|
||||||
|
.appendTo($info);
|
||||||
|
} else {
|
||||||
|
var $div = $('<div>')
|
||||||
|
.addClass('OxSelectable')
|
||||||
|
.css({marginTop: '8px'})
|
||||||
|
.appendTo($info);
|
||||||
|
['edition', 'publisher', 'date'].forEach(function(key, index) {
|
||||||
|
index && $('<div>').css({float: 'left'}).html('; ').appendTo($div);
|
||||||
|
$('<div>')
|
||||||
|
.css({float: 'left'})
|
||||||
|
.html(formatKey(key))
|
||||||
|
.appendTo($div);
|
||||||
|
Ox.EditableContent({
|
||||||
|
clickLink: oml.clickLink,
|
||||||
|
format: function(value) {
|
||||||
|
return formatValue(value.split(', '), key)
|
||||||
|
},
|
||||||
|
placeholder: formatLight('unknown'),
|
||||||
|
tooltip: oml.getEditTooltip(),
|
||||||
|
value: data[key] || ''
|
||||||
|
})
|
||||||
|
.css({float: 'left'})
|
||||||
|
.bindEvent({
|
||||||
|
submit: function(event) {
|
||||||
|
editMetadata(key, event.value);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.appendTo($div);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
$('<div>')
|
if (data.classification) {
|
||||||
.css({
|
$('<div>')
|
||||||
marginTop: '8px'
|
.css({
|
||||||
})
|
marginTop: '8px',
|
||||||
.text(
|
textAlign: 'justify'
|
||||||
(data.place || '')
|
})
|
||||||
+ (data.place && (data.publisher || data.date) ? ' : ' : '')
|
.html(Ox.encodeHTMLEntities(data.classification))
|
||||||
+ (data.publisher || '')
|
.appendTo($info);
|
||||||
+ (data.publisher && data.date ? ', ' : '')
|
}
|
||||||
+ (data.date || '')
|
|
||||||
)
|
|
||||||
.appendTo($info);
|
|
||||||
|
|
||||||
if (data.description) {
|
if (data.description) {
|
||||||
$('<div>')
|
$('<div>')
|
||||||
|
@ -445,11 +497,14 @@ oml.ui.infoView = function(identifyData) {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// FIXME: identify dialog should call this too
|
||||||
function editMetadata(key, value) {
|
function editMetadata(key, value) {
|
||||||
var edit;
|
var edit;
|
||||||
if (value != data[key]) {
|
if (value != data[key]) {
|
||||||
edit = Ox.extend({id: ui.item}, key, value);
|
edit = Ox.extend({id: ui.item}, key, value);
|
||||||
oml.api.edit(edit, function(result) {
|
oml.api.edit(edit, function(result) {
|
||||||
|
Ox.Request.clearCache('find');
|
||||||
|
oml.$ui.browser.reloadList();
|
||||||
that.update(result.data, $data);
|
that.update(result.data, $data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -469,7 +524,7 @@ oml.ui.infoView = function(identifyData) {
|
||||||
transfer: function(data) {
|
transfer: function(data) {
|
||||||
if (data.id == ui.item && data.progress == 1) {
|
if (data.id == ui.item && data.progress == 1) {
|
||||||
Ox.Request.clearCache(); // FIXME: too much
|
Ox.Request.clearCache(); // FIXME: too much
|
||||||
that.update(ui.item, $data);
|
that.update(ui.item, [$info, $data]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -254,8 +254,20 @@ oml.ui.usersDialog = function() {
|
||||||
width: 480
|
width: 480
|
||||||
})
|
})
|
||||||
.bindEvent({
|
.bindEvent({
|
||||||
change: function() {
|
change: function(data) {
|
||||||
// ...
|
var value = oml.validateName(
|
||||||
|
data.value,
|
||||||
|
users.map(function(user) {
|
||||||
|
return user.nickname;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
this.value(value);
|
||||||
|
oml.api.editUser({
|
||||||
|
id: user.id,
|
||||||
|
nickname: value
|
||||||
|
}, function() {
|
||||||
|
// ...
|
||||||
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.appendTo($form);
|
.appendTo($form);
|
||||||
|
@ -480,6 +492,10 @@ oml.ui.usersDialog = function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateUsers() {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
|
||||||
that.update = function() {
|
that.update = function() {
|
||||||
|
|
||||||
that.options({
|
that.options({
|
||||||
|
@ -503,7 +519,6 @@ oml.ui.usersDialog = function() {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
Ox.print('FOLDERS::', folders)
|
|
||||||
folders.forEach(function(folder, index) {
|
folders.forEach(function(folder, index) {
|
||||||
$lists.push(
|
$lists.push(
|
||||||
(
|
(
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 43 KiB |
Loading…
Reference in a new issue