| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- // MLQRequire: { "Plugin": "Minecraft-Payment", "Type": "Service", "Name": "MinecraftPayService" }
- class MinecraftUsers {
- constructor() {
- this.user = {};
- this.subscriptionsStates = new Map();
- }
- onview(vnode) {
- if (typeof (MinecraftUser) !== 'function')
- LoadQueue.Start(() => { });
- else
- this.loadUser();
- }
- loadUser() {
- var id = m.route.param('id');
- if (id.match(/^[0-9]+$/))
- id = +id;
- else
- return;
- if (this.user.ID !== id) {
- this.user = $.extend(true, new MinecraftUser(), MinecraftPayService.Users.find(o => o.ID === id)) || this.user;
- if (this.user.ID) {
- MinecraftPayAPI.GetAllSubscriptionStates({ params: { id } }).then(map => {
- this.subscriptionsStates = map || this.subscriptionsStates;
- });
- }
- m.redraw();
- }
- }
- UnlockServer(serverId) {
- if (!this.subscriptionsStates.get(serverId)) {
- Modal.YesNo('Delete minecraft user', __('Do you really want to unlock this server for this minecraft user?'), (c, e) => this.unlockServer(this.user.ID, serverId, c)).Show();
- }
- }
- unlockServer(userId, serverId, confirmed) {
- if (confirmed) {
- MinecraftPayAPI.SubscribeServer({ params: { id: userId, serverId } }).then(r => {
- this.subscriptionsStates.set(serverId, r.Obj);
- Toasts.Messaged(r.Message, Toast.Load({ Type: r.Success ? 'success' : 'danger' }));
- });
- }
- return undefined;
- }
- }
|