[lib.popup-controller][scss.global] design for 'loading' animation in submit <button> before api response + [lib.*-controller] when called from popup will call 'gs.get.popup().hide' to remove the loading animation and close the popup

This commit is contained in:
xdrm-brackets 2018-03-29 12:56:17 +02:00
parent 3e3a9197b2
commit 32f4e9a7b3
7 changed files with 57 additions and 34 deletions

View File

@ -0,0 +1,11 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" width="32" height="32" fill="white">
<circle transform="translate(8 0)" cx="0" cy="16" r="0">
<animate attributeName="r" values="0; 4; 0; 0" dur="1.2s" repeatCount="indefinite" begin="0" keytimes="0;0.2;0.7;1" keySplines="0.2 0.2 0.4 0.8;0.2 0.6 0.4 0.8;0.2 0.6 0.4 0.8" calcMode="spline"/>
</circle>
<circle transform="translate(16 0)" cx="0" cy="16" r="0">
<animate attributeName="r" values="0; 4; 0; 0" dur="1.2s" repeatCount="indefinite" begin="0.3" keytimes="0;0.2;0.7;1" keySplines="0.2 0.2 0.4 0.8;0.2 0.6 0.4 0.8;0.2 0.6 0.4 0.8" calcMode="spline"/>
</circle>
<circle transform="translate(24 0)" cx="0" cy="16" r="0">
<animate attributeName="r" values="0; 4; 0; 0" dur="1.2s" repeatCount="indefinite" begin="0.6" keytimes="0;0.2;0.7;1" keySplines="0.2 0.2 0.4 0.8;0.2 0.6 0.4 0.8;0.2 0.6 0.4 0.8" calcMode="spline"/>
</circle>
</svg>

After

Width:  |  Height:  |  Size: 928 B

View File

