/web/js/ch.js
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
- // Generated by CoffeeScript 1.7.1
- (function() {
- var Application, Cooperativa, CooperativaListView, CooperativaView, CooperativasCollection, CooperativasPagerView, FilterFormView, MapView, NoCooperativasView, NoPostsView, Post, PostView, PostsCollection, PostsFilterView, PostsLayout, PostsListView, PostsPagerView, fsConstructor, match, month_to_es, root,
- __hasProp = {}.hasOwnProperty,
- __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; },
- __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
- __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; };
- root = typeof exports !== "undefined" && exports !== null ? exports : this;
- month_to_es = function(month) {
- var months;
- months = ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Set', 'Oct', 'Nov', 'Dic'];
- return months[month - 1];
- };
- match = function(what, where) {
- if (what == null) {
- return true;
- }
- return where.toLowerCase().indexOf(what.toLowerCase()) !== -1;
- };
- Cooperativa = (function(_super) {
- __extends(Cooperativa, _super);
- function Cooperativa() {
- return Cooperativa.__super__.constructor.apply(this, arguments);
- }
- return Cooperativa;
- })(Backbone.Model);
- CooperativasCollection = (function(_super) {
- __extends(CooperativasCollection, _super);
- function CooperativasCollection() {
- return CooperativasCollection.__super__.constructor.apply(this, arguments);
- }
- CooperativasCollection.prototype.model = Cooperativa;
- CooperativasCollection.prototype.paginator_ui = {
- firstPage: 1,
- currentPage: 1,
- perPage: 6,
- totalPages: 10,
- pagesInRange: 4
- };
- CooperativasCollection.prototype.search = function(attrs) {
- return this.setFieldFilter([
- {
- field: 'school_name',
- type: 'function',
- value: function(val) {
- return match(attrs.colegio, val);
- }
- }, {
- field: 'name',
- type: 'function',
- value: function(val) {
- return match(attrs.cooperativa, val);
- }
- }, {
- field: 'activity_id',
- type: 'function',
- value: function(val) {
- return !attrs.actividad || val === attrs.actividad;
- }
- }, {
- field: 'address',
- type: 'function',
- value: function(val) {
- return match(attrs.address, val);
- }
- }, {
- field: 'level_id',
- type: 'function',
- value: function(val) {
- return !attrs.nivel || val === attrs.nivel;
- }
- }
- ]);
- };
- return CooperativasCollection;
- })(Backbone.Paginator.clientPager);
- CooperativaView = (function(_super) {
- __extends(CooperativaView, _super);
- function CooperativaView() {
- return CooperativaView.__super__.constructor.apply(this, arguments);
- }
- CooperativaView.prototype.template = "#cooperativa-list-item-template";
- CooperativaView.prototype.templateHelpers = {
- klass: function() {
- return "sponsored-" + this.sponsored;
- },
- uri: function() {
- return root.location.pathname + '/' + this.slug + '/home';
- }
- };
- return CooperativaView;
- })(Backbone.Marionette.ItemView);
- NoCooperativasView = (function(_super) {
- __extends(NoCooperativasView, _super);
- function NoCooperativasView() {
- return NoCooperativasView.__super__.constructor.apply(this, arguments);
- }
- NoCooperativasView.prototype.template = "#no-cooperativas-template";
- return NoCooperativasView;
- })(Backbone.Marionette.ItemView);
- CooperativaListView = (function(_super) {
- __extends(CooperativaListView, _super);
- function CooperativaListView() {
- return CooperativaListView.__super__.constructor.apply(this, arguments);
- }
- CooperativaListView.prototype.itemView = CooperativaView;
- CooperativaListView.prototype.emptyView = NoCooperativasView;
- return CooperativaListView;
- })(Backbone.Marionette.CollectionView);
- FilterFormView = (function(_super) {
- __extends(FilterFormView, _super);
- function FilterFormView() {
- this.onRender = __bind(this.onRender, this);
- return FilterFormView.__super__.constructor.apply(this, arguments);
- }
- FilterFormView.prototype.template = "#filter-form-template";
- FilterFormView.prototype.events = {
- 'keyup input.colegio': 'filters_changed',
- 'keyup input.cooperativa': 'filters_changed',
- 'change select.nivel': 'filters_changed',
- 'change select.actividad': 'filters_changed',
- 'keyup input.address': 'filters_changed',
- 'click button.reset': 'reset'
- };
- FilterFormView.prototype.filters_changed = function(ev) {
- ev.preventDefault();
- return this.collection.search({
- colegio: this.$('input.colegio').val(),
- cooperativa: this.$('input.cooperativa').val(),
- nivel: this.$('select.nivel').val(),
- actividad: this.$('select.actividad').val(),
- address: this.$('input.address').val()
- });
- };
- FilterFormView.prototype.reset = function(ev) {
- ev.preventDefault();
- this.$('input.colegio').val('');
- this.$('input.cooperativa').val('');
- this.$('select.nivel').val('');
- this.$('select.actividad').val('');
- this.$('input.address').val('');
- return this.collection.search({});
- };
- FilterFormView.prototype.onRender = function() {
- return this.$("input").placeholder();
- };
- return FilterFormView;
- })(Marionette.ItemView);
- CooperativasPagerView = (function(_super) {
- __extends(CooperativasPagerView, _super);
- function CooperativasPagerView() {
- return CooperativasPagerView.__super__.constructor.apply(this, arguments);
- }
- CooperativasPagerView.prototype.template = "#pager-template";
- CooperativasPagerView.prototype.events = {
- 'click a': 'clicked'
- };
- CooperativasPagerView.prototype.initialize = function() {
- return this.listenTo(this.collection, "reset", this.render, this);
- };
- CooperativasPagerView.prototype.clicked = function(ev) {
- ev.preventDefault();
- return this.collection.goTo($(ev.target).text());
- };
- CooperativasPagerView.prototype.serializeData = function() {
- return this.collection.info();
- };
- return CooperativasPagerView;
- })(Marionette.ItemView);
- MapView = (function(_super) {
- __extends(MapView, _super);
- function MapView() {
- return MapView.__super__.constructor.apply(this, arguments);
- }
- MapView.prototype.template = "#map-template";
- MapView.prototype.map = null;
- MapView.prototype.markers = [];
- MapView.prototype.initialize = function() {
- this.listenTo(this.collection, "reset", this.render, this);
- return _.each(this.collection.origModels, (function(_this) {
- return function(item, index) {
- var lat, latlng, lng, marker;
- lat = item.get('latitude');
- lng = item.get('longitude');
- latlng = new google.maps.LatLng(lat, lng);
- marker = new google.maps.Marker({
- id: item.get('id'),
- position: latlng
- });
- google.maps.event.addListener(marker, "click", function() {
- return _this.markerClicked(marker);
- });
- return _this.markers.push(marker);
- };
- })(this));
- };
- MapView.prototype.markerClicked = function(marker) {
- return this.collection.each((function(_this) {
- return function(item, index) {
- return item.set('clicked', marker.id === item.get('id'));
- };
- })(this));
- };
- MapView.prototype.drawMap = function() {
- var options;
- options = {
- mapTypeId: google.maps.MapTypeId.SATELLITE,
- zoom: 16,
- panControl: false,
- mapTypeControl: false,
- scaleControl: false,
- rotateControl: false,
- zoomControl: false,
- streetViewControl: false
- };
- this.$el.height(640);
- return this.map = new google.maps.Map(this.el, options);
- };
- MapView.prototype.render = function() {
- var bounds, ids, m, _i, _len, _ref, _ref1;
- if (!this.map) {
- this.drawMap();
- }
- bounds = new google.maps.LatLngBounds();
- ids = _.pluck(this.collection.sortedAndFilteredModels, 'id');
- _ref = this.markers;
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
- m = _ref[_i];
- if (_ref1 = m.id, __indexOf.call(ids, _ref1) >= 0) {
- bounds.extend(m.getPosition());
- m.setMap(this.map);
- } else {
- m.setMap(null);
- }
- }
- if (ids.length > 0) {
- this.map.setCenter(bounds.getCenter());
- return this.map.fitBounds(bounds);
- }
- };
- return MapView;
- })(Marionette.ItemView);
- Application = (function(_super) {
- __extends(Application, _super);
- function Application() {
- return Application.__super__.constructor.apply(this, arguments);
- }
- return Application;
- })(Backbone.Marionette.Application);
- Post = (function(_super) {
- __extends(Post, _super);
- function Post() {
- return Post.__super__.constructor.apply(this, arguments);
- }
- return Post;
- })(Backbone.Model);
- PostsCollection = (function(_super) {
- __extends(PostsCollection, _super);
- function PostsCollection() {
- return PostsCollection.__super__.constructor.apply(this, arguments);
- }
- PostsCollection.prototype.model = Post;
- PostsCollection.prototype.paginator_ui = {
- firstPage: 1,
- currentPage: 1,
- perPage: 6,
- totalPages: 10,
- pagesInRange: 4
- };
- PostsCollection.prototype.filter_per_year = function(year) {
- var field_filter;
- field_filter = {
- field: 'published_at',
- type: 'function',
- value: function(published_at) {
- return published_at.slice(0, 4) === year;
- }
- };
- return this.setFieldFilter([field_filter]);
- };
- return PostsCollection;
- })(Backbone.Paginator.clientPager);
- PostView = (function(_super) {
- __extends(PostView, _super);
- function PostView() {
- return PostView.__super__.constructor.apply(this, arguments);
- }
- PostView.prototype.template = "#post-list-item-template";
- PostView.prototype.className = "post-item";
- PostView.prototype.templateHelpers = {
- uri: function() {
- return root.location.pathname + '/' + this.slug;
- },
- year: function() {
- return this.published_at.slice(0, 4);
- },
- month: function() {
- return month_to_es(this.published_at.slice(5, 7));
- },
- day: function() {
- return this.published_at.slice(8, 10);
- }
- };
- return PostView;
- })(Backbone.Marionette.ItemView);
- NoPostsView = (function(_super) {
- __extends(NoPostsView, _super);
- function NoPostsView() {
- return NoPostsView.__super__.constructor.apply(this, arguments);
- }
- NoPostsView.prototype.template = "#no-posts-template";
- return NoPostsView;
- })(Backbone.Marionette.ItemView);
- PostsListView = (function(_super) {
- __extends(PostsListView, _super);
- function PostsListView() {
- return PostsListView.__super__.constructor.apply(this, arguments);
- }
- PostsListView.prototype.itemView = PostView;
- PostsListView.prototype.emptyView = NoPostsView;
- PostsListView.prototype.className = "row";
- return PostsListView;
- })(Backbone.Marionette.CollectionView);
- PostsFilterView = (function(_super) {
- __extends(PostsFilterView, _super);
- function PostsFilterView() {
- return PostsFilterView.__super__.constructor.apply(this, arguments);
- }
- PostsFilterView.prototype.template = "#filter-template";
- PostsFilterView.prototype.events = {
- 'change select': 'filter'
- };
- PostsFilterView.prototype.initialize = function() {
- this.years = _.uniq(this.collection.map(function(model) {
- return model.get('published_at').slice(0, 4);
- })).sort().reverse();
- return this.collection.filter_per_year(this.years[0]);
- };
- PostsFilterView.prototype.filter = function(ev) {
- return this.collection.filter_per_year($(ev.target).val());
- };
- PostsFilterView.prototype.serializeData = function() {
- return {
- years: this.years
- };
- };
- return PostsFilterView;
- })(Marionette.ItemView);
- PostsPagerView = (function(_super) {
- __extends(PostsPagerView, _super);
- function PostsPagerView() {
- return PostsPagerView.__super__.constructor.apply(this, arguments);
- }
- PostsPagerView.prototype.template = "#pager-template";
- PostsPagerView.prototype.events = {
- 'click a': 'clicked'
- };
- PostsPagerView.prototype.initialize = function() {
- return this.listenTo(this.collection, "reset", this.render, this);
- };
- PostsPagerView.prototype.clicked = function(ev) {
- ev.preventDefault();
- return this.collection.goTo($(ev.target).text());
- };
- PostsPagerView.prototype.serializeData = function() {
- return this.collection.info();
- };
- return PostsPagerView;
- })(Marionette.ItemView);
- PostsLayout = (function(_super) {
- __extends(PostsLayout, _super);
- function PostsLayout() {
- return PostsLayout.__super__.constructor.apply(this, arguments);
- }
- PostsLayout.prototype.template = "#layout-template";
- PostsLayout.prototype.className = "container contenedor-post post-anteriores";
- PostsLayout.prototype.regions = {
- filter: ".filter",
- list: ".list",
- pager: ".pager"
- };
- return PostsLayout;
- })(Backbone.Marionette.Layout);
- fsConstructor = function() {
- this.startCooperativas = function(options) {
- var cooperativas, filters, list, map, pager;
- cooperativas = new CooperativasCollection(options["cooperativas"]);
- cooperativas.bootstrap();
- list = new CooperativaListView({
- collection: cooperativas,
- el: '#container .list'
- });
- list.render();
- filters = new FilterFormView({
- collection: cooperativas,
- el: '#container .filter-form'
- });
- filters.render();
- pager = new CooperativasPagerView({
- collection: cooperativas,
- el: '#container .pager'
- });
- pager.render();
- map = new MapView({
- collection: cooperativas,
- el: '#container .map'
- });
- return map.render();
- };
- this.initializeEditor = function(options) {
- var init;
- window.CKEDITOR_BASEPATH = options.ckeditorPath;
- init = function() {
- if (window.CKEDITOR.instances[options.name]) {
- delete window.CKEDITOR.instances[options.name];
- }
- return CKEDITOR.replace(options.name, options.config);
- };
- if (typeof CKEDITOR !== "undefined" && CKEDITOR !== null) {
- return init();
- } else {
- return $.getScript(options.webPath, function() {
- return init();
- });
- }
- };
- this.startPosts = function(options) {
- var app, layout, posts;
- app = new Application;
- app.addRegions({
- mainRegion: "#container"
- });
- layout = new PostsLayout;
- app.mainRegion.show(layout);
- posts = new PostsCollection(options["posts"]);
- posts.bootstrap();
- layout.list.show(new PostsListView({
- collection: posts
- }));
- layout.pager.show(new PostsPagerView({
- collection: posts
- }));
- return app.start(options);
- };
- this.startEvents = function(options) {
- var app, layout, posts;
- app = new Application;
- app.addRegions({
- mainRegion: "#container"
- });
- layout = new PostsLayout;
- app.mainRegion.show(layout);
- posts = new PostsCollection(options["posts"]);
- posts.bootstrap();
- layout.filter.show(new PostsFilterView({
- collection: posts
- }));
- layout.list.show(new PostsListView({
- collection: posts
- }));
- layout.pager.show(new PostsPagerView({
- collection: posts
- }));
- return app.start(options);
- };
- this.startUplodify = function(options) {
- return $("#file_upload").uploadify({
- swf: "/swf/uploadify.swf",
- uploader: options["uploader"],
- buttonText: "Seleccionar Video",
- multi: false,
- fileTypeDesc: "Archivos de Video",
- fileTypeExts: "*.avi;*.mp4;*.wmv;*.mov",
- fileSizeLimit: "100MB",
- debug: false,
- onSelectError: (function(_this) {
- return function(file, errorCode, errorMsg) {
- console.log(_this, file, errorCode, errorMsg);
- switch (errorCode) {
- case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
- errorMsg += "\nThe number of files selected exceeds the remaining upload limit (" + errorMsg + ").";
- break;
- case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
- errorMsg += "\nThe file \"" + file.name + "\" exceeds the size limit (" + _this.fileSizeLimit + ").";
- break;
- case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
- errorMsg += "\nThe file \"" + file.name + "\" is empty.";
- break;
- case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
- errorMsg += "\nThe file \"" + file.name + "\" is not an accepted file type (" + fileTypeDesc + ").";
- }
- return alert(errorMsg);
- };
- })(this),
- onUploadError: function(file, errorCode, errorMsg, errorString) {
- return alert("The file " + file.name + " could not be uploaded: " + errorString);
- },
- onUploadSuccess: function(file, data, response) {
- var r;
- r = JSON.parse(data);
- console.log(file, data, response);
- return window.location = r.redirect;
- }
- });
- };
- this.enhancePostForm = function(options) {
- var checkContent, content, content_loaded, dirty;
- dirty = false;
- content = '';
- content_loaded = false;
- checkContent = setInterval(function() {
- var instance;
- if (typeof CKEDITOR !== "undefined" && CKEDITOR !== null) {
- instance = CKEDITOR.instances["" + options['prefix'] + "[content]"];
- if (content_loaded) {
- if (content !== instance.getData()) {
- dirty = true;
- return clearInterval(checkContent);
- }
- } else {
- return CKEDITOR.on('instanceReady', function() {
- content = instance.getData();
- return content_loaded = true;
- });
- }
- }
- }, 500);
- $("#a-admin-form").find("input, select, textarea").change(function(ev) {
- return dirty = true;
- });
- return $(".a-media.a-js-choose-button").click(function(ev) {
- if (dirty) {
- window.onbeforeunload = function() {
- return 'No guardč´¸ los cambios hechos en el formulario. Si abandona la pagina ahora se perderč°Šn.';
- };
- return setTimeout(function() {
- return window.onbeforeunload = null;
- }, 50);
- }
- });
- };
- this.enhanceAlerts = function(options) {
- $(".a-admin-container").removeClass("a-ui");
- $(".a-admin-content").removeClass("a-admin-content");
- return $(".alert .close").on("click", function(ev) {
- var href, that;
- ev.preventDefault();
- href = $(this).attr("href");
- that = this;
- return $.ajax({
- url: href
- }).done(function() {
- return $(that).closest(".alert").alert("close");
- }).fail(function() {
- return alert("error");
- });
- });
- };
- this.setupMap = function(options) {
- var geocoder, getPosition, map, marker, reverse_geocode, setPosition;
- reverse_geocode = function(latLng) {
- return geocoder.geocode({
- latLng: latLng
- }, function(results, status) {
- if (status === google.maps.GeocoderStatus.OK) {
- if (results[0]) {
- return $("#cooperativa_address").val(results[0].formatted_address);
- }
- }
- });
- };
- getPosition = function() {
- var lat, lng;
- lat = $("#cooperativa_latitude").val();
- lng = $("#cooperativa_longitude").val();
- return new google.maps.LatLng(lat, lng);
- };
- setPosition = function() {
- $("#cooperativa_latitude").val(marker.getPosition().lat());
- return $("#cooperativa_longitude").val(marker.getPosition().lng());
- };
- options = {
- zoom: 16,
- center: getPosition(),
- mapTypeId: google.maps.MapTypeId.SATELLITE
- };
- map = new google.maps.Map(document.getElementById("map_canvas"), options);
- geocoder = new google.maps.Geocoder();
- marker = new google.maps.Marker({
- map: map,
- draggable: true
- });
- marker.setPosition(getPosition());
- reverse_geocode(getPosition());
- $("#cooperativa_address").autocomplete({
- source: function(request, response) {
- return geocoder.geocode({
- address: request.term
- }, function(results, status) {
- return response($.map(results, function(item) {
- return {
- label: item.formatted_address,
- value: item.formatted_address,
- latitude: item.geometry.location.lat(),
- longitude: item.geometry.location.lng()
- };
- }));
- });
- },
- select: function(event, ui) {
- var location;
- location = new google.maps.LatLng(ui.item.latitude, ui.item.longitude);
- marker.setPosition(location);
- setPosition();
- return map.setCenter(location);
- }
- });
- google.maps.event.addListener(marker, "drag", function() {
- setPosition();
- return reverse_geocode(marker.getPosition());
- });
- return google.maps.event.addListener(map, "click", function(event) {
- marker.setPosition(event.latLng);
- setPosition();
- return reverse_geocode(marker.getPosition());
- });
- };
- this.enhanceSponsorFields = function(options) {};
- return this;
- };
- root.fs = new fsConstructor();
- apostrophe.debug = false;
- }).call(this);