Skip to content
Browse files

Key Filter implementiert

  • Loading branch information...
1 parent af956f9 commit ea38a708ae3c3b7758aa50abbcc43dbc41af3c73 Stephan committed Dec 10, 2012
View
51 app/modules/localeEdit/views.js
@@ -65,33 +65,27 @@ function(app, LocaleEdit, Backbone) {
this.currentPage = page;
this.render();
-
- $('#SelElementsPerPage option:selected').removeAttr('selected');
+ $('#SelElementsPerPage option:selected').removeAttr('selected');
var currentSelected = this.elementsPerPage;
$("#SelElementsPerPage option").filter(function() {
return $(this).val() == currentSelected;
}).attr('selected', true);
$('#SelElementsPerPage').val(this.elementsPerPage);
},
- keyCountChanged: function(count){
- this.keyCount = count;
- this.render();
- },
data: function() {
return {
currentpage: this.currentPage,
- elementsPerPage: this.elementsPerPage,
- keyCount : this.keyCount
+ elementsPerPage: this.elementsPerPage
};
},
initialize: function(){
this.currentPage = 1;
+
this.elementsPerPage = 5;
- this.keyCountChanged = 0;
+ console.log('filter view elementsPerPage : ' + this.elementsPerPage);
mediator.Subscribe('pageChanged', this.pageChanged, {}, this)
- mediator.Subscribe('localeKeyCountChanged', this.keyCountChanged, {}, this)
-
+
},
template: 'app/templates/localeedit/filter',
manage: true
@@ -111,6 +105,8 @@ function(app, LocaleEdit, Backbone) {
translationChanged: function(ev) {
this.model.Value = $(ev.target).val();
this.render();
+ mediator.Publish('modelChanged', this.model);
+
},
@@ -136,10 +132,11 @@ function(app, LocaleEdit, Backbone) {
beforeRender: function() {
var items = this.model.get('LocaleValues');
-
for (var i = 0; i < items.length; i++) {
+ items[i].Key = this.model.get('LocaleKey');
this.insertView("ul.locales", new Views.EditKeyValueItem({
model: items[i]
+
}));
}
@@ -172,7 +169,8 @@ Views.EditList = Backbone.View.extend({
},
save: function() {
//localStorage.setItem(this.name, JSON.stringify(this.data));
- LocaleEdit.SaveLocales(this.collection);
+ var collToUse = this.wholeCollecxtion || this.collection;
+ LocaleEdit.SaveLocales(collToUse);
},
renderList : function(filteredCollection){
@@ -189,7 +187,7 @@ Views.EditList = Backbone.View.extend({
var count = 0;
var start = (this.currentPage * this.pageSize) - this.pageSize;
var index = 0;
-
+ console.log('rendering with page size :' + this.pageSize);
this.collection.each(function(locale) {
index +=1;
@@ -236,10 +234,27 @@ Views.EditList = Backbone.View.extend({
this.goToPage(Math.round(this.collection.length / this.pageSize) +1 );
},
changeElementsPerPage:function(pageSize){
-
+ console.log('setting page size to:' + Number(pageSize));
this.pageSize = Number(pageSize);
this.render();
},
+ syncFilteredWithWholeCollection: function(model){
+
+ for (var obj in this.wholeCollecxtion.models) {
+
+ var currentModel = this.wholeCollecxtion.models[obj];
+
+ if(this.wholeCollecxtion.models[obj].attributes.LocaleKey === model.Key ){
+ for (var langv in this.wholeCollecxtion.models[obj].attributes.LocaleValues) {
+
+ if(this.wholeCollecxtion.models[obj].attributes.LocaleValues[langv].Language === model.Language ){
+ this.wholeCollecxtion.models[obj].attributes.LocaleValues[langv].Value = model.Value;
+ }
+ }
+ }
+ }
+
+ },
initialize: function() {
this.collection.on("reset", this.render, this);
mediator.Subscribe('keySearch', this.search, {}, this);
@@ -249,12 +264,8 @@ Views.EditList = Backbone.View.extend({
mediator.Subscribe('goToStart', this.goToStart, {}, this);
mediator.Subscribe('goToEnd', this.goToEnd, {}, this) ;
mediator.Subscribe('elementsPerPageCHanged', this.changeElementsPerPage, {}, this);
+ mediator.Subscribe('modelChanged', this.syncFilteredWithWholeCollection, {}, this);
- this.collection.on("reset", function(){
- mediator.Publish('localeKeyCountChanged', this.collection.length);
- }, this);
-
-
this.pageSize = 5;
this.currentPage = 1;
}
View
277 app/modules/localeEdit/views.js.BACKUP.3952.js
@@ -0,0 +1,277 @@
+define([
+ 'app',
+ 'LocaleEdit',
+ 'backbone',
+ 'Mediator'
+],
+
+function(app, LocaleEdit, Backbone) {
+
+ var Views = {};
+ var mediator = new Mediator();
+
+ Views.Upload = Backbone.View.extend({
+ template: 'app/templates/localeedit/upload',
+ tagName: 'div',
+ manage: true
+ });
+
+ Views.Overview = Backbone.View.extend({
+ template: 'app/templates/localeedit/overview',
+ manage: true
+ });
+
+ Views.EditFilter = Backbone.View.extend({
+ events: {
+ "keyup #keySearchTask" : "KeySearch",
+ "click #nextPage" : "NextPage",
+ "click #prevPage" : "PrevPage",
+ "click #gotoStart" : "goToStart",
+ "click #gotoEnd" : "goToEnd",
+ "change #SelElementsPerPage" : "changeElementsPerPage"
+ },
+
+ goToStart: function(e){
+ mediator.Publish('goToStart');
+ return this;
+ },
+
+ goToEnd: function(e){
+ mediator.Publish('goToEnd');
+ return this;
+ },
+ changeElementsPerPage: function(){
+
+ var elementsPerPage = $("#SelElementsPerPage").val();
+ this.elementsPerPage = elementsPerPage;
+ mediator.Publish('elementsPerPageCHanged', elementsPerPage);
+ return this;
+ },
+ NextPage: function(e){
+ mediator.Publish('nextpage');
+ return this;
+ },
+ PrevPage: function(e){
+ mediator.Publish('prevpage');
+ return this;
+ },
+
+ KeySearch: function(e){
+ var keySearchterm = $("#keySearchTask").val();
+ mediator.Publish('keySearch', keySearchterm);
+ return this;
+ },
+ pageChanged : function(page){
+ this.currentPage = page;
+
+ this.render();
+
+ $('#SelElementsPerPage option:selected').removeAttr('selected');
+ var currentSelected = this.elementsPerPage;
+ $("#SelElementsPerPage option").filter(function() {
+ return $(this).val() == currentSelected;
+ }).attr('selected', true);
+
+ $('#SelElementsPerPage').val(this.elementsPerPage);
+ },
+ keyCountChanged: function(count){
+ this.keyCount = count;
+ this.render();
+ },
+ data: function() {
+ return {
+ currentpage: this.currentPage,
+ elementsPerPage: this.elementsPerPage,
+ keyCount : this.keyCount
+ };
+ },
+ initialize: function(){
+ this.currentPage = 1;
+ this.elementsPerPage = 5;
+ this.keyCountChanged = 0;
+ mediator.Subscribe('pageChanged', this.pageChanged, {}, this)
+ mediator.Subscribe('localeKeyCountChanged', this.keyCountChanged, {}, this)
+
+ },
+ template: 'app/templates/localeedit/filter',
+ manage: true
+ });
+
+ Views.EditKeyValueItem = Backbone.View.extend({
+ template: 'app/templates/localeedit/editKeyValueItem',
+ manage: true,
+
+ tagName: "li",
+ className: 'edititem ',
+
+ events: {
+ "change input.translation": "translationChanged"
+ },
+
+ translationChanged: function(ev) {
+ this.model.Value = $(ev.target).val();
+ this.render();
+ mediator.Publish('modelChanged', this.model);
+ },
+
+
+ data: function() {
+ return { model: this.model };
+ }
+
+ });
+
+
+ Views.EditItem = Backbone.View.extend({
+ template: 'app/templates/localeedit/editItem',
+ manage: true,
+
+ tagName: "div",
+ className: 'edit-wrapper-outer',
+
+ data: function() {
+ return { model: this.model,
+ index: this.model.index };
+ },
+
+
+ beforeRender: function() {
+ var items = this.model.get('LocaleValues');
+
+ for (var i = 0; i < items.length; i++) {
+ this.insertView("ul.locales", new Views.EditKeyValueItem({
+ model: items[i]
+ }));
+ }
+
+ }
+
+ });
+
+Views.EditList = Backbone.View.extend({
+ template: 'app/templates/localeedit/edit',
+ //tagName: 'div',
+ manage: true,
+ className: 'container',
+
+ data: function() {
+ return {
+ count: this.collection.length,
+ currentpage: this.currentPage
+ };
+ },
+
+ events: {
+ "click #SaveBtn" : "save",
+ "click #ResetBtn" : "reload"
+ //,
+ //"change #taskSorting":"sorts"
+ },
+ keySearch: function(term){
+ var collToUse = this.wholeCollecxtion || this.collection;
+ this.renderList(collToUse.search(term));
+ },
+ save: function() {
+ //localStorage.setItem(this.name, JSON.stringify(this.data));
+ LocaleEdit.SaveLocales(this.collection);
+ },
+ renderList : function(filteredCollection){
+
+ if(this.wholeCollecxtion === undefined)
+ {
+ this.wholeCollecxtion = this.collection;
+ };
+ this.collection = filteredCollection;
+ this.render();
+ },
+
+ beforeRender: function() {
+
+ var count = 0;
+ var start = (this.currentPage * this.pageSize) - this.pageSize;
+ var index = 0;
+
+ this.collection.each(function(locale) {
+ index +=1;
+
+ if(index > start && count < this.pageSize ) {
+ count +=1;
+ locale.index = index;
+ this.insertView("div.localelistitems", new Views.EditItem({
+ model: locale
+ }));
+ }
+ }, this);
+ },
+
+ cleanup: function() {
+ //this.collection.off(null, null, this);
+ },
+ reload: function(){
+ this.collection.reset();
+ this.collection.fetch();
+ this.goToPage(1);
+ },
+ goToPage: function(page) {
+ this.currentPage = page;
+ mediator.Publish('pageChanged', this.currentPage);
+ this.render();
+ },
+ prevPage: function(){
+ if(this.currentPage == 0 ) {
+ return;
+ };
+ this.goToPage(this.currentPage -= 1);
+ },
+ nextPage: function(){
+ if( (this.currentPage + 1) > (Math.round(this.collection.length / this.pageSize) +1) )
+ {
+ return;
+ }
+ this.goToPage(this.currentPage += 1);
+ },
+ goToStart: function(){
+ this.goToPage(1);
+ },
+ goToEnd: function(){
+ this.goToPage(Math.round(this.collection.length / this.pageSize) +1 );
+ },
+ changeElementsPerPage:function(pageSize){
+
+ this.pageSize = Number(pageSize);
+ this.render();
+ },
+ syncFilteredWithWholeCollection: function(model){
+ console.log(model);
+ },
+ initialize: function() {
+ this.collection.on("reset", this.render, this);
+
+ mediator.Subscribe('keySearch', this.keySearch, {}, this);
+ mediator.Subscribe('nextpage', this.nextPage, {}, this);
+ mediator.Subscribe('prevpage', this.prevPage, {}, this) ;
+
+ mediator.Subscribe('goToStart', this.goToStart, {}, this);
+ mediator.Subscribe('goToEnd', this.goToEnd, {}, this) ;
+ mediator.Subscribe('elementsPerPageCHanged', this.changeElementsPerPage, {}, this);
+ mediator.Subscribe('modelChanged', this.syncFilteredWithWholeCollection, {}, this);
+
+<<<<<<< Updated upstream
+ this.collection.on("reset", function(){
+ mediator.Publish('localeKeyCountChanged', this.collection.length);
+ }, this);
+
+=======
+>>>>>>> Stashed changes
+
+ this.pageSize = 5;
+ this.currentPage = 1;
+ }
+
+ });
+
+ return Views;
+
+});
+
+
View
257 app/modules/localeEdit/views.js.BASE.3952.js
@@ -0,0 +1,257 @@
+define([
+ 'app',
+ 'LocaleEdit',
+ 'backbone',
+ 'Mediator'
+],
+
+function(app, LocaleEdit, Backbone) {
+
+ var Views = {};
+ var mediator = new Mediator();
+
+ Views.Upload = Backbone.View.extend({
+ template: 'app/templates/localeedit/upload',
+ tagName: 'div',
+ manage: true
+ });
+
+ Views.Overview = Backbone.View.extend({
+ template: 'app/templates/localeedit/overview',
+ manage: true
+ });
+
+ Views.EditFilter = Backbone.View.extend({
+ events: {
+ "keyup #keySearchTask" : "KeySearch",
+ "click #nextPage" : "NextPage",
+ "click #prevPage" : "PrevPage",
+ "click #gotoStart" : "goToStart",
+ "click #gotoEnd" : "goToEnd",
+ "change #SelElementsPerPage" : "changeElementsPerPage"
+ },
+
+ goToStart: function(e){
+ mediator.Publish('goToStart');
+ return this;
+ },
+
+ goToEnd: function(e){
+ mediator.Publish('goToEnd');
+ return this;
+ },
+ changeElementsPerPage: function(){
+
+ var elementsPerPage = $("#SelElementsPerPage").val();
+ this.elementsPerPage = elementsPerPage;
+ mediator.Publish('elementsPerPageCHanged', elementsPerPage);
+ return this;
+ },
+ NextPage: function(e){
+ mediator.Publish('nextpage');
+ return this;
+ },
+ PrevPage: function(e){
+ mediator.Publish('prevpage');
+ return this;
+ },
+
+ KeySearch: function(e){
+ var keySearchterm = $("#keySearchTask").val();
+ mediator.Publish('keySearch', keySearchterm);
+ return this;
+ },
+ pageChanged : function(page){
+ this.currentPage = page;
+
+ this.render();
+ $('#SelElementsPerPage option:selected').removeAttr('selected');
+ var currentSelected = this.elementsPerPage;
+ $("#SelElementsPerPage option").filter(function() {
+ return $(this).val() == currentSelected;
+ }).attr('selected', true);
+
+ $('#SelElementsPerPage').val(this.elementsPerPage);
+ },
+ data: function() {
+ return {
+ currentpage: this.currentPage,
+ elementsPerPage: this.elementsPerPage
+ };
+ },
+ initialize: function(){
+ this.currentPage = 1;
+
+ this.elementsPerPage = 5;
+ console.log('filter view elementsPerPage : ' + this.elementsPerPage);
+ mediator.Subscribe('pageChanged', this.pageChanged, {}, this)
+
+ },
+ template: 'app/templates/localeedit/filter',
+ manage: true
+ });
+
+ Views.EditKeyValueItem = Backbone.View.extend({
+ template: 'app/templates/localeedit/editKeyValueItem',
+ manage: true,
+
+ tagName: "li",
+ className: 'edititem ',
+
+ events: {
+ "change input.translation": "translationChanged"
+ },
+
+ translationChanged: function(ev) {
+ this.model.Value = $(ev.target).val();
+ this.render();
+ },
+
+
+ data: function() {
+ return { model: this.model };
+ }
+
+ });
+
+
+ Views.EditItem = Backbone.View.extend({
+ template: 'app/templates/localeedit/editItem',
+ manage: true,
+
+ tagName: "div",
+ className: 'edit-wrapper-outer',
+
+ data: function() {
+ return { model: this.model,
+ index: this.model.index };
+ },
+
+
+ beforeRender: function() {
+ var items = this.model.get('LocaleValues');
+
+ for (var i = 0; i < items.length; i++) {
+ this.insertView("ul.locales", new Views.EditKeyValueItem({
+ model: items[i]
+ }));
+ }
+
+ }
+
+ });
+
+Views.EditList = Backbone.View.extend({
+ template: 'app/templates/localeedit/edit',
+ //tagName: 'div',
+ manage: true,
+ className: 'container',
+
+ data: function() {
+ return {
+ count: this.collection.length,
+ currentpage: this.currentPage
+ };
+ },
+
+ events: {
+ "click #SaveBtn" : "save",
+ "click #ResetBtn" : "reload"
+ //,
+ //"change #taskSorting":"sorts"
+ },
+ search: function(term){
+ var collToUse = this.wholeCollecxtion || this.collection;
+ this.renderList(collToUse.search(term));
+ },
+ save: function() {
+ //localStorage.setItem(this.name, JSON.stringify(this.data));
+ LocaleEdit.SaveLocales(this.collection);
+ },
+ renderList : function(filteredCollection){
+
+ if(this.wholeCollecxtion === undefined)
+ {
+ this.wholeCollecxtion = this.collection;
+ };
+ this.collection = filteredCollection;
+ this.render();
+ },
+
+ beforeRender: function() {
+
+ var count = 0;
+ var start = (this.currentPage * this.pageSize) - this.pageSize;
+ var index = 0;
+ console.log('rendering with page size :' + this.pageSize);
+ this.collection.each(function(locale) {
+ index +=1;
+
+ if(index > start && count < this.pageSize ) {
+ count +=1;
+ locale.index = index;
+ this.insertView("div.localelistitems", new Views.EditItem({
+ model: locale
+ }));
+ }
+ }, this);
+ },
+
+ cleanup: function() {
+ //this.collection.off(null, null, this);
+ },
+ reload: function(){
+ this.collection.reset();
+ this.collection.fetch();
+ this.goToPage(1);
+ },
+ goToPage: function(page) {
+ this.currentPage = page;
+ mediator.Publish('pageChanged', this.currentPage);
+ this.render();
+ },
+ prevPage: function(){
+ if(this.currentPage == 0 ) {
+ return;
+ };
+ this.goToPage(this.currentPage -= 1);
+ },
+ nextPage: function(){
+ if( (this.currentPage + 1) > (Math.round(this.collection.length / this.pageSize) +1) )
+ {
+ return;
+ }
+ this.goToPage(this.currentPage += 1);
+ },
+ goToStart: function(){
+ this.goToPage(1);
+ },
+ goToEnd: function(){
+ this.goToPage(Math.round(this.collection.length / this.pageSize) +1 );
+ },
+ changeElementsPerPage:function(pageSize){
+ console.log('setting page size to:' + Number(pageSize));
+ this.pageSize = Number(pageSize);
+ this.render();
+ },
+ initialize: function() {
+ this.collection.on("reset", this.render, this);
+ mediator.Subscribe('keySearch', this.search, {}, this);
+ mediator.Subscribe('nextpage', this.nextPage, {}, this);
+ mediator.Subscribe('prevpage', this.prevPage, {}, this) ;
+
+ mediator.Subscribe('goToStart', this.goToStart, {}, this);
+ mediator.Subscribe('goToEnd', this.goToEnd, {}, this) ;
+ mediator.Subscribe('elementsPerPageCHanged', this.changeElementsPerPage, {}, this);
+
+ this.pageSize = 5;
+ this.currentPage = 1;
+ }
+
+ });
+
+ return Views;
+
+});
+
+
View
268 app/modules/localeEdit/views.js.LOCAL.3952.js
@@ -0,0 +1,268 @@
+define([
+ 'app',
+ 'LocaleEdit',
+ 'backbone',
+ 'Mediator'
+],
+
+function(app, LocaleEdit, Backbone) {
+
+ var Views = {};
+ var mediator = new Mediator();
+
+ Views.Upload = Backbone.View.extend({
+ template: 'app/templates/localeedit/upload',
+ tagName: 'div',
+ manage: true
+ });
+
+ Views.Overview = Backbone.View.extend({
+ template: 'app/templates/localeedit/overview',
+ manage: true
+ });
+
+ Views.EditFilter = Backbone.View.extend({
+ events: {
+ "keyup #keySearchTask" : "KeySearch",
+ "click #nextPage" : "NextPage",
+ "click #prevPage" : "PrevPage",
+ "click #gotoStart" : "goToStart",
+ "click #gotoEnd" : "goToEnd",
+ "change #SelElementsPerPage" : "changeElementsPerPage"
+ },
+
+ goToStart: function(e){
+ mediator.Publish('goToStart');
+ return this;
+ },
+
+ goToEnd: function(e){
+ mediator.Publish('goToEnd');
+ return this;
+ },
+ changeElementsPerPage: function(){
+
+ var elementsPerPage = $("#SelElementsPerPage").val();
+ this.elementsPerPage = elementsPerPage;
+ mediator.Publish('elementsPerPageCHanged', elementsPerPage);
+ return this;
+ },
+ NextPage: function(e){
+ mediator.Publish('nextpage');
+ return this;
+ },
+ PrevPage: function(e){
+ mediator.Publish('prevpage');
+ return this;
+ },
+
+ KeySearch: function(e){
+ var keySearchterm = $("#keySearchTask").val();
+ mediator.Publish('keySearch', keySearchterm);
+ return this;
+ },
+ pageChanged : function(page){
+ this.currentPage = page;
+
+ this.render();
+
+ $('#SelElementsPerPage option:selected').removeAttr('selected');
+ var currentSelected = this.elementsPerPage;
+ $("#SelElementsPerPage option").filter(function() {
+ return $(this).val() == currentSelected;
+ }).attr('selected', true);
+
+ $('#SelElementsPerPage').val(this.elementsPerPage);
+ },
+ keyCountChanged: function(count){
+ this.keyCount = count;
+ this.render();
+ },
+ data: function() {
+ return {
+ currentpage: this.currentPage,
+ elementsPerPage: this.elementsPerPage,
+ keyCount : this.keyCount
+ };
+ },
+ initialize: function(){
+ this.currentPage = 1;
+ this.elementsPerPage = 5;
+ this.keyCountChanged = 0;
+ mediator.Subscribe('pageChanged', this.pageChanged, {}, this)
+ mediator.Subscribe('localeKeyCountChanged', this.keyCountChanged, {}, this)
+
+ },
+ template: 'app/templates/localeedit/filter',
+ manage: true
+ });
+
+ Views.EditKeyValueItem = Backbone.View.extend({
+ template: 'app/templates/localeedit/editKeyValueItem',
+ manage: true,
+
+ tagName: "li",
+ className: 'edititem ',
+
+ events: {
+ "change input.translation": "translationChanged"
+ },
+
+ translationChanged: function(ev) {
+ this.model.Value = $(ev.target).val();
+ this.render();
+ },
+
+
+ data: function() {
+ return { model: this.model };
+ }
+
+ });
+
+
+ Views.EditItem = Backbone.View.extend({
+ template: 'app/templates/localeedit/editItem',
+ manage: true,
+
+ tagName: "div",
+ className: 'edit-wrapper-outer',
+
+ data: function() {
+ return { model: this.model,
+ index: this.model.index };
+ },
+
+
+ beforeRender: function() {
+ var items = this.model.get('LocaleValues');
+
+ for (var i = 0; i < items.length; i++) {
+ this.insertView("ul.locales", new Views.EditKeyValueItem({
+ model: items[i]
+ }));
+ }
+
+ }
+
+ });
+
+Views.EditList = Backbone.View.extend({
+ template: 'app/templates/localeedit/edit',
+ //tagName: 'div',
+ manage: true,
+ className: 'container',
+
+ data: function() {
+ return {
+ count: this.collection.length,
+ currentpage: this.currentPage
+ };
+ },
+
+ events: {
+ "click #SaveBtn" : "save",
+ "click #ResetBtn" : "reload"
+ //,
+ //"change #taskSorting":"sorts"
+ },
+ search: function(term){
+ var collToUse = this.wholeCollecxtion || this.collection;
+ this.renderList(collToUse.search(term));
+ },
+ save: function() {
+ //localStorage.setItem(this.name, JSON.stringify(this.data));
+ LocaleEdit.SaveLocales(this.collection);
+ },
+ renderList : function(filteredCollection){
+
+ if(this.wholeCollecxtion === undefined)
+ {
+ this.wholeCollecxtion = this.collection;
+ };
+ this.collection = filteredCollection;
+ this.render();
+ },
+
+ beforeRender: function() {
+
+ var count = 0;
+ var start = (this.currentPage * this.pageSize) - this.pageSize;
+ var index = 0;
+
+ this.collection.each(function(locale) {
+ index +=1;
+
+ if(index > start && count < this.pageSize ) {
+ count +=1;
+ locale.index = index;
+ this.insertView("div.localelistitems", new Views.EditItem({
+ model: locale
+ }));
+ }
+ }, this);
+ },
+
+ cleanup: function() {
+ //this.collection.off(null, null, this);
+ },
+ reload: function(){
+ this.collection.reset();
+ this.collection.fetch();
+ this.goToPage(1);
+ },
+ goToPage: function(page) {
+ this.currentPage = page;
+ mediator.Publish('pageChanged', this.currentPage);
+ this.render();
+ },
+ prevPage: function(){
+ if(this.currentPage == 0 ) {
+ return;
+ };
+ this.goToPage(this.currentPage -= 1);
+ },
+ nextPage: function(){
+ if( (this.currentPage + 1) > (Math.round(this.collection.length / this.pageSize) +1) )
+ {
+ return;
+ }
+ this.goToPage(this.currentPage += 1);
+ },
+ goToStart: function(){
+ this.goToPage(1);
+ },
+ goToEnd: function(){
+ this.goToPage(Math.round(this.collection.length / this.pageSize) +1 );
+ },
+ changeElementsPerPage:function(pageSize){
+
+ this.pageSize = Number(pageSize);
+ this.render();
+ },
+ initialize: function() {
+ this.collection.on("reset", this.render, this);
+ mediator.Subscribe('keySearch', this.search, {}, this);
+ mediator.Subscribe('nextpage', this.nextPage, {}, this);
+ mediator.Subscribe('prevpage', this.prevPage, {}, this) ;
+
+ mediator.Subscribe('goToStart', this.goToStart, {}, this);
+ mediator.Subscribe('goToEnd', this.goToEnd, {}, this) ;
+ mediator.Subscribe('elementsPerPageCHanged', this.changeElementsPerPage, {}, this);
+
+ this.collection.on("reset", function(){
+ mediator.Publish('localeKeyCountChanged', this.collection.length);
+ }, this);
+
+
+ this.pageSize = 5;
+ this.currentPage = 1;
+ }
+
+ });
+
+ return Views;
+
+});
+
+
View
264 app/modules/localeEdit/views.js.REMOTE.3952.js
@@ -0,0 +1,264 @@
+define([
+ 'app',
+ 'LocaleEdit',
+ 'backbone',
+ 'Mediator'
+],
+
+function(app, LocaleEdit, Backbone) {
+
+ var Views = {};
+ var mediator = new Mediator();
+
+ Views.Upload = Backbone.View.extend({
+ template: 'app/templates/localeedit/upload',
+ tagName: 'div',
+ manage: true
+ });
+
+ Views.Overview = Backbone.View.extend({
+ template: 'app/templates/localeedit/overview',
+ manage: true
+ });
+
+ Views.EditFilter = Backbone.View.extend({
+ events: {
+ "keyup #keySearchTask" : "KeySearch",
+ "click #nextPage" : "NextPage",
+ "click #prevPage" : "PrevPage",
+ "click #gotoStart" : "goToStart",
+ "click #gotoEnd" : "goToEnd",
+ "change #SelElementsPerPage" : "changeElementsPerPage"
+ },
+
+ goToStart: function(e){
+ mediator.Publish('goToStart');
+ return this;
+ },
+
+ goToEnd: function(e){
+ mediator.Publish('goToEnd');
+ return this;
+ },
+ changeElementsPerPage: function(){
+
+ var elementsPerPage = $("#SelElementsPerPage").val();
+ this.elementsPerPage = elementsPerPage;
+ mediator.Publish('elementsPerPageCHanged', elementsPerPage);
+ return this;
+ },
+ NextPage: function(e){
+ mediator.Publish('nextpage');
+ return this;
+ },
+ PrevPage: function(e){
+ mediator.Publish('prevpage');
+ return this;
+ },
+
+ KeySearch: function(e){
+ var keySearchterm = $("#keySearchTask").val();
+ mediator.Publish('keySearch', keySearchterm);
+ return this;
+ },
+ pageChanged : function(page){
+ this.currentPage = page;
+
+ this.render();
+ $('#SelElementsPerPage option:selected').removeAttr('selected');
+ var currentSelected = this.elementsPerPage;
+ $("#SelElementsPerPage option").filter(function() {
+ return $(this).val() == currentSelected;
+ }).attr('selected', true);
+
+ $('#SelElementsPerPage').val(this.elementsPerPage);
+ },
+ data: function() {
+ return {
+ currentpage: this.currentPage,
+ elementsPerPage: this.elementsPerPage
+ };
+ },
+ initialize: function(){
+ this.currentPage = 1;
+
+ this.elementsPerPage = 5;
+ console.log('filter view elementsPerPage : ' + this.elementsPerPage);
+ mediator.Subscribe('pageChanged', this.pageChanged, {}, this)
+
+ },
+ template: 'app/templates/localeedit/filter',
+ manage: true
+ });
+
+ Views.EditKeyValueItem = Backbone.View.extend({
+ template: 'app/templates/localeedit/editKeyValueItem',
+ manage: true,
+
+ tagName: "li",
+ className: 'edititem ',
+
+ events: {
+ "change input.translation": "translationChanged"
+ },
+
+ translationChanged: function(ev) {
+ this.model.Value = $(ev.target).val();
+ this.render();
+ mediator.Publish('modelChanged', this.model);
+ },
+
+
+ data: function() {
+ return { model: this.model };
+ }
+
+ });
+
+
+ Views.EditItem = Backbone.View.extend({
+ template: 'app/templates/localeedit/editItem',
+ manage: true,
+
+ tagName: "div",
+ className: 'edit-wrapper-outer',
+
+ data: function() {
+ return { model: this.model,
+ index: this.model.index };
+ },
+
+
+ beforeRender: function() {
+ var items = this.model.get('LocaleValues');
+
+ for (var i = 0; i < items.length; i++) {
+ this.insertView("ul.locales", new Views.EditKeyValueItem({
+ model: items[i]
+ }));
+ }
+
+ }
+
+ });
+
+Views.EditList = Backbone.View.extend({
+ template: 'app/templates/localeedit/edit',
+ //tagName: 'div',
+ manage: true,
+ className: 'container',
+
+ data: function() {
+ return {
+ count: this.collection.length,
+ currentpage: this.currentPage
+ };
+ },
+
+ events: {
+ "click #SaveBtn" : "save",
+ "click #ResetBtn" : "reload"
+ //,
+ //"change #taskSorting":"sorts"
+ },
+ keySearch: function(term){
+ var collToUse = this.wholeCollecxtion || this.collection;
+ this.renderList(collToUse.search(term));
+ },
+ save: function() {
+ //localStorage.setItem(this.name, JSON.stringify(this.data));
+ LocaleEdit.SaveLocales(this.collection);
+ },
+ renderList : function(filteredCollection){
+
+ if(this.wholeCollecxtion === undefined)
+ {
+ this.wholeCollecxtion = this.collection;
+ };
+ this.collection = filteredCollection;
+ this.render();
+ },
+
+ beforeRender: function() {
+
+ var count = 0;
+ var start = (this.currentPage * this.pageSize) - this.pageSize;
+ var index = 0;
+ console.log('rendering with page size :' + this.pageSize);
+ this.collection.each(function(locale) {
+ index +=1;
+
+ if(index > start && count < this.pageSize ) {
+ count +=1;
+ locale.index = index;
+ this.insertView("div.localelistitems", new Views.EditItem({
+ model: locale
+ }));
+ }
+ }, this);
+ },
+
+ cleanup: function() {
+ //this.collection.off(null, null, this);
+ },
+ reload: function(){
+ this.collection.reset();
+ this.collection.fetch();
+ this.goToPage(1);
+ },
+ goToPage: function(page) {
+ this.currentPage = page;
+ mediator.Publish('pageChanged', this.currentPage);
+ this.render();
+ },
+ prevPage: function(){
+ if(this.currentPage == 0 ) {
+ return;
+ };
+ this.goToPage(this.currentPage -= 1);
+ },
+ nextPage: function(){
+ if( (this.currentPage + 1) > (Math.round(this.collection.length / this.pageSize) +1) )
+ {
+ return;
+ }
+ this.goToPage(this.currentPage += 1);
+ },
+ goToStart: function(){
+ this.goToPage(1);
+ },
+ goToEnd: function(){
+ this.goToPage(Math.round(this.collection.length / this.pageSize) +1 );
+ },
+ changeElementsPerPage:function(pageSize){
+ console.log('setting page size to:' + Number(pageSize));
+ this.pageSize = Number(pageSize);
+ this.render();
+ },
+ syncFilteredWithWholeCollection: function(model){
+ console.log(model);
+ },
+ initialize: function() {
+ this.collection.on("reset", this.render, this);
+
+ mediator.Subscribe('keySearch', this.keySearch, {}, this);
+ mediator.Subscribe('nextpage', this.nextPage, {}, this);
+ mediator.Subscribe('prevpage', this.prevPage, {}, this) ;
+
+ mediator.Subscribe('goToStart', this.goToStart, {}, this);
+ mediator.Subscribe('goToEnd', this.goToEnd, {}, this) ;
+ mediator.Subscribe('elementsPerPageCHanged', this.changeElementsPerPage, {}, this);
+ mediator.Subscribe('modelChanged', this.syncFilteredWithWholeCollection, {}, this);
+
+
+ this.pageSize = 5;
+ this.currentPage = 1;
+ }
+
+ });
+
+ return Views;
+
+});
+
+
View
203 app/modules/localeEdit/views.js.orig
@@ -1,12 +1,14 @@
define([
'app',
'LocaleEdit',
- 'backbone'
+ 'backbone',
+ 'Mediator'
],
-function(app, LocaleEdit, Backbone) {
+function(app, LocaleEdit, Backbone) {
var Views = {};
+ var mediator = new Mediator();
Views.Upload = Backbone.View.extend({
template: 'app/templates/localeedit/upload',
@@ -19,6 +21,81 @@ function(app, LocaleEdit, Backbone) {
manage: true
});
+ Views.EditFilter = Backbone.View.extend({
+ events: {
+ "keyup #keySearchTask" : "KeySearch",
+ "click #nextPage" : "NextPage",
+ "click #prevPage" : "PrevPage",
+ "click #gotoStart" : "goToStart",
+ "click #gotoEnd" : "goToEnd",
+ "change #SelElementsPerPage" : "changeElementsPerPage"
+ },
+
+ goToStart: function(e){
+ mediator.Publish('goToStart');
+ return this;
+ },
+
+ goToEnd: function(e){
+ mediator.Publish('goToEnd');
+ return this;
+ },
+ changeElementsPerPage: function(){
+
+ var elementsPerPage = $("#SelElementsPerPage").val();
+ this.elementsPerPage = elementsPerPage;
+ mediator.Publish('elementsPerPageCHanged', elementsPerPage);
+ return this;
+ },
+ NextPage: function(e){
+ mediator.Publish('nextpage');
+ return this;
+ },
+ PrevPage: function(e){
+ mediator.Publish('prevpage');
+ return this;
+ },
+
+ KeySearch: function(e){
+ var keySearchterm = $("#keySearchTask").val();
+ mediator.Publish('keySearch', keySearchterm);
+ return this;
+ },
+ pageChanged : function(page){
+ this.currentPage = page;
+
+ this.render();
+
+ $('#SelElementsPerPage option:selected').removeAttr('selected');
+ var currentSelected = this.elementsPerPage;
+ $("#SelElementsPerPage option").filter(function() {
+ return $(this).val() == currentSelected;
+ }).attr('selected', true);
+
+ $('#SelElementsPerPage').val(this.elementsPerPage);
+ },
+ keyCountChanged: function(count){
+ this.keyCount = count;
+ this.render();
+ },
+ data: function() {
+ return {
+ currentpage: this.currentPage,
+ elementsPerPage: this.elementsPerPage,
+ keyCount : this.keyCount
+ };
+ },
+ initialize: function(){
+ this.currentPage = 1;
+ this.elementsPerPage = 5;
+ this.keyCountChanged = 0;
+ mediator.Subscribe('pageChanged', this.pageChanged, {}, this)
+ mediator.Subscribe('localeKeyCountChanged', this.keyCountChanged, {}, this)
+
+ },
+ template: 'app/templates/localeedit/filter',
+ manage: true
+ });
Views.EditKeyValueItem = Backbone.View.extend({
template: 'app/templates/localeedit/editKeyValueItem',
@@ -34,6 +111,7 @@ function(app, LocaleEdit, Backbone) {
translationChanged: function(ev) {
this.model.Value = $(ev.target).val();
this.render();
+ mediator.Publish('modelChanged', this.model);
},
@@ -52,7 +130,8 @@ function(app, LocaleEdit, Backbone) {
className: 'edit-wrapper-outer',
data: function() {
- return { model: this.model };
+ return { model: this.model,
+ index: this.model.index };
},
@@ -77,66 +156,122 @@ Views.EditList = Backbone.View.extend({
data: function() {
return {
- count: this.collection.length
+ count: this.collection.length,
+ currentpage: this.currentPage
};
},
events: {
- "keyup #keySearchTask" : "search",
- "click #SaveBtn" : "save"
+ "click #SaveBtn" : "save",
+ "click #ResetBtn" : "reload"
//,
//"change #taskSorting":"sorts"
},
- search: function(e){
- var searchTerm = $("#keySearchTask").val();
- //this.renderList(this.collection.search(letters));
- this.collection.filter(function(model) {
- return model.get("LocaleKey").indexOf(searchTerm) != -1;
- });
- this.collection.reset();
+ keySearch: function(term){
+ var collToUse = this.wholeCollecxtion || this.collection;
+ this.renderList(collToUse.search(term));
},
save: function() {
-<<<<<<< HEAD
//localStorage.setItem(this.name, JSON.stringify(this.data));
LocaleEdit.SaveLocales(this.collection);
-=======
- //localStorage.setItem(this.name, JSON.stringify(this.data));
- console.log(JSON.stringify(this.collection));
->>>>>>> bugfix
},
- renderList : function(task){
- console.log(task);
+ renderList : function(filteredCollection){
+
+ if(this.wholeCollecxtion === undefined)
+ {
+ this.wholeCollecxtion = this.collection;
+ };
+ this.collection = filteredCollection;
+ this.render();
},
beforeRender: function() {
- //var active = this.options.commits.repo;
- this.collection.each(function(locale) {
- // if (locale.get("name") === active) {
- // app.active = repo;
- // }
+ var count = 0;
+ var start = (this.currentPage * this.pageSize) - this.pageSize;
+ var index = 0;
- this.insertView("div.localelistitems", new Views.EditItem({
- model: locale
- }));
+ this.collection.each(function(locale) {
+ index +=1;
+
+ if(index > start && count < this.pageSize ) {
+ count +=1;
+ locale.index = index;
+ this.insertView("div.localelistitems", new Views.EditItem({
+ model: locale
+ }));
+ }
}, this);
},
cleanup: function() {
- this.collection.off(null, null, this);
+ //this.collection.off(null, null, this);
+ },
+ reload: function(){
+ this.collection.reset();
+ this.collection.fetch();
+ this.goToPage(1);
+ },
+ goToPage: function(page) {
+ this.currentPage = page;
+ mediator.Publish('pageChanged', this.currentPage);
+ this.render();
+ },
+ prevPage: function(){
+ if(this.currentPage == 0 ) {
+ return;
+ };
+ this.goToPage(this.currentPage -= 1);
+ },
+ nextPage: function(){
+ if( (this.currentPage + 1) > (Math.round(this.collection.length / this.pageSize) +1) )
+ {
+ return;
+ }
+ this.goToPage(this.currentPage += 1);
+ },
+ goToStart: function(){
+ this.goToPage(1);
},
+ goToEnd: function(){
+ this.goToPage(Math.round(this.collection.length / this.pageSize) +1 );
+ },
+ changeElementsPerPage:function(pageSize){
+ this.pageSize = Number(pageSize);
+ this.render();
+ },
+ syncFilteredWithWholeCollection: function(model){
+ console.log(model);
+ },
initialize: function() {
this.collection.on("reset", this.render, this);
+
+ mediator.Subscribe('keySearch', this.keySearch, {}, this);
+ mediator.Subscribe('nextpage', this.nextPage, {}, this);
+ mediator.Subscribe('prevpage', this.prevPage, {}, this) ;
+
+ mediator.Subscribe('goToStart', this.goToStart, {}, this);
+ mediator.Subscribe('goToEnd', this.goToEnd, {}, this) ;
+ mediator.Subscribe('elementsPerPageCHanged', this.changeElementsPerPage, {}, this);
+ mediator.Subscribe('modelChanged', this.syncFilteredWithWholeCollection, {}, this);
+
+<<<<<<< Updated upstream
+ this.collection.on("reset", function(){
+ mediator.Publish('localeKeyCountChanged', this.collection.length);
+ }, this);
+
+=======
+>>>>>>> Stashed changes
- this.collection.on("fetch", function() {
- this.$("div.loading").html("<img src='/app/img/loading.gif'>");
- }, this);
- //this.collection.fetch();
+ this.pageSize = 5;
+ this.currentPage = 1;
}
});
return Views;
-});
+});
+
+
View
2 app/templates/localeedit/filter.html
@@ -3,7 +3,7 @@
<div class="row" style="padding: 0 0 0 40px;">
<div class="pull-left">
- <input id="keySearchTask" disabled class="input-medium" type="text" placeholder="KEY" value='<%= keySearchterm %>'></input>
+ <input id="keySearchTask" class="input-medium" type="text" placeholder="KEY" value='<%= keySearchterm %>'></input>
<input class="input-medium" disabled type="text" placeholder="LANGUAGE"></input>
<input class="input-medium" disabled type="text" placeholder="VALUE"></input>
</div>

0 comments on commit ea38a70

Please sign in to comment.
Something went wrong with that request. Please try again.