2
0

fsportal.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985
  1. /*
  2. * The FreeSWITCH Portal Project
  3. * Copyright (C) 2013-2013, Seven Du <dujinfang@gmail.com>
  4. *
  5. * Version: MPL 1.1
  6. *
  7. * The contents of this file are subject to the Mozilla Public License Version
  8. * 1.1 (the "License"); you may not use this file except in compliance with
  9. * the License. You may obtain a copy of the License at
  10. * http://www.mozilla.org/MPL/
  11. *
  12. * Software distributed under the License is distributed on an "AS IS" basis,
  13. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  14. * for the specific language governing rights and limitations under the
  15. * License.
  16. *
  17. * The Original Code is The FreeSWITCH Portal Project Software/Application
  18. *
  19. * The Initial Developer of the Original Code is
  20. * Seven Du <dujinfang@gmail.com>
  21. * Portions created by the Initial Developer are Copyright (C)
  22. * the Initial Developer. All Rights Reserved.
  23. *
  24. * Contributor(s):
  25. *
  26. * Seven Du <dujinfang@gmail.com>
  27. *
  28. *
  29. * fsportal.js -- The FreeSWITCH Portal Project
  30. *
  31. */
  32. var App = Ember.Application.create({
  33. LOG_TRANSITIONS: true,
  34. rootElement: $('#container'),
  35. total: 0,
  36. ready: function(){
  37. $.get("/txtapi/status", function(data){
  38. $('#serverStatus').html("<pre>" + data + "</pre>");
  39. });
  40. }
  41. });
  42. App.ApplicationRoute = Ember.Route.extend({
  43. setupController: function(controller) {
  44. // alert("setupController");
  45. },
  46. actions: {
  47. newUser: function() {
  48. return Bootstrap.ModalManager.show('newUserForm');
  49. }
  50. }
  51. });
  52. App.CallsRoute = Ember.Route.extend({
  53. setupController: function(controller) {
  54. // Set the IndexController's `title`
  55. // controller.set('title', "My App");
  56. // alert("a")
  57. console.log("callsRoute");
  58. App.callsController.load();
  59. }//,
  60. // renderTemplate: function() {
  61. // this.render('calls');
  62. // }
  63. });
  64. App.ChannelsRoute = Ember.Route.extend({
  65. setupController: function(controller) {
  66. // Set the IndexController's `title`
  67. // controller.set('title', "My App");
  68. // alert("a")
  69. console.log("callsRoute");
  70. App.channelsController.load();
  71. }//,
  72. // renderTemplate: function() {
  73. // this.render('calls');
  74. // }
  75. });
  76. App.ShowRegistrationsRoute = Ember.Route.extend({
  77. setupController: function(controller) {
  78. // Set the Controller's `title`
  79. controller.set('title', "ShowRegistrations");
  80. App.registrationsController.load();
  81. }//,
  82. // renderTemplate: function() {
  83. // this.render('calls');
  84. // }
  85. });
  86. App.ShowModulesRoute = Ember.Route.extend({
  87. setupController: function(controller) {
  88. // Set the Controller's `title`
  89. App.showModulesController.load();
  90. }//,
  91. // renderTemplate: function() {
  92. // this.render('calls');
  93. // }
  94. });
  95. App.ShowApplicationsRoute = Ember.Route.extend({
  96. setupController: function(controller) {
  97. // Set the Controller's `title`
  98. controller.set('title', "ShowApplications");
  99. console.log("showApplications");
  100. App.applicationsController.load();
  101. }//,
  102. // renderTemplate: function() {
  103. // this.render('calls');
  104. // }
  105. });
  106. App.ShowEndpointsRoute = Ember.Route.extend({
  107. setupController: function(controller) {
  108. // Set the Controller's `title`
  109. controller.set('title', "ShowEndpoints");
  110. console.log(controller);
  111. App.showEndpointsController.load();
  112. }//,
  113. // renderTemplate: function() {
  114. // this.render('calls');
  115. // }
  116. });
  117. App.ShowCodecsRoute = Ember.Route.extend({
  118. setupController: function(controller) {
  119. App.showCodecsController.load();
  120. }
  121. });
  122. App.ShowFilesRoute = Ember.Route.extend({
  123. setupController: function(controller) {
  124. App.showFilesController.load();
  125. }
  126. });
  127. App.ShowAPIsRoute = Ember.Route.extend({
  128. setupController: function(controller) {
  129. App.showAPIsController.load();
  130. }
  131. });
  132. App.ShowAliasesRoute = Ember.Route.extend({
  133. setupController: function(controller) {
  134. App.showAliasesController.load();
  135. }
  136. });
  137. App.ShowCompletesRoute = Ember.Route.extend({
  138. setupController: function(controller) {
  139. App.showCompletesController.load();
  140. }
  141. });
  142. App.ShowManagementsRoute = Ember.Route.extend({
  143. setupController: function(controller) {
  144. App.showManagementsController.load();
  145. }
  146. });
  147. App.ShowSaysRoute = Ember.Route.extend({
  148. setupController: function(controller) {
  149. App.showSaysController.load();
  150. }
  151. });
  152. App.ShowNatMapsRoute = Ember.Route.extend({
  153. setupController: function(controller) {
  154. App.showNatMapsController.load();
  155. }
  156. });
  157. App.ShowChatsRoute = Ember.Route.extend({
  158. setupController: function(controller) {
  159. App.showChatsController.load();
  160. }
  161. });
  162. App.ShowInterfacesRoute = Ember.Route.extend({
  163. setupController: function(controller) {
  164. App.showInterfacesController.load();
  165. }
  166. });
  167. App.ShowInterfaceTypesRoute = Ember.Route.extend({
  168. setupController: function(controller) {
  169. App.showInterfaceTypesController.load();
  170. }
  171. });
  172. App.ShowTasksRoute = Ember.Route.extend({
  173. setupController: function(controller) {
  174. App.showTasksController.load();
  175. }
  176. });
  177. App.ShowLimitsRoute = Ember.Route.extend({
  178. setupController: function(controller) {
  179. App.showLimitsController.load();
  180. }
  181. });
  182. App.UsersRoute = Ember.Route.extend({
  183. setupController: function(controller) {
  184. App.usersController.load();
  185. }
  186. });
  187. App.newUserRoute = Ember.Route.extend({
  188. setupController: function(Controller) {
  189. alert("auto_update_calls");
  190. },
  191. actions: {
  192. show: function(controller) {
  193. App.newUserController.show();
  194. }
  195. }
  196. });
  197. App.SofiaStatusRoute = Ember.Route.extend({
  198. setupController: function(controller) {
  199. App.sofiaStatusController.load();
  200. }
  201. });
  202. App.Router.map(function(){
  203. this.route("calls");
  204. this.route("channels");
  205. this.route("showRegistrations");
  206. this.route("showModules");
  207. this.route("showApplications");
  208. this.route("showEndpoints");
  209. this.route("showCodecs");
  210. this.route("showFiles");
  211. this.route("showAPIs");
  212. this.route("showAliases");
  213. this.route("showCompletes");
  214. this.route("showManagements");
  215. this.route("showNatMaps");
  216. this.route("showSays");
  217. this.route("showChats");
  218. this.route("showInterfaces");
  219. this.route("showInterfaceTypes");
  220. this.route("showTasks");
  221. this.route("showLimits");
  222. this.route("show");
  223. this.route("users");
  224. this.route("newUser");
  225. this.route("sofiaStatus");
  226. this.route("addGateway");
  227. this.route("about", { path: "/about" });
  228. });
  229. App.User = Em.Object.extend({
  230. id: null,
  231. context: null,
  232. domain: null,
  233. group: null,
  234. contact: null
  235. });
  236. App.Call = Em.Object.extend({
  237. uuid: null,
  238. cidName: null,
  239. cidNumber: null
  240. });
  241. App.Channel = Em.Object.extend({
  242. uuid: null,
  243. cidName: null,
  244. cidNumber: null
  245. });
  246. App.ApplicationController = Ember.ObjectController.extend({
  247. actions: {
  248. newUser: function() {
  249. alert("ApplicationController");
  250. }
  251. }
  252. });
  253. App.callsController = Ember.ArrayController.create({
  254. content: [],
  255. init: function(){
  256. },
  257. load: function() {
  258. var me = this;
  259. $.getJSON("/txtapi/show?calls%20as%20json", function(data){
  260. // var channels = JSON.parse(data);
  261. console.log(data.row_count);
  262. me.set('total', data.row_count);
  263. me.content.clear();
  264. if (data.row_count == 0) return;
  265. // me.pushObjects(data.rows);
  266. data.rows.forEach(function(r) {
  267. me.pushObject(App.Call.create(r));
  268. });
  269. });
  270. },
  271. delete: function(uuid) {
  272. var obj = this.content.findProperty("uuid", uuid);
  273. if (obj) this.content.removeObject(obj);// else alert(uuid);
  274. },
  275. dump: function(uuid) {
  276. var obj = this.content.findProperty("uuid", uuid);
  277. console.log(obj.getProperties(["uuid", "cid_num"]));
  278. },
  279. raw: function() {
  280. $.get("/api/show?calls", function(data){
  281. $('#aa').html(data);
  282. });
  283. }
  284. });
  285. App.channelsController = Ember.ArrayController.create({
  286. content: [],
  287. listener: undefined,
  288. init: function(){
  289. },
  290. load: function() {
  291. var me = this;
  292. $.getJSON("/txtapi/show?channels%20as%20json", function(data){
  293. // var channels = JSON.parse(data);
  294. console.log(data.row_count);
  295. me.set('total', data.row_count);
  296. me.content.clear();
  297. if (data.row_count == 0) return;
  298. data.rows.forEach(function(row) {
  299. me.pushObject(App.Channel.create(row));
  300. });
  301. });
  302. },
  303. delete: function(uuid) {
  304. var obj = this.content.findProperty("uuid", uuid);
  305. if (obj) this.content.removeObject(obj);// else alert(uuid);
  306. },
  307. dump: function(uuid) {
  308. var obj = this.content.findProperty("uuid", uuid);
  309. console.log(obj.getProperties(["uuid", "cid_num"]));
  310. },
  311. checkEvent: function () { // event_sink with json is not yet support in FS
  312. console.log("check");
  313. var me = this;
  314. if (!this.get("listener")) {
  315. $.getJSON("/api/event_sink?command=create-listener&events=ALL&format=json", function(data){
  316. console.log(data);
  317. if (data.listener) {
  318. me.set("listener", data.listener["listen-id"]);
  319. }
  320. });
  321. }
  322. if (!me.get("listener")) return;
  323. $.getJSON("/api/event_sink?command=check-listener&listen-id=" +
  324. me.get("listener") + "&format=json", function(data){
  325. console.log(data);
  326. if (!data.listener) {
  327. me.set("listener", undefined);
  328. } else {
  329. data.events.forEach(function(e) {
  330. eventCallback(e);
  331. });
  332. }
  333. });
  334. },
  335. checkXMLEvent: function() {
  336. console.log("check XML Event");
  337. var me = this;
  338. if (!this.get("listener")) {
  339. $.get("/api/event_sink?command=create-listener&events=ALL", function(data){
  340. // console.log(data);
  341. var listen_id = data.getElementsByTagName("listen-id")[0];
  342. if (listen_id) {
  343. me.set("listener", listen_id.textContent);
  344. }
  345. });
  346. }
  347. if (!me.get("listener")) return;
  348. $.get("/api/event_sink?command=check-listener&listen-id=" + me.get("listener"), function(data){
  349. // console.log(data);
  350. var listener = data.getElementsByTagName("listener")[0];
  351. if (!listener) {
  352. me.set("listener", undefined);
  353. } else {
  354. var events = data.getElementsByTagName("event");
  355. for (var i=0; i<events.length; i++) {
  356. var e = {};
  357. var headers = events[i].getElementsByTagName("headers")[0];
  358. for (var j=0; j<headers.childNodes.length; j++) {
  359. e[headers.childNodes[j].nodeName] = headers.childNodes[j].textContent;
  360. }
  361. // console.log(e);
  362. eventCallback(e);
  363. }
  364. }
  365. });
  366. }
  367. });
  368. App.registrationsController = Ember.ArrayController.create({
  369. content: [],
  370. init: function(){
  371. },
  372. load: function() {
  373. var me = this;
  374. $.getJSON("/txtapi/show?registrations%20as%20json", function(data){
  375. // var channels = JSON.parse(data);
  376. console.log(data.row_count);
  377. me.set('total', data.row_count);
  378. me.content.clear();
  379. if (data.row_count == 0) return;
  380. me.pushObjects(data.rows);
  381. });
  382. }
  383. });
  384. App.applicationsController = Ember.ArrayController.create({
  385. content: [],
  386. init: function(){
  387. },
  388. load: function() {
  389. var me = this;
  390. $.getJSON("/txtapi/show?application%20as%20json", function(data){
  391. // var channels = JSON.parse(data);
  392. console.log(data.row_count);
  393. me.set('total', data.row_count);
  394. me.content.clear();
  395. if (data.row_count == 0) return;
  396. me.pushObjects(data.rows);
  397. });
  398. }
  399. });
  400. App.showEndpointsController = Ember.ArrayController.create({
  401. content: [],
  402. init: function(){
  403. },
  404. load: function() {
  405. var me = this;
  406. $.getJSON("/txtapi/show?endpoints%20as%20json", function(data){
  407. // var channels = JSON.parse(data);
  408. console.log(data.row_count);
  409. me.set('total', data.row_count);
  410. me.content.clear();
  411. if (data.row_count == 0) return;
  412. me.pushObjects(data.rows);
  413. });
  414. }
  415. });
  416. App.showCodecsController = Ember.ArrayController.create({
  417. content: [],
  418. init: function(){
  419. },
  420. load: function() {
  421. var me = this;
  422. $.getJSON("/txtapi/show?codec%20as%20json", function(data){
  423. // var channels = JSON.parse(data);
  424. console.log(data.row_count);
  425. me.set('total', data.row_count);
  426. me.content.clear();
  427. if (data.row_count == 0) return;
  428. me.pushObjects(data.rows);
  429. });
  430. }
  431. });
  432. App.showFilesController = Ember.ArrayController.create({
  433. content: [],
  434. init: function(){
  435. },
  436. load: function() {
  437. var me = this;
  438. $.getJSON("/txtapi/show?files%20as%20json", function(data){
  439. // var channels = JSON.parse(data);
  440. me.set('total', data.row_count);
  441. me.content.clear();
  442. if (data.row_count == 0) return;
  443. me.pushObjects(data.rows);
  444. });
  445. }
  446. });
  447. App.showAPIsController = Ember.ArrayController.create({
  448. content: [],
  449. init: function(){
  450. },
  451. load: function() {
  452. var me = this;
  453. $.getJSON("/txtapi/show?api%20as%20json", function(data){
  454. // var channels = JSON.parse(data);
  455. me.set('total', data.row_count);
  456. me.content.clear();
  457. if (data.row_count == 0) return;
  458. var rows = [];
  459. data.rows.forEach(function(r) {
  460. if (r.name == "show") {
  461. r.syntax = r.syntax.replace(/\|/g, "\n");
  462. } else if (r.name == "fsctl") {
  463. r.syntax = r.syntax.replace(/\]\|/g, "]\n");
  464. } else {
  465. r.syntax = r.syntax.replace(/\n/g, "\n");
  466. }
  467. // console.log(r.syntax);
  468. rows.push(r);
  469. });
  470. me.pushObjects(rows);
  471. });
  472. }
  473. });
  474. App.showModulesController = Ember.ArrayController.create({
  475. content: [],
  476. init: function(){
  477. },
  478. load: function() {
  479. var me = this;
  480. $.getJSON("/txtapi/show?module%20as%20json", function(data){
  481. me.set('total', data.row_count);
  482. me.content.clear();
  483. console.log(data);
  484. if (data.row_count == 0) return;
  485. me.pushObjects(data.rows);
  486. });
  487. }
  488. });
  489. App.showAliasesController = Ember.ArrayController.create({
  490. content: [],
  491. init: function(){
  492. },
  493. load: function() {
  494. var me = this;
  495. $.getJSON("/txtapi/show?aliases%20as%20json", function(data){
  496. me.set('total', data.row_count);
  497. me.content.clear();
  498. if (data.row_count == 0) return;
  499. me.pushObjects(data.rows);
  500. });
  501. }
  502. });
  503. App.showCompletesController = Ember.ArrayController.create({
  504. content: [],
  505. init: function(){
  506. },
  507. load: function() {
  508. var me = this;
  509. $.getJSON("/txtapi/show?complete%20as%20json", function(data){
  510. me.set('total', data.row_count);
  511. me.content.clear();
  512. if (data.row_count == 0) return;
  513. me.pushObjects(data.rows);
  514. });
  515. }
  516. });
  517. App.showManagementsController = Ember.ArrayController.create({
  518. content: [],
  519. init: function(){
  520. },
  521. load: function() {
  522. var me = this;
  523. $.getJSON("/txtapi/show?management%20as%20json", function(data){
  524. me.set('total', data.row_count);
  525. me.content.clear();
  526. if (data.row_count == 0) return;
  527. me.pushObjects(data.rows);
  528. });
  529. }
  530. });
  531. App.showNatMapsController = Ember.ArrayController.create({
  532. content: [],
  533. init: function(){
  534. },
  535. load: function() {
  536. var me = this;
  537. $.getJSON("/txtapi/show?nat_map%20as%20json", function(data){
  538. me.set('total', data.row_count);
  539. me.content.clear();
  540. if (data.row_count == 0) return;
  541. me.pushObjects(data.rows);
  542. });
  543. }
  544. });
  545. App.showSaysController = Ember.ArrayController.create({
  546. content: [],
  547. init: function(){
  548. },
  549. load: function() {
  550. var me = this;
  551. $.getJSON("/txtapi/show?say%20as%20json", function(data){
  552. me.set('total', data.row_count);
  553. me.content.clear();
  554. if (data.row_count == 0) return;
  555. me.pushObjects(data.rows);
  556. });
  557. }
  558. });
  559. App.showChatsController = Ember.ArrayController.create({
  560. content: [],
  561. init: function(){
  562. },
  563. load: function() {
  564. var me = this;
  565. $.getJSON("/txtapi/show?chat%20as%20json", function(data){
  566. me.set('total', data.row_count);
  567. me.content.clear();
  568. if (data.row_count == 0) return;
  569. me.pushObjects(data.rows);
  570. });
  571. }
  572. });
  573. App.showInterfacesController = Ember.ArrayController.create({
  574. content: [],
  575. init: function(){
  576. },
  577. load: function() {
  578. var me = this;
  579. $.getJSON("/txtapi/show?interfaces%20as%20json", function(data){
  580. me.set('total', data.row_count);
  581. me.content.clear();
  582. if (data.row_count == 0) return;
  583. me.pushObjects(data.rows);
  584. });
  585. }
  586. });
  587. App.showInterfaceTypesController = Ember.ArrayController.create({
  588. content: [],
  589. init: function(){
  590. },
  591. load: function() {
  592. var me = this;
  593. $.getJSON("/txtapi/show?interface_types%20as%20json", function(data){
  594. me.set('total', data.row_count);
  595. me.content.clear();
  596. if (data.row_count == 0) return;
  597. me.pushObjects(data.rows);
  598. });
  599. }
  600. });
  601. App.showTasksController = Ember.ArrayController.create({
  602. content: [],
  603. init: function(){
  604. },
  605. load: function() {
  606. var me = this;
  607. $.getJSON("/txtapi/show?tasks%20as%20json", function(data){
  608. me.set('total', data.row_count);
  609. me.content.clear();
  610. if (data.row_count == 0) return;
  611. me.pushObjects(data.rows);
  612. });
  613. }
  614. });
  615. App.showLimitsController = Ember.ArrayController.create({
  616. content: [],
  617. init: function(){
  618. },
  619. load: function() {
  620. var me = this;
  621. $.getJSON("/txtapi/show?limit%20as%20json", function(data){
  622. me.set('total', data.row_count);
  623. me.content.clear();
  624. if (data.row_count == 0) return;
  625. me.pushObjects(data.rows);
  626. });
  627. }
  628. });
  629. App.usersController = Ember.ArrayController.create({
  630. content: [],
  631. init: function(){
  632. },
  633. load: function() {
  634. var me = this;
  635. $.get("/txtapi/list_users", function(data){
  636. // var channels = JSON.parse(data);
  637. lines = data.split("\n");
  638. me.content.clear();
  639. var users = [];
  640. for (var i=1; i<lines.length; i++) {
  641. var line = lines[i];
  642. var fields = line.split("|");
  643. if (fields.length == 1) break;
  644. var user = {
  645. id: fields.shift(),
  646. context: fields.shift(),
  647. domain: fields.shift(),
  648. group: fields.shift(),
  649. contact: fields.shift(),
  650. callgroup: fields.shift(),
  651. cid_name: fields.shift(),
  652. cid_number: fields.shift()
  653. }
  654. // me.pushObject(App.User.create(user));
  655. users.push(App.User.create(user));
  656. }
  657. me.pushObjects(users);
  658. });
  659. }
  660. });
  661. App.UsersController = Ember.ObjectController.extend({
  662. newUserButtons: [
  663. Ember.Object.create({title: 'Create', clicked:"submit", type:"primary"}),
  664. Ember.Object.create({title: 'Cancel', clicked: "cancel", dismiss: 'modal'})
  665. ],
  666. actions: {
  667. //Submit the modal
  668. submit: function() {
  669. $.post("/txtapi/lua?portal/create_user.lua%20" + $("#user_id").val(), {
  670. data: "user_id=xxxx",
  671. success: function() { },
  672. error: function(e) { }
  673. });
  674. // Bootstrap.NM.push('Successfully submitted modal', 'success');
  675. return Bootstrap.ModalManager.hide('newUserForm');
  676. },
  677. //Cancel the modal, we don't need to hide the model manually because we set {..., dismiss: 'modal'} on the button meta data
  678. cancel: function() {
  679. Bootstrap.ModalManager.hide('newUserForm');
  680. return Bootstrap.NM.push('Modal was cancelled', 'info');
  681. },
  682. //Show the modal
  683. newUser: function() {
  684. return Bootstrap.ModalManager.show('newUserForm');
  685. }
  686. }
  687. });
  688. App.sofiaStatusController = Ember.ArrayController.create({
  689. content: [],
  690. init: function(){
  691. },
  692. load: function() {
  693. var me = this;
  694. $.get("/xmlapi/sofia?xmlstatus", function(data){
  695. console.log(data);
  696. var row_count = 0;
  697. var aliases = data.getElementsByTagName("alias");
  698. var profiles = data.getElementsByTagName("profile");
  699. var gateways = data.getElementsByTagName("gateway");
  700. me.content.clear();
  701. for (var i=0; i<aliases.length; i++) {
  702. var row = {};
  703. row.name = aliases[i].getElementsByTagName("name")[0].textContent;
  704. row.type = aliases[i].getElementsByTagName("type")[0].textContent;
  705. row.data = aliases[i].getElementsByTagName("data")[0].textContent;
  706. row.state = aliases[i].getElementsByTagName("state")[0].textContent;
  707. console.log(row)
  708. row_count++;
  709. me.pushObject(row);
  710. }
  711. for (var i=0; i<profiles.length; i++) {
  712. var row = {};
  713. row.name = profiles[i].getElementsByTagName("name")[0].textContent;
  714. row.type = profiles[i].getElementsByTagName("type")[0].textContent;
  715. row.data = profiles[i].getElementsByTagName("data")[0].textContent;
  716. row.state = profiles[i].getElementsByTagName("state")[0].textContent;
  717. row.actions = "Start | Stop | Restart | More ...";
  718. console.log(row)
  719. row_count++;
  720. me.pushObject(row);
  721. }
  722. for (var i=0; i<gateways.length; i++) {
  723. var row = {};
  724. row.name = gateways[i].getElementsByTagName("name")[0].textContent;
  725. row.type = gateways[i].getElementsByTagName("type")[0].textContent;
  726. row.data = gateways[i].getElementsByTagName("data")[0].textContent;
  727. row.state = gateways[i].getElementsByTagName("state")[0].textContent;
  728. row.actions = "Reg | UnReg | Delete";
  729. console.log(row)
  730. row_count++;
  731. me.pushObject(row);
  732. }
  733. me.set('total', row_count);
  734. });
  735. }
  736. });
  737. App.SofiaStatusController = Ember.ObjectController.extend({
  738. addGatewayButtons: [
  739. Ember.Object.create({title: 'Add', clicked:"submit", type:"primary"}),
  740. Ember.Object.create({title: 'Cancel', clicked: "cancel", dismiss: 'modal'})
  741. ],
  742. actions: {
  743. //Submit the modal
  744. submit: function() {
  745. // alert("Not implemented");
  746. // return false;
  747. url = "/txtapi/lua?portal/create_gateway.lua%20" +
  748. $("#gateway_name").val() + "%20" +
  749. $("#gateway_realm").val() + "%20" +
  750. $("#gateway_username").val() + "%20" +
  751. $("#gateway_password").val() + "%20" +
  752. $("#gateway_register").is(":checked");
  753. $.post(url, {
  754. success: function() { },
  755. error: function(e) { }
  756. });
  757. // Bootstrap.NM.push('Successfully submitted modal', 'success');
  758. return Bootstrap.ModalManager.hide('newUserForm');
  759. },
  760. //Cancel the modal, we don't need to hide the model manually because we set {..., dismiss: 'modal'} on the button meta data
  761. cancel: function() {
  762. Bootstrap.ModalManager.hide('newUserForm');
  763. return Bootstrap.NM.push('Modal was cancelled', 'info');
  764. },
  765. //Show the modal
  766. addGateway: function() {
  767. return Bootstrap.ModalManager.show('newUserForm');
  768. }
  769. }
  770. });
  771. // App.initialize();
  772. var global_debug_event = false;
  773. var global_background_job = false;
  774. function eventCallback(data) {
  775. console.log(data["Event-Name"]);
  776. if (global_debug_event ||
  777. (global_background_job && data["Event-Name"] == "BACKGROUND_JOB")) {
  778. console.log(data);
  779. }
  780. if (data["Event-Name"] == "CHANNEL_CREATE") {
  781. var channel = {
  782. uuid: data["Unique-ID"],
  783. cid_num: data["Caller-Caller-ID-Number"],
  784. dest: data["Caller-Destination-Number"],
  785. callstate: data["Channel-Call-State"],
  786. direction: data["Call-Direction"]
  787. }
  788. App.channelsController.pushObject(App.Channel.create(channel));
  789. var x = $('#auto_update_calls')[0];
  790. if (typeof x != "undefined" && x.checked) {
  791. return;
  792. }
  793. App.callsController.pushObject(App.Call.create(channel));
  794. } else if (data["Event-Name"] == "CHANNEL_HANGUP_COMPLETE") {
  795. App.channelsController.delete(data["Unique-ID"]);
  796. var x = $('#auto_update_calls')[0];
  797. if (typeof x != "undefined" && x.checked) {
  798. return;
  799. }
  800. App.callsController.delete(data["Unique-ID"]);
  801. } else if (data["Event-Name"] == "CHANNEL_BRIDGE") {
  802. var x = $('#auto_update_calls')[0];
  803. if (typeof x != "undefined" && x.checked) {
  804. return;
  805. }
  806. App.callsController.delete(data["Unique-ID"]);
  807. App.callsController.delete(data["Other-Leg-Unique-ID"]);
  808. var call = {
  809. uuid: data["Unique-ID"],
  810. b_uuid: data["Other-Leg-Unique-ID"],
  811. cid_num: data["Caller-Caller-ID-Number"],
  812. b_cid_num: data["Other-Leg-Caller-ID-Number"],
  813. dest: data["Caller-Destination-Number"],
  814. b_dest: data["Other-Leg-Destination-Number"],
  815. callstate: data["Channel-Call-State"],
  816. b_callstate: data["Channel-Call-State"],
  817. direction: data["Call-Direction"],
  818. b_direction: data["Other-Leg-Direction"],
  819. created: data["Caller-Channel-Created-Time"]
  820. };
  821. App.callsController.pushObject(App.Call.create(call));
  822. } else if (data["Event-Name"] == "CHANNEL_CALLSTATE") {
  823. var obj = App.channelsController.content.findProperty("uuid", data["Unique-ID"]);
  824. if (obj) {
  825. obj.set("callstate", data["Channel-Call-State"]);
  826. }
  827. }
  828. }
  829. // execute api
  830. function api(cmdstr)
  831. {
  832. cmdarr = cmdstr.split(" ");
  833. cmd = cmdarr.shift();
  834. arg = escape(cmdarr.join(" "));
  835. arg = arg ? "?" + arg : "";
  836. url = "/txtapi/" + cmd + arg;
  837. $.get(url, function(data){
  838. console.log(data);
  839. });
  840. return url;
  841. }
  842. //execute bgapi
  843. function bgapi(cmd)
  844. {
  845. if (!global_background_job) {
  846. socket.send("event json BACKGROUND_JOB");
  847. global_background_job = true;
  848. }
  849. api("bgapi " + cmd);
  850. }
  851. // subscribe event
  852. function event(e)
  853. {
  854. cmd = "event json " + e;
  855. socket.send(cmd);
  856. return cmd;
  857. }