PageRenderTime 50ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/web/js/ch.js

https://github.com/diegodorado/fundacion-sancor
JavaScript | 756 lines | 632 code | 123 blank | 1 comment | 29 complexity | feff1590d829cd221420e82336ad75e3 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, LGPL-3.0, Apache-2.0, ISC, AGPL-3.0
  1. // Generated by CoffeeScript 1.7.1
  2. (function() {
  3. var Application, Cooperativa, CooperativaListView, CooperativaView, CooperativasCollection, CooperativasPagerView, FilterFormView, MapView, NoCooperativasView, NoPostsView, Post, PostView, PostsCollection, PostsFilterView, PostsLayout, PostsListView, PostsPagerView, fsConstructor, match, month_to_es, root,
  4. __hasProp = {}.hasOwnProperty,
  5. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  6. __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  7. __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
  8. root = typeof exports !== "undefined" && exports !== null ? exports : this;
  9. month_to_es = function(month) {
  10. var months;
  11. months = ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Set', 'Oct', 'Nov', 'Dic'];
  12. return months[month - 1];
  13. };
  14. match = function(what, where) {
  15. if (what == null) {
  16. return true;
  17. }
  18. return where.toLowerCase().indexOf(what.toLowerCase()) !== -1;
  19. };
  20. Cooperativa = (function(_super) {
  21. __extends(Cooperativa, _super);
  22. function Cooperativa() {
  23. return Cooperativa.__super__.constructor.apply(this, arguments);
  24. }
  25. return Cooperativa;
  26. })(Backbone.Model);
  27. CooperativasCollection = (function(_super) {
  28. __extends(CooperativasCollection, _super);
  29. function CooperativasCollection() {
  30. return CooperativasCollection.__super__.constructor.apply(this, arguments);
  31. }
  32. CooperativasCollection.prototype.model = Cooperativa;
  33. CooperativasCollection.prototype.paginator_ui = {
  34. firstPage: 1,
  35. currentPage: 1,
  36. perPage: 6,
  37. totalPages: 10,
  38. pagesInRange: 4
  39. };
  40. CooperativasCollection.prototype.search = function(attrs) {
  41. return this.setFieldFilter([
  42. {
  43. field: 'school_name',
  44. type: 'function',
  45. value: function(val) {
  46. return match(attrs.colegio, val);
  47. }
  48. }, {
  49. field: 'name',
  50. type: 'function',
  51. value: function(val) {
  52. return match(attrs.cooperativa, val);
  53. }
  54. }, {
  55. field: 'activity_id',
  56. type: 'function',
  57. value: function(val) {
  58. return !attrs.actividad || val === attrs.actividad;
  59. }
  60. }, {
  61. field: 'address',
  62. type: 'function',
  63. value: function(val) {
  64. return match(attrs.address, val);
  65. }
  66. }, {
  67. field: 'level_id',
  68. type: 'function',
  69. value: function(val) {
  70. return !attrs.nivel || val === attrs.nivel;
  71. }
  72. }
  73. ]);
  74. };
  75. return CooperativasCollection;
  76. })(Backbone.Paginator.clientPager);
  77. CooperativaView = (function(_super) {
  78. __extends(CooperativaView, _super);
  79. function CooperativaView() {
  80. return CooperativaView.__super__.constructor.apply(this, arguments);
  81. }
  82. CooperativaView.prototype.template = "#cooperativa-list-item-template";
  83. CooperativaView.prototype.templateHelpers = {
  84. klass: function() {
  85. return "sponsored-" + this.sponsored;
  86. },
  87. uri: function() {
  88. return root.location.pathname + '/' + this.slug + '/home';
  89. }
  90. };
  91. return CooperativaView;
  92. })(Backbone.Marionette.ItemView);
  93. NoCooperativasView = (function(_super) {
  94. __extends(NoCooperativasView, _super);
  95. function NoCooperativasView() {
  96. return NoCooperativasView.__super__.constructor.apply(this, arguments);
  97. }
  98. NoCooperativasView.prototype.template = "#no-cooperativas-template";
  99. return NoCooperativasView;
  100. })(Backbone.Marionette.ItemView);
  101. CooperativaListView = (function(_super) {
  102. __extends(CooperativaListView, _super);
  103. function CooperativaListView() {
  104. return CooperativaListView.__super__.constructor.apply(this, arguments);
  105. }
  106. CooperativaListView.prototype.itemView = CooperativaView;
  107. CooperativaListView.prototype.emptyView = NoCooperativasView;
  108. return CooperativaListView;
  109. })(Backbone.Marionette.CollectionView);
  110. FilterFormView = (function(_super) {
  111. __extends(FilterFormView, _super);
  112. function FilterFormView() {
  113. this.onRender = __bind(this.onRender, this);
  114. return FilterFormView.__super__.constructor.apply(this, arguments);
  115. }
  116. FilterFormView.prototype.template = "#filter-form-template";
  117. FilterFormView.prototype.events = {
  118. 'keyup input.colegio': 'filters_changed',
  119. 'keyup input.cooperativa': 'filters_changed',
  120. 'change select.nivel': 'filters_changed',
  121. 'change select.actividad': 'filters_changed',
  122. 'keyup input.address': 'filters_changed',
  123. 'click button.reset': 'reset'
  124. };
  125. FilterFormView.prototype.filters_changed = function(ev) {
  126. ev.preventDefault();
  127. return this.collection.search({
  128. colegio: this.$('input.colegio').val(),
  129. cooperativa: this.$('input.cooperativa').val(),
  130. nivel: this.$('select.nivel').val(),
  131. actividad: this.$('select.actividad').val(),
  132. address: this.$('input.address').val()
  133. });
  134. };
  135. FilterFormView.prototype.reset = function(ev) {
  136. ev.preventDefault();
  137. this.$('input.colegio').val('');
  138. this.$('input.cooperativa').val('');
  139. this.$('select.nivel').val('');
  140. this.$('select.actividad').val('');
  141. this.$('input.address').val('');
  142. return this.collection.search({});
  143. };
  144. FilterFormView.prototype.onRender = function() {
  145. return this.$("input").placeholder();
  146. };
  147. return FilterFormView;
  148. })(Marionette.ItemView);
  149. CooperativasPagerView = (function(_super) {
  150. __extends(CooperativasPagerView, _super);
  151. function CooperativasPagerView() {
  152. return CooperativasPagerView.__super__.constructor.apply(this, arguments);
  153. }
  154. CooperativasPagerView.prototype.template = "#pager-template";
  155. CooperativasPagerView.prototype.events = {
  156. 'click a': 'clicked'
  157. };
  158. CooperativasPagerView.prototype.initialize = function() {
  159. return this.listenTo(this.collection, "reset", this.render, this);
  160. };
  161. CooperativasPagerView.prototype.clicked = function(ev) {
  162. ev.preventDefault();
  163. return this.collection.goTo($(ev.target).text());
  164. };
  165. CooperativasPagerView.prototype.serializeData = function() {
  166. return this.collection.info();
  167. };
  168. return CooperativasPagerView;
  169. })(Marionette.ItemView);
  170. MapView = (function(_super) {
  171. __extends(MapView, _super);
  172. function MapView() {
  173. return MapView.__super__.constructor.apply(this, arguments);
  174. }
  175. MapView.prototype.template = "#map-template";
  176. MapView.prototype.map = null;
  177. MapView.prototype.markers = [];
  178. MapView.prototype.initialize = function() {
  179. this.listenTo(this.collection, "reset", this.render, this);
  180. return _.each(this.collection.origModels, (function(_this) {
  181. return function(item, index) {
  182. var lat, latlng, lng, marker;
  183. lat = item.get('latitude');
  184. lng = item.get('longitude');
  185. latlng = new google.maps.LatLng(lat, lng);
  186. marker = new google.maps.Marker({
  187. id: item.get('id'),
  188. position: latlng
  189. });
  190. google.maps.event.addListener(marker, "click", function() {
  191. return _this.markerClicked(marker);
  192. });
  193. return _this.markers.push(marker);
  194. };
  195. })(this));
  196. };
  197. MapView.prototype.markerClicked = function(marker) {
  198. return this.collection.each((function(_this) {
  199. return function(item, index) {
  200. return item.set('clicked', marker.id === item.get('id'));
  201. };
  202. })(this));
  203. };
  204. MapView.prototype.drawMap = function() {
  205. var options;
  206. options = {
  207. mapTypeId: google.maps.MapTypeId.SATELLITE,
  208. zoom: 16,
  209. panControl: false,
  210. mapTypeControl: false,
  211. scaleControl: false,
  212. rotateControl: false,
  213. zoomControl: false,
  214. streetViewControl: false
  215. };
  216. this.$el.height(640);
  217. return this.map = new google.maps.Map(this.el, options);
  218. };
  219. MapView.prototype.render = function() {
  220. var bounds, ids, m, _i, _len, _ref, _ref1;
  221. if (!this.map) {
  222. this.drawMap();
  223. }
  224. bounds = new google.maps.LatLngBounds();
  225. ids = _.pluck(this.collection.sortedAndFilteredModels, 'id');
  226. _ref = this.markers;
  227. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  228. m = _ref[_i];
  229. if (_ref1 = m.id, __indexOf.call(ids, _ref1) >= 0) {
  230. bounds.extend(m.getPosition());
  231. m.setMap(this.map);
  232. } else {
  233. m.setMap(null);
  234. }
  235. }
  236. if (ids.length > 0) {
  237. this.map.setCenter(bounds.getCenter());
  238. return this.map.fitBounds(bounds);
  239. }
  240. };
  241. return MapView;
  242. })(Marionette.ItemView);
  243. Application = (function(_super) {
  244. __extends(Application, _super);
  245. function Application() {
  246. return Application.__super__.constructor.apply(this, arguments);
  247. }
  248. return Application;
  249. })(Backbone.Marionette.Application);
  250. Post = (function(_super) {
  251. __extends(Post, _super);
  252. function Post() {
  253. return Post.__super__.constructor.apply(this, arguments);
  254. }
  255. return Post;
  256. })(Backbone.Model);
  257. PostsCollection = (function(_super) {
  258. __extends(PostsCollection, _super);
  259. function PostsCollection() {
  260. return PostsCollection.__super__.constructor.apply(this, arguments);
  261. }
  262. PostsCollection.prototype.model = Post;
  263. PostsCollection.prototype.paginator_ui = {
  264. firstPage: 1,
  265. currentPage: 1,
  266. perPage: 6,
  267. totalPages: 10,
  268. pagesInRange: 4
  269. };
  270. PostsCollection.prototype.filter_per_year = function(year) {
  271. var field_filter;
  272. field_filter = {
  273. field: 'published_at',
  274. type: 'function',
  275. value: function(published_at) {
  276. return published_at.slice(0, 4) === year;
  277. }
  278. };
  279. return this.setFieldFilter([field_filter]);
  280. };
  281. return PostsCollection;
  282. })(Backbone.Paginator.clientPager);
  283. PostView = (function(_super) {
  284. __extends(PostView, _super);
  285. function PostView() {
  286. return PostView.__super__.constructor.apply(this, arguments);
  287. }
  288. PostView.prototype.template = "#post-list-item-template";
  289. PostView.prototype.className = "post-item";
  290. PostView.prototype.templateHelpers = {
  291. uri: function() {
  292. return root.location.pathname + '/' + this.slug;
  293. },
  294. year: function() {
  295. return this.published_at.slice(0, 4);
  296. },
  297. month: function() {
  298. return month_to_es(this.published_at.slice(5, 7));
  299. },
  300. day: function() {
  301. return this.published_at.slice(8, 10);
  302. }
  303. };
  304. return PostView;
  305. })(Backbone.Marionette.ItemView);
  306. NoPostsView = (function(_super) {
  307. __extends(NoPostsView, _super);
  308. function NoPostsView() {
  309. return NoPostsView.__super__.constructor.apply(this, arguments);
  310. }
  311. NoPostsView.prototype.template = "#no-posts-template";
  312. return NoPostsView;
  313. })(Backbone.Marionette.ItemView);
  314. PostsListView = (function(_super) {
  315. __extends(PostsListView, _super);
  316. function PostsListView() {
  317. return PostsListView.__super__.constructor.apply(this, arguments);
  318. }
  319. PostsListView.prototype.itemView = PostView;
  320. PostsListView.prototype.emptyView = NoPostsView;
  321. PostsListView.prototype.className = "row";
  322. return PostsListView;
  323. })(Backbone.Marionette.CollectionView);
  324. PostsFilterView = (function(_super) {
  325. __extends(PostsFilterView, _super);
  326. function PostsFilterView() {
  327. return PostsFilterView.__super__.constructor.apply(this, arguments);
  328. }
  329. PostsFilterView.prototype.template = "#filter-template";
  330. PostsFilterView.prototype.events = {
  331. 'change select': 'filter'
  332. };
  333. PostsFilterView.prototype.initialize = function() {
  334. this.years = _.uniq(this.collection.map(function(model) {
  335. return model.get('published_at').slice(0, 4);
  336. })).sort().reverse();
  337. return this.collection.filter_per_year(this.years[0]);
  338. };
  339. PostsFilterView.prototype.filter = function(ev) {
  340. return this.collection.filter_per_year($(ev.target).val());
  341. };
  342. PostsFilterView.prototype.serializeData = function() {
  343. return {
  344. years: this.years
  345. };
  346. };
  347. return PostsFilterView;
  348. })(Marionette.ItemView);
  349. PostsPagerView = (function(_super) {
  350. __extends(PostsPagerView, _super);
  351. function PostsPagerView() {
  352. return PostsPagerView.__super__.constructor.apply(this, arguments);
  353. }
  354. PostsPagerView.prototype.template = "#pager-template";
  355. PostsPagerView.prototype.events = {
  356. 'click a': 'clicked'
  357. };
  358. PostsPagerView.prototype.initialize = function() {
  359. return this.listenTo(this.collection, "reset", this.render, this);
  360. };
  361. PostsPagerView.prototype.clicked = function(ev) {
  362. ev.preventDefault();
  363. return this.collection.goTo($(ev.target).text());
  364. };
  365. PostsPagerView.prototype.serializeData = function() {
  366. return this.collection.info();
  367. };
  368. return PostsPagerView;
  369. })(Marionette.ItemView);
  370. PostsLayout = (function(_super) {
  371. __extends(PostsLayout, _super);
  372. function PostsLayout() {
  373. return PostsLayout.__super__.constructor.apply(this, arguments);
  374. }
  375. PostsLayout.prototype.template = "#layout-template";
  376. PostsLayout.prototype.className = "container contenedor-post post-anteriores";
  377. PostsLayout.prototype.regions = {
  378. filter: ".filter",
  379. list: ".list",
  380. pager: ".pager"
  381. };
  382. return PostsLayout;
  383. })(Backbone.Marionette.Layout);
  384. fsConstructor = function() {
  385. this.startCooperativas = function(options) {
  386. var cooperativas, filters, list, map, pager;
  387. cooperativas = new CooperativasCollection(options["cooperativas"]);
  388. cooperativas.bootstrap();
  389. list = new CooperativaListView({
  390. collection: cooperativas,
  391. el: '#container .list'
  392. });
  393. list.render();
  394. filters = new FilterFormView({
  395. collection: cooperativas,
  396. el: '#container .filter-form'
  397. });
  398. filters.render();
  399. pager = new CooperativasPagerView({
  400. collection: cooperativas,
  401. el: '#container .pager'
  402. });
  403. pager.render();
  404. map = new MapView({
  405. collection: cooperativas,
  406. el: '#container .map'
  407. });
  408. return map.render();
  409. };
  410. this.initializeEditor = function(options) {
  411. var init;
  412. window.CKEDITOR_BASEPATH = options.ckeditorPath;
  413. init = function() {
  414. if (window.CKEDITOR.instances[options.name]) {
  415. delete window.CKEDITOR.instances[options.name];
  416. }
  417. return CKEDITOR.replace(options.name, options.config);
  418. };
  419. if (typeof CKEDITOR !== "undefined" && CKEDITOR !== null) {
  420. return init();
  421. } else {
  422. return $.getScript(options.webPath, function() {
  423. return init();
  424. });
  425. }
  426. };
  427. this.startPosts = function(options) {
  428. var app, layout, posts;
  429. app = new Application;
  430. app.addRegions({
  431. mainRegion: "#container"
  432. });
  433. layout = new PostsLayout;
  434. app.mainRegion.show(layout);
  435. posts = new PostsCollection(options["posts"]);
  436. posts.bootstrap();
  437. layout.list.show(new PostsListView({
  438. collection: posts
  439. }));
  440. layout.pager.show(new PostsPagerView({
  441. collection: posts
  442. }));
  443. return app.start(options);
  444. };
  445. this.startEvents = function(options) {
  446. var app, layout, posts;
  447. app = new Application;
  448. app.addRegions({
  449. mainRegion: "#container"
  450. });
  451. layout = new PostsLayout;
  452. app.mainRegion.show(layout);
  453. posts = new PostsCollection(options["posts"]);
  454. posts.bootstrap();
  455. layout.filter.show(new PostsFilterView({
  456. collection: posts
  457. }));
  458. layout.list.show(new PostsListView({
  459. collection: posts
  460. }));
  461. layout.pager.show(new PostsPagerView({
  462. collection: posts
  463. }));
  464. return app.start(options);
  465. };
  466. this.startUplodify = function(options) {
  467. return $("#file_upload").uploadify({
  468. swf: "/swf/uploadify.swf",
  469. uploader: options["uploader"],
  470. buttonText: "Seleccionar Video",
  471. multi: false,
  472. fileTypeDesc: "Archivos de Video",
  473. fileTypeExts: "*.avi;*.mp4;*.wmv;*.mov",
  474. fileSizeLimit: "100MB",
  475. debug: false,
  476. onSelectError: (function(_this) {
  477. return function(file, errorCode, errorMsg) {
  478. console.log(_this, file, errorCode, errorMsg);
  479. switch (errorCode) {
  480. case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
  481. errorMsg += "\nThe number of files selected exceeds the remaining upload limit (" + errorMsg + ").";
  482. break;
  483. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  484. errorMsg += "\nThe file \"" + file.name + "\" exceeds the size limit (" + _this.fileSizeLimit + ").";
  485. break;
  486. case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
  487. errorMsg += "\nThe file \"" + file.name + "\" is empty.";
  488. break;
  489. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  490. errorMsg += "\nThe file \"" + file.name + "\" is not an accepted file type (" + fileTypeDesc + ").";
  491. }
  492. return alert(errorMsg);
  493. };
  494. })(this),
  495. onUploadError: function(file, errorCode, errorMsg, errorString) {
  496. return alert("The file " + file.name + " could not be uploaded: " + errorString);
  497. },
  498. onUploadSuccess: function(file, data, response) {
  499. var r;
  500. r = JSON.parse(data);
  501. console.log(file, data, response);
  502. return window.location = r.redirect;
  503. }
  504. });
  505. };
  506. this.enhancePostForm = function(options) {
  507. var checkContent, content, content_loaded, dirty;
  508. dirty = false;
  509. content = '';
  510. content_loaded = false;
  511. checkContent = setInterval(function() {
  512. var instance;
  513. if (typeof CKEDITOR !== "undefined" && CKEDITOR !== null) {
  514. instance = CKEDITOR.instances["" + options['prefix'] + "[content]"];
  515. if (content_loaded) {
  516. if (content !== instance.getData()) {
  517. dirty = true;
  518. return clearInterval(checkContent);
  519. }
  520. } else {
  521. return CKEDITOR.on('instanceReady', function() {
  522. content = instance.getData();
  523. return content_loaded = true;
  524. });
  525. }
  526. }
  527. }, 500);
  528. $("#a-admin-form").find("input, select, textarea").change(function(ev) {
  529. return dirty = true;
  530. });
  531. return $(".a-media.a-js-choose-button").click(function(ev) {
  532. if (dirty) {
  533. window.onbeforeunload = function() {
  534. return 'No guardč´¸ los cambios hechos en el formulario. Si abandona la pagina ahora se perderč°Šn.';
  535. };
  536. return setTimeout(function() {
  537. return window.onbeforeunload = null;
  538. }, 50);
  539. }
  540. });
  541. };
  542. this.enhanceAlerts = function(options) {
  543. $(".a-admin-container").removeClass("a-ui");
  544. $(".a-admin-content").removeClass("a-admin-content");
  545. return $(".alert .close").on("click", function(ev) {
  546. var href, that;
  547. ev.preventDefault();
  548. href = $(this).attr("href");
  549. that = this;
  550. return $.ajax({
  551. url: href
  552. }).done(function() {
  553. return $(that).closest(".alert").alert("close");
  554. }).fail(function() {
  555. return alert("error");
  556. });
  557. });
  558. };
  559. this.setupMap = function(options) {
  560. var geocoder, getPosition, map, marker, reverse_geocode, setPosition;
  561. reverse_geocode = function(latLng) {
  562. return geocoder.geocode({
  563. latLng: latLng
  564. }, function(results, status) {
  565. if (status === google.maps.GeocoderStatus.OK) {
  566. if (results[0]) {
  567. return $("#cooperativa_address").val(results[0].formatted_address);
  568. }
  569. }
  570. });
  571. };
  572. getPosition = function() {
  573. var lat, lng;
  574. lat = $("#cooperativa_latitude").val();
  575. lng = $("#cooperativa_longitude").val();
  576. return new google.maps.LatLng(lat, lng);
  577. };
  578. setPosition = function() {
  579. $("#cooperativa_latitude").val(marker.getPosition().lat());
  580. return $("#cooperativa_longitude").val(marker.getPosition().lng());
  581. };
  582. options = {
  583. zoom: 16,
  584. center: getPosition(),
  585. mapTypeId: google.maps.MapTypeId.SATELLITE
  586. };
  587. map = new google.maps.Map(document.getElementById("map_canvas"), options);
  588. geocoder = new google.maps.Geocoder();
  589. marker = new google.maps.Marker({
  590. map: map,
  591. draggable: true
  592. });
  593. marker.setPosition(getPosition());
  594. reverse_geocode(getPosition());
  595. $("#cooperativa_address").autocomplete({
  596. source: function(request, response) {
  597. return geocoder.geocode({
  598. address: request.term
  599. }, function(results, status) {
  600. return response($.map(results, function(item) {
  601. return {
  602. label: item.formatted_address,
  603. value: item.formatted_address,
  604. latitude: item.geometry.location.lat(),
  605. longitude: item.geometry.location.lng()
  606. };
  607. }));
  608. });
  609. },
  610. select: function(event, ui) {
  611. var location;
  612. location = new google.maps.LatLng(ui.item.latitude, ui.item.longitude);
  613. marker.setPosition(location);
  614. setPosition();
  615. return map.setCenter(location);
  616. }
  617. });
  618. google.maps.event.addListener(marker, "drag", function() {
  619. setPosition();
  620. return reverse_geocode(marker.getPosition());
  621. });
  622. return google.maps.event.addListener(map, "click", function(event) {
  623. marker.setPosition(event.latLng);
  624. setPosition();
  625. return reverse_geocode(marker.getPosition());
  626. });
  627. };
  628. this.enhanceSponsorFields = function(options) {};
  629. return this;
  630. };
  631. root.fs = new fsConstructor();
  632. apostrophe.debug = false;
  633. }).call(this);