Commit 64e6f14b authored by Vivek's avatar Vivek Committed by wenjie.zheng

jabberclient: added auto-reconnect after disconnection, updated error handling.

parent 0d8b41d3
......@@ -200,6 +200,7 @@
</div>\n
<input data-inline="true" type="submit" value="Log In" data-theme="b">\n
</form>\n
<pre style="white-space: pre-wrap;">{{message}}</pre>\n
</div>\n
<div class="ui-block-c"></div>\n
</div>\n
......@@ -249,7 +250,6 @@
\n
<script class="history-template" type="text/x-handlebars-template"><pre style="white-space: pre-wrap;">{{text}}</pre></script>\n
\n
<script class="error-template" type="text/x-handlebars-template"><pre style="white-space: pre-wrap;">{{error_message}}</pre></script>\n
<script class="header-template" type="text/x-handlebars-template">\n
{{#if left_url}}\n
<a href="{{left_url}}" class="ui-btn-left ui-btn ui-btn-inline ui-mini ui-corner-all">{{left_title}}</a>\n
......@@ -407,7 +407,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
<value> <string>zope1</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -421,7 +421,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>944.5553.6477.32460</string> </value>
<value> <string>944.54830.54261.27972</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -439,7 +439,7 @@
</tuple>
<state>
<tuple>
<float>1435739472.1</float>
<float>1438695309.09</float>
<string>GMT</string>
</tuple>
</state>
......
......@@ -239,7 +239,7 @@
var prefix,\n
date = new Date(),\n
timestamp = date.getFullYear() + "-" +\n
zfill(date.getMonth(), 2) + "-" +\n
zfill(date.getMonth() + 1, 2) + "-" +\n
zfill(date.getDate(), 2) + " " +\n
date.toTimeString();\n
if (is_incomming) {\n
......@@ -413,25 +413,6 @@
$(gadget.props.element).trigger("create");\n
});\n
}\n
\n
function renderErrorPage(gadget, error) {\n
var error_text = error;\n
return RSVP.Queue()\n
.push(function () {\n
return gadget.aq_pleasePublishMyState({page: PAGE_CONNECTION});\n
})\n
.push(function (connection_url) {\n
gadget.props.header_element.innerHTML = gadget.props.header_template({\n
left_url: connection_url,\n
left_title: "Login",\n
title: "Error Message"\n
});\n
gadget.props.content_element.innerHTML = gadget.props.error_template({\n
error_message: error_text\n
});\n
$(gadget.props.element).trigger("create");\n
});\n
}\n
\n
function renderDialogPage(gadget, connection_gadget) {\n
var jid,\n
......@@ -487,10 +468,13 @@
});\n
}\n
\n
function renderConnectPage(gadget) {\n
function renderConnectPage(gadget, display_message) {\n
// Always flush the contact list\n
gadget.props.contact_dict = {};\n
gadget.props.my_server = \'\',\n
gadget.props.my_jid = \'\';\n
gadget.props.my_password = \'\';\n
gadget.props.connected = false;\n
// Always kill the previous connection gadget to ensure disconnection\n
gadget.props.connection_element.innerHTML = "";\n
return gadget.dropGadget(CONNECTION_GADGET_SCOPE)\n
......@@ -510,7 +494,9 @@
title: "Connect"\n
});\n
gadget.props.content_element.innerHTML =\n
gadget.props.login_template({});\n
gadget.props.login_template({\n
message: display_message || ""\n
});\n
$(gadget.props.element).trigger("create");\n
gadget.props.content_element.querySelector("input[name=jid]")\n
.focus();\n
......@@ -531,15 +517,14 @@
.push(function (result_list) {\n
var connection_gadget = result_list[0],\n
submit_event = result_list[1];\n
gadget.props.my_server = submit_event.target[0].value; \n
gadget.props.my_jid = submit_event.target[1].value;\n
gadget.props.my_password = submit_event.target[2].value;\n
return connection_gadget.connect(\n
submit_event.target[0].value,\n
submit_event.target[1].value,\n
submit_event.target[2].value\n
);\n
})\n
.push(function () {\n
return redirectToDefaultPage(gadget);\n
});\n
}\n
\n
......@@ -582,10 +567,8 @@
});\n
}\n
\n
function renderResetPasswordPage(gadget, connection_gadget, status) {\n
if(!status) {\n
status = "";\n
}\n
function renderResetPasswordPage(gadget, connection_gadget, display_message) {\n
var new_password = \'\';\n
return new RSVP.Queue()\n
.push(function () {\n
return gadget.aq_pleasePublishMyState({page: PAGE_CONTACT});\n
......@@ -598,7 +581,7 @@
});\n
gadget.props.content_element.innerHTML =\n
gadget.props.reset_password_template({\n
message: status\n
message: display_message || ""\n
});\n
$(gadget.props.element).trigger("create");\n
gadget.props.content_element.querySelector("input[type=submit]")\n
......@@ -617,6 +600,7 @@
})\n
.push(function (submit_event) {\n
var matched = false;\n
new_password = submit_event.target[1].value;\n
gadget.props.content_element.querySelector("input[type=submit]")\n
.disabled = true;\n
matched = validatePassword(\n
......@@ -629,6 +613,7 @@
submit_event.target[1].value\n
)\n
.push(function (status) {\n
gadget.props.my_password = new_password;\n
return renderResetPasswordPage(gadget, connection_gadget, status);\n
}, function (error) {\n
var message = "Password Reset Failed.";\n
......@@ -667,9 +652,6 @@
g.props.history_template = Handlebars.compile(\n
document.querySelector(".history-template").innerHTML\n
);\n
g.props.error_template = Handlebars.compile(\n
document.querySelector(".error-template").innerHTML\n
);\n
g.props.reset_password_template = Handlebars.compile(\n
document.querySelector(".reset-password-template").innerHTML\n
);\n
......@@ -691,7 +673,11 @@
//////////////////////////////////////////\n
.allowPublicAcquisition("notifyXMPPConnected", function () {\n
var gadget = this;\n
return gadget.getDeclaredGadget(CONNECTION_GADGET_SCOPE)\n
gadget.props.connected = true;\n
return redirectToDefaultPage(gadget)\n
.push(function() {\n
return gadget.getDeclaredGadget(CONNECTION_GADGET_SCOPE);\n
})\n
.push(function (connection_gadget) {\n
return connection_gadget.sendPresence();\n
})\n
......@@ -707,8 +693,8 @@
initializeContact(gadget, all_contacts[key].jid);\n
}\n
}, function (error) {\n
var error_text = "Roster Fetching Failed";\n
return renderErrorPage(gadget, error_text);\n
var error_text = "Fetching Contact List Failed. Please login again.";\n
return renderConnectPage(gadget, error_text);\n
});\n
})\n
.allowPublicAcquisition("notifyXMPPConnecting", function () {\n
......@@ -788,23 +774,37 @@
\n
.allowPublicAcquisition("notifyXMPPConnectingFail", function () {\n
var gadget = this,\n
error_text = \'XMPPConnectingFail\';\n
return renderErrorPage(gadget, error_text);\n
error_text = \'Connection Failed. Please login again.\';\n
return renderConnectPage(gadget, error_text);\n
})\n
.allowPublicAcquisition("notifyXMPPDisconnecting", function () {\n
var gadget = this,\n
error_text = \'XMPPDisconnecting\';\n
return renderErrorPage(gadget, error_text);\n
return;\n
})\n
.allowPublicAcquisition("notifyXMPPDisconnected", function () {\n
var gadget = this,\n
error_text = \'XMPPDisconnected\';\n
return renderErrorPage(gadget, error_text);\n
error_text = \'Session Disconnected. Please login again.\';\n
if(!gadget.props.connected) {\n
return renderConnectPage(gadget, error_text);\n
} else {\n
gadget.props.connected = false;\n
gadget.props.contact_dict = {};\n
return gadget.getDeclaredGadget(CONNECTION_GADGET_SCOPE)\n
.push(function (connection_gadget) {\n
return connection_gadget.connect(\n
gadget.props.my_server, \n
gadget.props.my_jid,\n
gadget.props.my_password\n
);\n
})\n
.push(function () {\n
return redirectToDefaultPage(gadget);\n
});\n
}\n
})\n
.allowPublicAcquisition("notifyXMPPAuthenticatingFailed", function (error_data) {\n
var gadget = this,\n
error_text = \'XMPPAuthenticatingFailed\';\n
return renderErrorPage(gadget, error_text);\n
error_text = \'Authentication Failed. Please try again.\';\n
return renderConnectPage(gadget, error_text);\n
})\n
.declareService(function () {\n
\n
......@@ -998,7 +998,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
<value> <string>zope1</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -1012,7 +1012,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>944.5545.36219.41881</string> </value>
<value> <string>944.54834.23868.16998</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -1030,7 +1030,7 @@
</tuple>
<state>
<tuple>
<float>1435744547.72</float>
<float>1438696276.38</float>
<string>GMT</string>
</tuple>
</state>
......
......@@ -583,7 +583,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>944.5651.30805.18688</string> </value>
<value> <string>944.7242.54723.60006</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -601,7 +601,7 @@
</tuple>
<state>
<tuple>
<float>1435744650.8</float>
<float>1436191748.38</float>
<string>GMT</string>
</tuple>
</state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment