|
|
|
@ -59,7 +59,8 @@ open class CustomField : RealmObject(), NameManageable, StaticRowRepresentableDa |
|
|
|
var type: Int = Type.LIST.uniqueIdentifier |
|
|
|
var type: Int = Type.LIST.uniqueIdentifier |
|
|
|
set(value) { |
|
|
|
set(value) { |
|
|
|
if (field == Type.LIST.uniqueIdentifier && value != Type.LIST.uniqueIdentifier) { |
|
|
|
if (field == Type.LIST.uniqueIdentifier && value != Type.LIST.uniqueIdentifier) { |
|
|
|
this.removeListEntries() |
|
|
|
this.entriesToDelete.addAll(this.entries) |
|
|
|
|
|
|
|
this.entries.clear() |
|
|
|
} |
|
|
|
} |
|
|
|
field = value |
|
|
|
field = value |
|
|
|
|
|
|
|
|
|
|
|
@ -146,7 +147,7 @@ open class CustomField : RealmObject(), NameManageable, StaticRowRepresentableDa |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun isValidForDelete(realm: Realm): Boolean { |
|
|
|
override fun isValidForDelete(realm: Realm): Boolean { |
|
|
|
val sessions = realm.where<Session>().contains("customFieldEntries.customField.id", id).findAll() |
|
|
|
val sessions = realm.where<Session>().contains("customFieldEntries.customFields.id", id).findAll() |
|
|
|
return sessions.isEmpty() |
|
|
|
return sessions.isEmpty() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -163,7 +164,7 @@ open class CustomField : RealmObject(), NameManageable, StaticRowRepresentableDa |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun deleteDependencies() { |
|
|
|
override fun deleteDependencies(realm: Realm) { |
|
|
|
if (isValid) { |
|
|
|
if (isValid) { |
|
|
|
val entries = realm.where<CustomFieldEntry>().equalTo("customField.id", id).findAll() |
|
|
|
val entries = realm.where<CustomFieldEntry>().equalTo("customField.id", id).findAll() |
|
|
|
entries.deleteAllFromRealm() |
|
|
|
entries.deleteAllFromRealm() |
|
|
|
@ -257,26 +258,24 @@ open class CustomField : RealmObject(), NameManageable, StaticRowRepresentableDa |
|
|
|
* Delete an entry |
|
|
|
* Delete an entry |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
fun deleteEntry(entry: CustomFieldEntry) { |
|
|
|
fun deleteEntry(entry: CustomFieldEntry) { |
|
|
|
entries.remove(entry) |
|
|
|
|
|
|
|
entriesToDelete.add(entry) |
|
|
|
entriesToDelete.add(entry) |
|
|
|
|
|
|
|
entries.remove(entry) |
|
|
|
|
|
|
|
|
|
|
|
sortEntries() |
|
|
|
sortEntries() |
|
|
|
updateRowRepresentation() |
|
|
|
updateRowRepresentation() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun removeListEntries() { |
|
|
|
fun cleanupEntries() { // called when saving the custom field |
|
|
|
|
|
|
|
|
|
|
|
this.entriesToDelete.addAll(entries) |
|
|
|
val realm = Realm.getDefaultInstance() |
|
|
|
this.entries.clear() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (realm != null) { |
|
|
|
realm.executeTransaction { |
|
|
|
realm.executeTransaction { |
|
|
|
this.entriesToDelete.forEach { // entries are out of realm |
|
|
|
this.entriesToDelete.forEach { |
|
|
|
realm.where<CustomFieldEntry>().equalTo("id", it.id).findFirst()?.deleteFromRealm() |
|
|
|
if (it.isManaged) { |
|
|
|
|
|
|
|
it.deleteFromRealm() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
realm.close() |
|
|
|
|
|
|
|
this.entriesToDelete.clear() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
|