-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
usermenu: Load usermenu asynchronously
- Loading branch information
Showing
8 changed files
with
145 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,6 +122,6 @@ | |
</form> | ||
</li> | ||
</ul> | ||
@common.usermenu(null) | ||
@common.usermenu() | ||
</div> | ||
</header> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@** | ||
* Yona, 21st Century Project Hosting SW | ||
* | ||
* Copyright Yona & Yobi Authors & NAVER Corp. | ||
* https://yona.io | ||
**@ | ||
<div class="tab-pane user-project-list active" id="myProjectList"> | ||
@views.html.index.myProjectList(UserApp.currentUser()) | ||
</div> | ||
<div class="tab-pane user-project-list" id="myOrganizationList"> | ||
@views.html.index.myOrganizationList(UserApp.currentUser()) | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,133 +1,144 @@ | ||
$(function() { | ||
/* Set side navigation */ | ||
// Also, see index.scala.html for home page menu sliding actions !! | ||
var $sidebar = $("#mySidenav"); | ||
var viewSize = $(window).width(); | ||
var PIXEL_CRITERIA_FOR_SMALL_DEVICE = 720; // Criteria to distinguish small devices | ||
var SIDE_BAR_DEFAULT_WIDTH = "420px"; | ||
$.get(UsermenuUrl) | ||
.done(function (data) { | ||
$("#usermenu-tab-content-list").html(data); | ||
afterUsermenuLoaded(); | ||
}) | ||
.fail(function (data) { | ||
$yobi.alert("Usermenu loading failed: " + data); | ||
});; | ||
|
||
$("#main").on("click", function(event){ | ||
if( $sidebar.width() !== 0 && $(event.target).parents("#mySidenav").length == 0) { | ||
closeSidebar($sidebar); | ||
} | ||
}); | ||
function afterUsermenuLoaded(){ | ||
/* Set side navigation */ | ||
// Also, see index.scala.html for home page menu sliding actions !! | ||
var $sidebar = $("#mySidenav"); | ||
var viewSize = $(window).width(); | ||
var PIXEL_CRITERIA_FOR_SMALL_DEVICE = 720; // Criteria to distinguish small devices | ||
var SIDE_BAR_DEFAULT_WIDTH = "420px"; | ||
|
||
$("#sidebar-open-btn").on("click", function (event) { | ||
event.stopPropagation(); | ||
if( $sidebar.width() !== 0){ | ||
closeSidebar($sidebar); | ||
} else { | ||
openSidebar($sidebar); | ||
updateStar(); | ||
} | ||
}); | ||
$("#main").on("click", function(event){ | ||
if( $sidebar.width() !== 0 && $(event.target).parents("#mySidenav").length == 0) { | ||
closeSidebar($sidebar); | ||
} | ||
}); | ||
|
||
function closeSidebar($sidebar) { | ||
$sidebar.width("0").css("border", "none"); | ||
$(".main-stream").removeClass("span8").addClass("span12"); | ||
} | ||
$("#sidebar-open-btn").on("click", function (event) { | ||
event.stopPropagation(); | ||
if( $sidebar.width() !== 0){ | ||
closeSidebar($sidebar); | ||
} else { | ||
openSidebar($sidebar); | ||
updateStar(); | ||
} | ||
}); | ||
|
||
function openSidebar($sidebar){ | ||
// 720px is a criteria to distinguish small devices | ||
if (viewSize > PIXEL_CRITERIA_FOR_SMALL_DEVICE) { | ||
$sidebar.width(SIDE_BAR_DEFAULT_WIDTH).css("border", "1px solid #ccc"); | ||
$(".search-input").focus(); | ||
} else { | ||
$sidebar.width("100vw").css("border", "1px solid #ccc"); | ||
function closeSidebar($sidebar) { | ||
$sidebar.width("0").css("border", "none"); | ||
$(".main-stream").removeClass("span8").addClass("span12"); | ||
} | ||
$(".main-stream").removeClass("span12").addClass("span8"); | ||
} | ||
|
||
// used for new project list ui | ||
$(".right-menu").on('click', ".myProjectList, a[href='#recentlyVisited'], a[href='#createdByMe'], a[href='#watching'], a[href='#joinmember']", function() { | ||
updateStar(); | ||
setTimeout(function focusToProjectSearchInput() { | ||
var $projectSearch = $('.project-search'); | ||
var $orgSearch = $('.org-search'); | ||
function openSidebar($sidebar){ | ||
// 720px is a criteria to distinguish small devices | ||
if (viewSize > PIXEL_CRITERIA_FOR_SMALL_DEVICE) { | ||
$projectSearch.focus(); | ||
} | ||
if(!$projectSearch.val()){ | ||
$projectSearch.val($orgSearch.val()); | ||
$sidebar.width(SIDE_BAR_DEFAULT_WIDTH).css("border", "1px solid #ccc"); | ||
$(".search-input").focus(); | ||
} else { | ||
$sidebar.width("100vw").css("border", "1px solid #ccc"); | ||
} | ||
$orgSearch.val(""); | ||
}, 200); | ||
$(".main-stream").removeClass("span12").addClass("span8"); | ||
} | ||
|
||
}); | ||
// used for new project list ui | ||
$(".right-menu").on('click', ".myProjectList, a[href='#recentlyVisited'], a[href='#createdByMe'], a[href='#watching'], a[href='#joinmember']", function() { | ||
updateStar(); | ||
setTimeout(function focusToProjectSearchInput() { | ||
var $projectSearch = $('.project-search'); | ||
var $orgSearch = $('.org-search'); | ||
if (viewSize > PIXEL_CRITERIA_FOR_SMALL_DEVICE) { | ||
$projectSearch.focus(); | ||
} | ||
if(!$projectSearch.val()){ | ||
$projectSearch.val($orgSearch.val()); | ||
} | ||
$orgSearch.val(""); | ||
}, 200); | ||
|
||
$('.myOrganizationList').on('click', function focusToOrgSearchInput(){ | ||
setTimeout(function () { | ||
var $projectSearch = $('.project-search'); | ||
var $orgSearch = $('.org-search'); | ||
if (viewSize > PIXEL_CRITERIA_FOR_SMALL_DEVICE) { | ||
$orgSearch.focus(); | ||
} | ||
$orgSearch.val($projectSearch.val()); | ||
$projectSearch.val(""); | ||
}, 200); | ||
}); | ||
}); | ||
|
||
// search by keyword | ||
$(".search-input").on("keyup", function() { | ||
var value = $(this).val().toLowerCase().trim(); | ||
$(".user-li").each(function() { | ||
$(this).toggle($(this).text().toLowerCase().indexOf(value) !== -1); | ||
$('.myOrganizationList').on('click', function focusToOrgSearchInput(){ | ||
setTimeout(function () { | ||
var $projectSearch = $('.project-search'); | ||
var $orgSearch = $('.org-search'); | ||
if (viewSize > PIXEL_CRITERIA_FOR_SMALL_DEVICE) { | ||
$orgSearch.focus(); | ||
} | ||
$orgSearch.val($projectSearch.val()); | ||
$projectSearch.val(""); | ||
}, 200); | ||
}); | ||
}).on("keydown.moveCursorFromInputform", function(e) { | ||
switch (e.keyCode) { | ||
case 27: // ESC | ||
closeSidebar($sidebar); | ||
break; | ||
default: | ||
break; | ||
} | ||
}); | ||
|
||
$(".project-list > .star-project").on("click", function toggleProjectFavorite(e) { | ||
e.stopPropagation(); | ||
var that = $(this); | ||
$.post(UsermenuToggleFavoriteProjectUrl + that.data("projectId")) | ||
.done(function (data) { | ||
if(data.favored){ | ||
that.find('i').addClass("starred"); | ||
} else { | ||
that.find('i').removeClass("starred"); | ||
that.parent(".project-list").remove(); | ||
} | ||
}) | ||
.fail(function (data) { | ||
$yobi.alert("Update failed: " + JSON.parse(data.responseText).reason); | ||
// search by keyword | ||
$(".search-input").on("keyup", function() { | ||
var value = $(this).val().toLowerCase().trim(); | ||
$(".user-li").each(function() { | ||
$(this).toggle($(this).text().toLowerCase().indexOf(value) !== -1); | ||
}); | ||
}); | ||
|
||
$(".org-list > .star-org").on("click", function toggleOrgFavorite(e) { | ||
e.stopPropagation(); | ||
var that = $(this); | ||
$.post(UsermenuToggleFoveriteOrganizationUrl + that.data("organizationId")) | ||
.done(function (data) { | ||
if(data.favored){ | ||
that.find('i').addClass("starred"); | ||
} else { | ||
that.find('i').removeClass("starred"); | ||
}).on("keydown.moveCursorFromInputform", function(e) { | ||
switch (e.keyCode) { | ||
case 27: // ESC | ||
closeSidebar($sidebar); | ||
break; | ||
default: | ||
break; | ||
} | ||
}) | ||
.fail(function (data) { | ||
$yobi.alert("Update failed: " + JSON.parse(data.responseText).reason); | ||
}); | ||
}); | ||
}); | ||
|
||
// This method intended to sync sub tab list of projects | ||
function updateStar(){ | ||
$.get(UsermenuGetFoveriteProjectsUrl) | ||
.done(function(data){ | ||
$(".star-project").each(function () { | ||
var $this = $(this); | ||
if (data.projectIds.includes($this.data("projectId"))) { | ||
$this.find("i").addClass("starred"); | ||
$(".project-list > .star-project").on("click", function toggleProjectFavorite(e) { | ||
e.stopPropagation(); | ||
var that = $(this); | ||
$.post(UsermenuToggleFavoriteProjectUrl + that.data("projectId")) | ||
.done(function (data) { | ||
if(data.favored){ | ||
that.find('i').addClass("starred"); | ||
} else { | ||
$this.find("i").removeClass("starred"); | ||
that.find('i').removeClass("starred"); | ||
that.parent(".project-list").remove(); | ||
} | ||
}) | ||
.fail(function (data) { | ||
$yobi.alert("Update failed: " + JSON.parse(data.responseText).reason); | ||
}); | ||
}); | ||
}); | ||
|
||
$(".org-list > .star-org").on("click", function toggleOrgFavorite(e) { | ||
e.stopPropagation(); | ||
var that = $(this); | ||
$.post(UsermenuToggleFoveriteOrganizationUrl + that.data("organizationId")) | ||
.done(function (data) { | ||
if(data.favored){ | ||
that.find('i').addClass("starred"); | ||
} else { | ||
that.find('i').removeClass("starred"); | ||
} | ||
}) | ||
.fail(function (data) { | ||
$yobi.alert("Update failed: " + JSON.parse(data.responseText).reason); | ||
}); | ||
}); | ||
|
||
// This method intended to sync sub tab list of projects | ||
function updateStar(){ | ||
$.get(UsermenuGetFoveriteProjectsUrl) | ||
.done(function(data){ | ||
$(".star-project").each(function () { | ||
var $this = $(this); | ||
if (data.projectIds.includes($this.data("projectId"))) { | ||
$this.find("i").addClass("starred"); | ||
} else { | ||
$this.find("i").removeClass("starred"); | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
}); |