@ -211,16 +211,16 @@ export default class ChannelController{
/* (3) Try to create room in API */ /* (3) Try to create room in API */
api.call('POST /channel', { link: link, name: name }, function(rs){ api.call('POST /channel', { link: link, name: name }, function(rs){
/* (1) Manage error */ /* (1) Hide popup */
gs.get.popup.hide();
/* (2) Manage error */
if( rs.error !== 0 || rs.cid == null ) if( rs.error !== 0 || rs.cid == null )
return false; return false;
/* (2) Reload channel list */ /* (3) Reload channel list */
this.fetch(); this.fetch();
/* (3) Hide popup */
gs.get.popup.hide();
}.bind(this), auth.token); }.bind(this), auth.token);
return true; return true;

View File

@ -87,6 +87,8 @@ export default class ContentController{
/* (3) Call api UPDATE */ /* (3) Call api UPDATE */
api.call(`PUT /user/${this.uid}`, { username: username }, function(rs){ api.call(`PUT /user/${this.uid}`, { username: username }, function(rs){
gs.get.popup.hide();
// manage error // manage error
if( rs.error !== 0 ) if( rs.error !== 0 )
return; return;
@ -125,7 +127,7 @@ export default class ContentController{
return false; return false;
/* (3) Call api UPDATE */ /* (3) Call api UPDATE */
api.call(`PUT /user/${this.uid}`, { password: password }, () => {}, auth.token); api.call(`PUT /user/${this.uid}`, { password: password }, () => gs.get.popup.hide(), auth.token);
/* (4) Error */ /* (4) Error */
return true; return true;

View File

@ -16,6 +16,10 @@ export default class PopupController{
/* (3) Active popup */ /* (3) Active popup */
this.active = null; this.active = null;
/* (4) Loading state */
this.loading = false;
/* (2) Popups /* (2) Popups
@ -35,8 +39,8 @@ export default class PopupController{
if( !this.name.is_valid() ) if( !this.name.is_valid() )
return; return;
if( gs.get.room.create(this.type.mutable, this.name.mutable) ) // loading
return this.parent.hide(); this.parent.loading = gs.get.room.create(this.type.mutable, this.name.mutable);
} }
@ -59,8 +63,8 @@ export default class PopupController{
if( !this.link.is_valid() ) if( !this.link.is_valid() )
return false; return false;
if( gs.get.channel.create(this.name.mutable, this.link.mutable) ) // loading
return this.parent.hide(); this.parent.loading = gs.get.channel.create(this.name.mutable, this.link.mutable);
} }
}); });
@ -75,8 +79,9 @@ export default class PopupController{
if( !this.username.is_valid() ) if( !this.username.is_valid() )
return false; return false;
if( gs.get.content.change_username(this.username.mutable) ) // loading
this.parent.hide(); this.parent.loading = gs.get.content.change_username(this.username.mutable);
} }
}); });
@ -91,8 +96,8 @@ export default class PopupController{
if( !this.username.is_valid() ) if( !this.username.is_valid() )
return false; return false;
if( gs.get.channel.invite(this.username.mutable) ) // loading
return this.parent.hide(); this.parent.loading = gs.get.channel.invite(this.username.mutable);
} }
}); });
@ -100,7 +105,7 @@ export default class PopupController{
/* (5) Remove channel */ /* (5) Remove channel */
this.register('channel.remove', { this.register('channel.remove', {
reset(){ }, reset(){ },
submit(){ gs.get.channel.remove() && this.parent.hide(); } submit(){ this.parent.loading = gs.get.channel.remove(); }
}); });
/* (6) Remove channel */ /* (6) Remove channel */
@ -112,13 +117,13 @@ export default class PopupController{
messages: [] messages: []
}, },
reset(){ this.data = { id: '', type: '', name: '', messages: [] }; }, reset(){ this.data = { id: '', type: '', name: '', messages: [] }; },
submit(){ gs.get.room.remove(this.data.type, this.data.id) && this.parent.hide(); } submit(){ this.parent.loading = gs.get.room.remove(this.data.type, this.data.id); }
}); });
/* (7) Leave channel */ /* (7) Leave channel */
this.register('channel.leave', { this.register('channel.leave', {
reset(){ }, reset(){ },
submit(){ gs.get.channel.remove() && this.parent.hide(); } submit(){ this.parent.loading = gs.get.channel.remove(); }
}); });
/* (8) Change password */ /* (8) Change password */
@ -139,8 +144,7 @@ export default class PopupController{
if( !this.password.is_valid || !this.confirm.is_valid() ) if( !this.password.is_valid || !this.confirm.is_valid() )
return false; return false;
if( gs.get.content.change_password(this.password.mutable) ) this.loading = gs.get.content.change_password(this.password.mutable);
return this.parent.hide();
} }
}); });
@ -243,6 +247,7 @@ export default class PopupController{
this.filter = true; this.filter = true;
/* (6) Reset popup */ /* (6) Reset popup */
this.loading = false;
this.list[name].reset(); this.list[name].reset();
/* (7) Show popup */ /* (7) Show popup */
@ -272,6 +277,7 @@ export default class PopupController{
this.list[this.active].active = false; this.list[this.active].active = false;
/* (5) Reset popup */ /* (5) Reset popup */
this.loading = false;
this.list[this.active].reset(); this.list[this.active].reset();
/* (6) Reset @active */ /* (6) Reset @active */

View File

@ -229,6 +229,8 @@ export default class RoomController{
/* (3) Try to create room in API */ /* (3) Try to create room in API */
api.call(`POST /channel/room/${gs.get.content.cid}`, { type: type, name: name }, function(rs){ api.call(`POST /channel/room/${gs.get.content.cid}`, { type: type, name: name }, function(rs){
gs.get.popup.hide();
/* (1) Manage error */ /* (1) Manage error */
if( rs.error !== 0 || rs.rid == null ) if( rs.error !== 0 || rs.rid == null )
return false; return false;
@ -236,9 +238,6 @@ export default class RoomController{
/* (2) Reload room list */ /* (2) Reload room list */
this.fetch(); this.fetch();
/* (3) Hide popup */
gs.get.popup.hide();
}.bind(this), auth.token); }.bind(this), auth.token);
return true; return true;
@ -267,6 +266,8 @@ export default class RoomController{
/* (3) Try to create room in API */ /* (3) Try to create room in API */
api.call(`DELETE /channel/room/${gs.get.content.cid}/${rid}`, {}, function(rs){ api.call(`DELETE /channel/room/${gs.get.content.cid}/${rid}`, {}, function(rs){
gs.get.popup.hide();
/* (1) Manage error */ /* (1) Manage error */
if( rs.error !== 0 ) if( rs.error !== 0 )
return false; return false;
@ -274,9 +275,6 @@ export default class RoomController{
/* (2) Reload room list */ /* (2) Reload room list */
this.fetch(); this.fetch();
/* (3) Hide popup */
gs.get.popup.hide();
}.bind(this), auth.token); }.bind(this), auth.token);
return true; return true;

View File

@ -153,7 +153,8 @@
border: 0; border: 0;
border-radius: 3px / 3px; border-radius: 3px / 3px;
background-color: $main; background: $main center center no-repeat;
background-size: contain;
color: #fff; color: #fff;
font-size: .8em; font-size: .8em;
@ -172,6 +173,11 @@
&:hover{ background-color: darken($main, 5%);} &:hover{ background-color: darken($main, 5%);}
&:active{ background-color: darken($main, 10%);} &:active{ background-color: darken($main, 10%);}
} }
&[data-loading='1']{
background-image: url('../asset/svg/loader.svg');
color: transparent;
}
} }
} }

