Commit f1cdd9f5 authored by Xiaowu Zhang's avatar Xiaowu Zhang

enable ip taken while net connects

parent f4b86584
...@@ -27,6 +27,9 @@ ...@@ -27,6 +27,9 @@
controlPanel = g.__element.getElementsByClassName("page")[0], controlPanel = g.__element.getElementsByClassName("page")[0],
i = 0, i = 0,
circle; circle;
if (controlPanel.firstChild) {
return;
}
overlay.className = 'overlay'; overlay.className = 'overlay';
loader.className = 'loader'; loader.className = 'loader';
while (i < 5) { while (i < 5) {
......
<!DOCTYPE html> <!DOCTYPE html>
<html manifest="audioPlayer.appcache"> <!--html manifest="audioPlayer.appcache"-->
<head> <head>
<!-- renderjs --> <!-- renderjs -->
<script src="../<%= copy.rsvp.relative_dest %>" type="text/javascript"></script> <script src="../<%= copy.rsvp.relative_dest %>" type="text/javascript"></script>
......
button.loop { button.loop {
width : 6em; width : 10em;
} }
#visualizer { #visualizer {
text-align: center; text-align: center;
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
<button type="button" class="loop" ></button> <button type="button" data-icon="refresh" class="loop" ></button>
<div id="visualizer"> <div id="visualizer">
......
/*global window, rJS, RSVP, console, jQuery, $, JSON, Handlebars, /*global window, rJS, RSVP, console, jQuery, $, JSON, Handlebars,
loopEventListener, RegExp, alert */ loopEventListener, RegExp, alert, promiseEventListener */
/*jslint maxlen:180, nomen: true */ /*jslint maxlen:180, nomen: true */
...@@ -19,6 +19,51 @@ ...@@ -19,6 +19,51 @@
return true; return true;
} }
function check(value) {
var g = this,
info = g.__element.getElementsByClassName('info')[0],
http,
port,
portEnd,
ipValue = value;
g.__element.getElementsByTagName('ul')[0].innerHTML = " ";
if (ipValue.indexOf("/", ipValue.length - 1) === -1) {
info.innerHTML = " not end with /";
return;
}
http = ipValue.indexOf("http://");
ipValue = ipValue.substring(ipValue.indexOf("//") + 2);
port = ipValue.indexOf(":");
portEnd = ipValue.indexOf(":/");
if (port !== -1) {
ipValue = ipValue.substring(0, port);
}
if (http === -1) {
info.innerHTML = " please start ip with http://";
return;
}
if (port === -1 || portEnd !== -1) {
info.innerHTML = "input port number";
return;
}
if (checkIp(ipValue) === false) {
info.innerHTML =
"invalide ip: ip should like xxx.xxx.xxx.xxx(xxx is between 0 ~ 255)";
return;
}
return new RSVP.Queue()
.push(function () {
return g.plSave({"ip": value});
})
.push(function () {
return g.displayThisPage({page: "playlist",
action: value});
})
.push(function (url) {
window.location = url;
});
}
gk.declareAcquiredMethod("allDocs", "allDocs") gk.declareAcquiredMethod("allDocs", "allDocs")
.declareAcquiredMethod("plSave", "plSave") .declareAcquiredMethod("plSave", "plSave")
.declareAcquiredMethod("plGive", "plGive") .declareAcquiredMethod("plGive", "plGive")
...@@ -30,6 +75,8 @@ ...@@ -30,6 +75,8 @@
.declareMethod('render', function (options) { .declareMethod('render', function (options) {
var gadget = this, var gadget = this,
ipValue, ipValue,
ip_context = gadget.
__element.getElementsByClassName('inputIp')[0],
list = gadget.__element.getElementsByTagName('ul')[0]; list = gadget.__element.getElementsByTagName('ul')[0];
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
...@@ -47,38 +94,49 @@ ...@@ -47,38 +94,49 @@
.href = param_list[1]; .href = param_list[1];
}) })
.push(function () { .push(function () {
if (options.action) {
return options.action;
}
return gadget.plGive("ip"); return gadget.plGive("ip");
}) })
.push(function (value) { .push(function (value) {
if (value !== undefined) { if (value !== undefined) {
ipValue = value; ipValue = value;
gadget.__element.getElementsByClassName('inputIp')[0] ip_context.value = value;
.value = value; return gadget.plCreateHttpStorage(value);
} }
return gadget.allDocs({"include_docs": true}); })
.push(function () {
return RSVP.any([
gadget.allDocs({"include_docs": true}),
promiseEventListener(ip_context, "change", false)
]);
}) })
.push(function (e) { .push(function (e) {
var tmp = e.data.rows, if (e.data) {
i, var tmp = e.data.rows,
j, i,
exp; j,
if (options.id !== undefined && options.id !== "online") { exp;
tmp = []; if (options.id !== undefined && options.id !== "online") {
for (i = 0, j = 0; i < e.data.rows.length; i += 1) { tmp = [];
exp = new RegExp(options.id, "i"); for (i = 0, j = 0; i < e.data.rows.length; i += 1) {
if (e.data.rows[i].doc.title.search(exp) !== -1) { exp = new RegExp(options.id, "i");
tmp[j] = e.data.rows[i]; if (e.data.rows[i].doc.title.search(exp) !== -1) {
j += 1; tmp[j] = e.data.rows[i];
j += 1;
}
} }
gadget.id = options.id;
} }
gadget.id = options.id; list.innerHTML = network({
"rows" : tmp
});
$(list).listview("refresh");
return gadget.displayThisTitle("online playlist: " +
tmp.length + " music");
} }
list.innerHTML = network({ return check.call(gadget, ip_context.value);
"rows" : tmp
});
$(list).listview("refresh");
return gadget.displayThisTitle("online playlist: " +
tmp.length + " music");
}) })
.fail(function (error) { .fail(function (error) {
if (ipValue) { if (ipValue) {
...@@ -113,50 +171,7 @@ ...@@ -113,50 +171,7 @@
}); });
}), }),
loopEventListener(ip, "change", false, function () { loopEventListener(ip, "change", false, function () {
var info = g.__element.getElementsByClassName('info')[0], return check.call(g, ip.value);
http,
port,
portEnd,
ipValue = ip.value;
g.__element.getElementsByTagName('ul')[0].innerHTML = " ";
if (ipValue.indexOf("/", ipValue.length - 1) === -1) {
info.innerHTML = " not end with /";
return;
}
http = ipValue.indexOf("http://");
ipValue = ipValue.substring(ipValue.indexOf("//") + 2);
port = ipValue.indexOf(":");
portEnd = ipValue.indexOf(":/");
if (port !== -1) {
ipValue = ipValue.substring(0, port);
}
if (http === -1) {
info.innerHTML = " please start ip with http://";
return;
}
if (port === -1 || portEnd !== -1) {
info.innerHTML = "input port number";
return;
}
if (checkIp(ipValue) === false) {
info.innerHTML =
"invalide ip: ip should like xxx.xxx.xxx.xxx(xxx is between 0 ~ 255)";
return;
}
return new RSVP.Queue()
.push(function () {
return g.plCreateHttpStorage(ip.value);
})
.push(function () {
return g.plSave({"ip": ip.value});
})
.push(function () {
return g.displayThisPage({page: "playlist",
action: ip.value});
})
.push(function (url) {
window.location = url;
});
}) })
]);//any ]);//any
});//rsvp });//rsvp
......
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