Permalink
Browse files

Better Login/logout handling + manga count in folder tree

  • Loading branch information...
1 parent 97b8214 commit 68cac7b9e6fe0da1a27b07b03ef847fcb5210a49 @a-fung committed Nov 5, 2012
@@ -456,11 +456,12 @@ public void ProcessFolderCache()
foreach (Dictionary<string, object> result in resultSet)
{
string path = Convert.ToString(result["path"]).Substring(collectionPathLength);
+ string lastFolderPath = null;
int i = 0, j = 0;
while ((i = path.IndexOf(separator, j)) != -1)
{
- string relativePath = path.Substring(0, i);
+ string relativePath = lastFolderPath = path.Substring(0, i);
if (!folderDictionary.ContainsKey(relativePath.ToLowerInvariant()))
{
FolderJson subfolder = new FolderJson();
@@ -478,6 +479,11 @@ public void ProcessFolderCache()
j = i + 1;
}
+
+ if (lastFolderPath != null)
+ {
+ folderDictionary[lastFolderPath.ToLowerInvariant()].count++;
+ }
}
Dictionary<string, object> cacheData = new Dictionary<string, object>();
@@ -251,7 +251,7 @@ public static string[] JsonDecodeArchiveContentString(string jsonString)
public static void TryLogError(Exception ex)
{
- if (!Config.IsInstalled)
+ if (!Config.IsInstalled || ex.GetType() == typeof(System.Threading.ThreadAbortException))
{
return;
}
@@ -10,5 +10,6 @@ public class FolderJson
{
public string name;
public FolderJson[] subfolders;
+ public int count;
}
}
@@ -9,6 +9,7 @@ class FolderJson
{
public var name:String;
public var subfolders:Array<FolderJson>;
+ public var count:Int;
public function new()
{
@@ -433,11 +433,12 @@ class Collection
for (result in resultSet)
{
var path:String = Std.string(result.get("path")).substr(collectionPathLength);
+ var lastFolderPath:String = null;
var i:Int = 0, j:Int = 0;
while ((i = path.indexOf(separator, j)) != -1)
{
- var relativePath = path.substr(0, i);
+ var relativePath:String = lastFolderPath = path.substr(0, i);
if (!folderDictionary.exists(relativePath))
{
var subfolder:FolderJson = new FolderJson();
@@ -452,6 +453,11 @@ class Collection
j = i + 1;
}
+
+ if (lastFolderPath != null)
+ {
+ folderDictionary.get(lastFolderPath).count++;
+ }
}
var cacheData:Hash<Dynamic> = new Hash<Dynamic>();
@@ -168,5 +168,20 @@ private void InternalHide()
jQuery.Select("#login-modal-password").Value("");
Hide();
}
+
+ public static void Logout()
+ {
+ LoginRequest request = new LoginRequest();
+ request.password = "logout";
+ Request.Send(request, LogoutSuccessful);
+ }
+
+ [AlternateSignature]
+ private extern static void LogoutSuccessful(JsonResponse response);
+ private static void LogoutSuccessful(LoginResponse response)
+ {
+ userInfo = response;
+ LoginWidget.RefreshAll();
+ }
}
}
@@ -10,14 +10,14 @@ namespace afung.MangaWeb3.Client.Module
{
public abstract class ClientModuleBase : ModuleBase
{
- protected ClientModuleBase(string templateId)
+ protected ClientModuleBase(string templateId, Action loginRefreshCallback)
: base("client", templateId)
{
jQuery.Select(".nav-mangas", attachedObject).Click(NavMangasClicked);
jQuery.Select(".nav-folders", attachedObject).Click(NavFoldersClicked);
jQuery.Select(".nav-search", attachedObject).Click(NavSearchClicked);
jQuery.Select(".nav-settings", attachedObject).Click(NavSettingsClicked);
- new LoginWidget(jQuery.Select(".nav-main", attachedObject));
+ new LoginWidget(jQuery.Select(".nav-main", attachedObject), loginRefreshCallback);
}
private void NavMangasClicked(jQueryEvent e)
@@ -20,17 +20,31 @@ public static FoldersModule Instance
{
if (_instance == null)
{
- _instance = new FoldersModule();
+ Action loginRefreshCallback = delegate
+ {
+ if (_instance != null)
+ {
+ _instance.Refresh();
+ }
+ };
+
+ _instance = new FoldersModule(loginRefreshCallback);
}
return _instance;
}
}
- private FoldersModule()
- : base("folders-module")
+ private FoldersModule(Action loginRefreshCallback)
+ : base("folders-module", loginRefreshCallback)
{
jQuery.Select("#folders-all-folders-btn").Click(AllFoldersButtonClicked);
+ Refresh();
+ }
+
+ public void Refresh()
+ {
+ jQuery.Select("#folders-area").Children().Remove();
Request.Send(new FolderRequest(), FolderRequestSuccess);
Template.Get("client", "loading-well", true).AppendTo(jQuery.Select("#folders-area"));
}
@@ -32,7 +32,15 @@ public static MangasModule Instance
{
if (_instance == null)
{
- _instance = new MangasModule();
+ Action loginRefreshCallback = delegate
+ {
+ if (_instance != null)
+ {
+ _instance.Refresh(null, true);
+ }
+ };
+
+ _instance = new MangasModule(loginRefreshCallback);
}
return _instance;
@@ -41,8 +49,8 @@ public static MangasModule Instance
private int currentPage;
- private MangasModule()
- : base("mangas-module")
+ private MangasModule(Action loginRefreshCallback)
+ : base("mangas-module", loginRefreshCallback)
{
items = new MangaListItemJson[] { };
currentPage = 1;
@@ -68,7 +76,9 @@ protected override void OnShow()
[AlternateSignature]
public extern void Refresh();
- public void Refresh(MangaFilter filter)
+ [AlternateSignature]
+ public extern void Refresh(MangaFilter filter);
+ public void Refresh(MangaFilter filter, bool suppressShowModule)
{
if (Script.IsNullOrUndefined(filter))
{
@@ -135,7 +145,14 @@ public void Refresh(MangaFilter filter)
items = new MangaListItemJson[] { };
jQuery.Select(".mangas-pagination").Children().Remove();
jQuery.Select("#mangas-list").Children().Remove();
- Show(onReady);
+ if (suppressShowModule)
+ {
+ onReady();
+ }
+ else
+ {
+ Show(onReady);
+ }
}
else
{
@@ -26,7 +26,7 @@ public static SearchModule Instance
}
private SearchModule()
- : base("search-module")
+ : base("search-module", null)
{
jQuery.Select("#search-submit").Click(SubmitSearchForm);
jQuery.Select("#search-form").Submit(SubmitSearchForm);
@@ -25,7 +25,7 @@ public static SettingsModule Instance
}
private SettingsModule()
- : base("settings-module")
+ : base("settings-module", null)
{
jQuery.Select("#settings-apply-btn").Click(ApplyChange);
jQuery.Select("#settings-form").Submit(ApplyChange);
@@ -30,7 +30,7 @@ public FoldersWidget(jQueryObject parent, FolderJson[] folders, string folderPat
{
string subfolderPath = folderPath + separator + folder.name;
jQueryObject row = Template.Get("client", "folders-trow", true).AppendTo(attachedObject.Children());
- jQueryObject btn = jQuery.Select(".folders-btn", row).Text(folder.name).Click(FolderButtonClick).Attribute("data-path", subfolderPath);
+ jQueryObject btn = jQuery.Select(".folders-btn", row).Click(FolderButtonClick).Attribute("data-path", subfolderPath).Text(folder.count == 0 ? folder.name : String.Format("{0} ({1})", folder.name, folder.count));
jQueryObject expandBtn = jQuery.Select(".folders-expand-btn", row).Click(ExpandButtonClick);
if (folder.subfolders != null && folder.subfolders.Length > 0)
@@ -76,7 +76,7 @@ private void ExpandButtonClick(jQueryEvent e)
table.Show();
target.Children().RemoveClass("icon-plus").AddClass("icon-minus");
- if (Settings.UseAnimation)
+ if (Settings.UseAnimation && table.Is(":visible"))
{
inTransition = true;
int targetHeight = table.GetHeight();
@@ -104,7 +104,7 @@ private void ExpandButtonClick(jQueryEvent e)
{
target.Children().AddClass("icon-plus").RemoveClass("icon-minus");
- if (Settings.UseAnimation)
+ if (Settings.UseAnimation && table.Is(":visible"))
{
inTransition = true;
@@ -15,10 +15,11 @@ public class LoginWidget
{
private jQueryObject loginButton;
private jQueryObject logoutDropdown;
+ private Action refreshCallback;
private static List<LoginWidget> instances;
- public LoginWidget(jQueryObject parent)
+ public LoginWidget(jQueryObject parent, Action refreshCallback)
{
if (instances == null)
{
@@ -27,6 +28,7 @@ public LoginWidget(jQueryObject parent)
loginButton = Template.Get("client", "nav-login-button", true).AppendTo(parent).Hide();
logoutDropdown = Template.Get("client", "nav-logout-dropdown", true).AppendTo(parent).Hide();
+ this.refreshCallback = refreshCallback;
jQuery.Select(".nav-login", loginButton).Click(LoginButtonClicked);
jQuery.Select(".nav-logout", logoutDropdown).Click(LogoutButtonClicked);
@@ -52,21 +54,7 @@ private void LoginButtonClicked(jQueryEvent e)
private void LogoutButtonClicked(jQueryEvent e)
{
e.PreventDefault();
-
- LoginRequest request = new LoginRequest();
- request.password = "logout";
-
- Request.Send(request, LogoutSuccessful, LogoutSuccessful);
- }
-
- [AlternateSignature]
- private extern void LogoutSuccessful(Exception error);
- [AlternateSignature]
- private extern void LogoutSuccessful(JsonResponse response);
- private void LogoutSuccessful()
- {
- // redirect to index.html
- Window.Location.Href = "index.html";
+ LoginModal.Logout();
}
private void ChangePasswordButtonClicked(jQueryEvent e)
@@ -75,7 +63,9 @@ private void ChangePasswordButtonClicked(jQueryEvent e)
ChangePasswordModal.ShowDialog();
}
- public void Refresh()
+ [AlternateSignature]
+ public extern void Refresh();
+ public void Refresh(bool callRefreshCallback)
{
LoginModal.GetUserName(delegate(LoginResponse userinfo)
{
@@ -90,6 +80,11 @@ public void Refresh()
logoutDropdown.Show();
jQuery.Select(".nav-user-username", logoutDropdown).Text(userinfo.username);
}
+
+ if (callRefreshCallback && refreshCallback != null)
+ {
+ refreshCallback();
+ }
});
}
@@ -99,7 +94,7 @@ public static void RefreshAll()
{
foreach (LoginWidget instance in instances)
{
- instance.Refresh();
+ instance.Refresh(true);
}
}
}

0 comments on commit 68cac7b

Please sign in to comment.