View File

@ -31,7 +31,7 @@
<span class='footer form'> <span class='footer form'>
<button @click='gs.popup.hide()'>Cancel</button> <button @click='gs.popup.hide()'>Cancel</button>
<button class='submit' @click='gs.popup.get(`room.create`).submit()'>Create Room</button> <button class='submit' :data-loading='gs.popup.loading?1:0' @click='gs.popup.get(`room.create`).submit()'>Create Room</button>
</span> </span>
</div> </div>
@ -49,7 +49,7 @@
<span class='footer form'> <span class='footer form'>
<button @click='gs.popup.hide()'>Cancel</button> <button @click='gs.popup.hide()'>Cancel</button>
<button class='submit' @click='gs.popup.get(`channel.create`).submit()'>Create Channel</button> <button class='submit' :data-loading='gs.popup.loading?1:0' @click='gs.popup.get(`channel.create`).submit()'>Create Channel</button>
</span> </span>
</div> </div>
@ -66,7 +66,7 @@
<span class='footer form'> <span class='footer form'>
<button @click='gs.popup.hide()'>Cancel</button> <button @click='gs.popup.hide()'>Cancel</button>
<button class='submit' @click='gs.popup.get(`username.change`).submit()'>Save</button> <button class='submit' :data-loading='gs.popup.loading?1:0' @click='gs.popup.get(`username.change`).submit()'>Save</button>
</span> </span>
</div> </div>
@ -81,7 +81,7 @@
<span class='footer form'> <span class='footer form'>
<button @click='gs.popup.hide()'>Cancel</button> <button @click='gs.popup.hide()'>Cancel</button>
<button class='submit' @click='gs.popup.get(`channel.invite`).submit()'>Invite</button> <button class='submit' :data-loading='gs.popup.loading?1:0' @click='gs.popup.get(`channel.invite`).submit()'>Invite</button>
</span> </span>
</div> </div>
@ -95,7 +95,7 @@
<span class='footer form'> <span class='footer form'>
<button @click='gs.popup.hide()'>Cancel</button> <button @click='gs.popup.hide()'>Cancel</button>
<button class='submit invalid' @click='gs.popup.get(`channel.remove`).submit()'>Remove</button> <button class='submit invalid' :data-loading='gs.popup.loading?1:0' @click='gs.popup.get(`channel.remove`).submit()'>Remove</button>
</span> </span>
</div> </div>
@ -109,7 +109,7 @@
<span class='footer form'> <span class='footer form'>
<button @click='gs.popup.hide()'>Cancel</button> <button @click='gs.popup.hide()'>Cancel</button>
<button class='submit invalid' @click='gs.popup.get(`room.remove`).submit()'>Remove</button> <button class='submit invalid' :data-loading='gs.popup.loading?1:0' @click='gs.popup.get(`room.remove`).submit()'>Remove</button>
</span> </span>
</div> </div>
@ -123,7 +123,7 @@
<span class='footer form'> <span class='footer form'>
<button @click='gs.popup.hide()'>Cancel</button> <button @click='gs.popup.hide()'>Cancel</button>
<button class='submit invalid' @click='gs.popup.get(`channel.leave`).submit()'>Leave</button> <button class='submit invalid' :data-loading='gs.popup.loading?1:0' @click='gs.popup.get(`channel.leave`).submit()'>Leave</button>
</span> </span>
</div> </div>
@ -142,7 +142,7 @@
<span class='footer form'> <span class='footer form'>
<button @click='gs.popup.hide()'>Cancel</button> <button @click='gs.popup.hide()'>Cancel</button>
<button class='submit' @click='gs.popup.get(`password.change`).submit()'>Update</button> <button class='submit' :data-loading='gs.popup.loading?1:0' @click='gs.popup.get(`password.change`).submit()'>Update</button>
</span> </span>
</div> </div>