Fix saving of new items
Added Scholar.Folders.reloadAll(), used after saving a new item or moving one to refresh isEmpty Fixed bug where items without creators wouldn't show
This commit is contained in:
parent
d398339997
commit
7800f7a39b
1 changed files with 32 additions and 18 deletions
|
@ -76,7 +76,8 @@ Scholar.Item.prototype.loadFromID = function(id){
|
||||||
+ 'LEFT JOIN treeStructure TS ON (I.itemID=TS.id AND isFolder=0) '
|
+ 'LEFT JOIN treeStructure TS ON (I.itemID=TS.id AND isFolder=0) '
|
||||||
+ 'LEFT JOIN itemCreators IC ON (I.itemID=IC.itemID) '
|
+ 'LEFT JOIN itemCreators IC ON (I.itemID=IC.itemID) '
|
||||||
+ 'LEFT JOIN creators C ON (IC.creatorID=C.creatorID) '
|
+ 'LEFT JOIN creators C ON (IC.creatorID=C.creatorID) '
|
||||||
+ 'WHERE itemID=' + id + ' AND IC.orderIndex=0';
|
+ 'WHERE itemID=' + id
|
||||||
|
+ ' AND (IC.orderIndex=0 OR IC.orderIndex IS NULL)';
|
||||||
var row = Scholar.DB.rowQuery(sql);
|
var row = Scholar.DB.rowQuery(sql);
|
||||||
this.loadFromRow(row);
|
this.loadFromRow(row);
|
||||||
}
|
}
|
||||||
|
@ -323,9 +324,8 @@ Scholar.Item.prototype.setPosition = function(newFolder, newPos, isNew){
|
||||||
var oldFolder = this.getField('parentFolderID');
|
var oldFolder = this.getField('parentFolderID');
|
||||||
var oldPos = this.getField('orderIndex');
|
var oldPos = this.getField('orderIndex');
|
||||||
|
|
||||||
|
|
||||||
if (this.getID()){
|
if (this.getID()){
|
||||||
if (newFolder==oldFolder && newPos==oldPos){
|
if (!isNew && newFolder==oldFolder && newPos==oldPos){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -363,13 +363,13 @@ Scholar.Item.prototype.setPosition = function(newFolder, newPos, isNew){
|
||||||
|
|
||||||
// If a new item, insert
|
// If a new item, insert
|
||||||
if (isNew){
|
if (isNew){
|
||||||
sql = 'INSERT INTO treeStructure SET id=' + this.getID() + ', ' +
|
var sql = 'INSERT INTO treeStructure '
|
||||||
'isFolder=0, orderIndex=' + newPos + ', ' +
|
+ '(id, isFolder, orderIndex, parentFolderID) VALUES ('
|
||||||
'parentFolderID=' + newFolder;
|
+ this.getID() + ', 0, ' + newPos + ', ' + newFolder + ')';
|
||||||
}
|
}
|
||||||
// Otherwise update
|
// Otherwise update
|
||||||
else {
|
else {
|
||||||
sql = 'UPDATE treeStructure SET parentFolderID=' + newFolder +
|
var sql = 'UPDATE treeStructure SET parentFolderID=' + newFolder +
|
||||||
', orderIndex=' + newPos + ' WHERE id=' + this.getID() +
|
', orderIndex=' + newPos + ' WHERE id=' + this.getID() +
|
||||||
" AND isFolder=0;\n";
|
" AND isFolder=0;\n";
|
||||||
}
|
}
|
||||||
|
@ -385,6 +385,7 @@ Scholar.Item.prototype.setPosition = function(newFolder, newPos, isNew){
|
||||||
|
|
||||||
if (this.getID() && !isNew){
|
if (this.getID() && !isNew){
|
||||||
Scholar.Items.reloadAll();
|
Scholar.Items.reloadAll();
|
||||||
|
Scholar.Folders.reloadAll(); // needed to recheck isEmpty
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -633,11 +634,18 @@ Scholar.Item.prototype.save = function(){
|
||||||
}
|
}
|
||||||
sql = sql.substring(0,sql.length-1) + ");\n";
|
sql = sql.substring(0,sql.length-1) + ");\n";
|
||||||
|
|
||||||
|
// Save basic data to items table and get new ID
|
||||||
var itemID = Scholar.DB.query(sql,sqlValues);
|
var itemID = Scholar.DB.query(sql,sqlValues);
|
||||||
|
this._data['itemID'] = itemID;
|
||||||
|
|
||||||
|
// Set itemData
|
||||||
if (this._changedItemData.length){
|
if (this._changedItemData.length){
|
||||||
sql = '';
|
sql = '';
|
||||||
for (fieldID in this._changedItemData.items){
|
for (fieldID in this._changedItemData.items){
|
||||||
|
if (!this.getField(fieldID)){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
sql += 'INSERT INTO itemData VALUES (' +
|
sql += 'INSERT INTO itemData VALUES (' +
|
||||||
itemID + ',' + fieldID + ',';
|
itemID + ',' + fieldID + ',';
|
||||||
if (Scholar.ItemFields.isInteger(fieldID)){
|
if (Scholar.ItemFields.isInteger(fieldID)){
|
||||||
|
@ -648,12 +656,11 @@ Scholar.Item.prototype.save = function(){
|
||||||
}
|
}
|
||||||
sql += ");\n";
|
sql += ");\n";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (sql){
|
||||||
Scholar.DB.query(sql);
|
Scholar.DB.query(sql);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Set the position of the new item
|
// Set the position of the new item
|
||||||
var newFolder = this.getField('parentFolderID')
|
var newFolder = this.getField('parentFolderID')
|
||||||
|
@ -664,10 +671,11 @@ Scholar.Item.prototype.save = function(){
|
||||||
|
|
||||||
this.setPosition(newFolder, newPos, true);
|
this.setPosition(newFolder, newPos, true);
|
||||||
|
|
||||||
// TODO: reload Folder or set the empty flag to false manually
|
|
||||||
// in case this was the first item in a folder
|
|
||||||
|
|
||||||
Scholar.DB.commitTransaction();
|
Scholar.DB.commitTransaction();
|
||||||
|
|
||||||
|
// Reload folders to update isEmpty,
|
||||||
|
// in case this was the first item in a folder
|
||||||
|
Scholar.Folders.reloadAll();
|
||||||
}
|
}
|
||||||
catch (e){
|
catch (e){
|
||||||
Scholar.DB.rollbackTransaction();
|
Scholar.DB.rollbackTransaction();
|
||||||
|
@ -951,7 +959,7 @@ Scholar.Items = new function(){
|
||||||
+ 'LEFT JOIN treeStructure TS ON (I.itemID=TS.id AND isFolder=0) '
|
+ 'LEFT JOIN treeStructure TS ON (I.itemID=TS.id AND isFolder=0) '
|
||||||
+ 'LEFT JOIN itemCreators IC ON (I.itemID=IC.itemID) '
|
+ 'LEFT JOIN itemCreators IC ON (I.itemID=IC.itemID) '
|
||||||
+ 'LEFT JOIN creators C ON (IC.creatorID=C.creatorID) '
|
+ 'LEFT JOIN creators C ON (IC.creatorID=C.creatorID) '
|
||||||
+ 'WHERE IC.orderIndex=0';
|
+ 'WHERE IC.orderIndex=0 OR IC.orderIndex IS NULL';
|
||||||
|
|
||||||
if (arguments[0]!='all'){
|
if (arguments[0]!='all'){
|
||||||
sql += ' AND I.itemID IN (' + Scholar.join(arguments,',') + ')';
|
sql += ' AND I.itemID IN (' + Scholar.join(arguments,',') + ')';
|
||||||
|
@ -1041,6 +1049,7 @@ Scholar.Folders = new function(){
|
||||||
var _foldersLoaded = false;
|
var _foldersLoaded = false;
|
||||||
|
|
||||||
this.get = get;
|
this.get = get;
|
||||||
|
this.reloadAll = reloadAll;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns a Scholar.Folder object for a folderID
|
* Returns a Scholar.Folder object for a folderID
|
||||||
|
@ -1053,6 +1062,11 @@ Scholar.Folders = new function(){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function reloadAll(){
|
||||||
|
_folders = new Array();
|
||||||
|
_load();
|
||||||
|
}
|
||||||
|
|
||||||
function _load(){
|
function _load(){
|
||||||
var sql = "SELECT folderID, folderName, parentFolderID, "
|
var sql = "SELECT folderID, folderName, parentFolderID, "
|
||||||
+ "(SELECT COUNT(*) FROM treeStructure WHERE "
|
+ "(SELECT COUNT(*) FROM treeStructure WHERE "
|
||||||
|
|
Loading…
Reference in a new issue