2020-11-27 15:28:54 -05:00
|
|
|
/*
|
|
|
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import {Link} from "./Link.js";
|
2020-11-30 05:24:08 -05:00
|
|
|
import {ViewModel} from "./utils/ViewModel.js";
|
2020-12-02 09:36:54 -05:00
|
|
|
import {OpenLinkViewModel} from "./open/OpenLinkViewModel.js";
|
|
|
|
import {createClients} from "./open/clients/index.js";
|
|
|
|
import {CreateLinkViewModel} from "./create/CreateLinkViewModel.js";
|
2020-12-04 04:33:31 -05:00
|
|
|
import {LoadServerPolicyViewModel} from "./policy/LoadServerPolicyViewModel.js";
|
2020-12-02 09:36:54 -05:00
|
|
|
import {Platform} from "./Platform.js";
|
2020-11-27 15:28:54 -05:00
|
|
|
|
|
|
|
export class RootViewModel extends ViewModel {
|
2020-11-30 06:49:31 -05:00
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
2020-11-30 05:24:08 -05:00
|
|
|
this.link = null;
|
2020-12-02 09:36:54 -05:00
|
|
|
this.openLinkViewModel = null;
|
|
|
|
this.createLinkViewModel = null;
|
2020-12-04 04:33:31 -05:00
|
|
|
this.loadServerPolicyViewModel = null;
|
2020-12-04 07:59:52 -05:00
|
|
|
this.preferences.on("canClear", () => {
|
|
|
|
this.emitChange();
|
|
|
|
});
|
2020-11-27 15:28:54 -05:00
|
|
|
}
|
|
|
|
|
2020-11-30 05:24:08 -05:00
|
|
|
_updateChildVMs(oldLink) {
|
2020-11-27 15:28:54 -05:00
|
|
|
if (this.link) {
|
2020-12-02 09:36:54 -05:00
|
|
|
this.createLinkViewModel = null;
|
2020-11-30 05:24:08 -05:00
|
|
|
if (!oldLink || !oldLink.equals(this.link)) {
|
2020-12-02 09:36:54 -05:00
|
|
|
this.openLinkViewModel = new OpenLinkViewModel(this.childOptions({
|
2020-11-30 05:24:08 -05:00
|
|
|
link: this.link,
|
2020-12-04 07:59:52 -05:00
|
|
|
clients: createClients(),
|
2020-11-30 05:24:08 -05:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
} else {
|
2020-12-02 09:39:33 -05:00
|
|
|
this.openLinkViewModel = null;
|
|
|
|
this.createLinkViewModel = new CreateLinkViewModel(this.childOptions());
|
2020-11-27 15:28:54 -05:00
|
|
|
}
|
2020-11-30 05:24:08 -05:00
|
|
|
this.emitChange();
|
|
|
|
}
|
|
|
|
|
|
|
|
updateHash(hash) {
|
2020-12-04 04:33:31 -05:00
|
|
|
if (hash.startsWith("#/policy/")) {
|
|
|
|
const server = hash.substr(9);
|
|
|
|
this.loadServerPolicyViewModel = new LoadServerPolicyViewModel(this.childOptions({server}));
|
|
|
|
this.loadServerPolicyViewModel.load();
|
|
|
|
} else {
|
|
|
|
const oldLink = this.link;
|
|
|
|
this.link = Link.parse(hash);
|
|
|
|
this._updateChildVMs(oldLink);
|
|
|
|
}
|
2020-11-27 15:28:54 -05:00
|
|
|
}
|
2020-11-30 04:57:39 -05:00
|
|
|
|
2020-12-01 06:06:37 -05:00
|
|
|
clearPreferences() {
|
|
|
|
this.preferences.clear();
|
|
|
|
this._updateChildVMs();
|
|
|
|
}
|
|
|
|
|
|
|
|
get hasPreferences() {
|
|
|
|
return this.preferences.canClear;
|
|
|
|
}
|
|
|
|
}
|