Skip to content

Commit d5f9612

Browse files
authored
Merge pull request #647 from noesya/feature/website-default-language-filter
Langue par défaut obligatoire + filtre en JS dans le formulaire d'un website
2 parents 42358fe + af418a4 commit d5f9612

18 files changed

Lines changed: 104 additions & 23 deletions

File tree

.codeclimate.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
version: "2"
2+
plugins:
3+
duplication:
4+
enabled: true
5+
config:
6+
languages:
7+
javascript:
8+
mass_threshold: 50
9+
sass-lint:
10+
enabled: true
11+
config:
12+
config: .sass-lint.yml
13+
eslint:
14+
enabled: true
15+
channel: "eslint-5"
16+
config:
17+
config: .eslintrc.yml
18+
exclude_patterns:
19+
- "node_modules/**"
20+
- "vendor/**"
21+
- "db/**"
22+
- "config/**"
23+
- "docs/**"
24+
- "test/**"

app/assets/javascripts/admin/appstack.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
//= require_tree ./commons
1717
//= require_tree ../application/plugins
1818
//= require_tree ./plugins
19+
//= require_tree ./utils
1920
//= require ./communication/init
2021

2122
window.osuny = {};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//= require_self
22
//= require ./menu_items
33
//= require ./preview
4+
//= require ./websites
45

56
window.osuny.communication = {};

app/assets/javascripts/admin/communication/menu_items.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,7 @@ window.osuny.communication.menuItems = {
7373

7474
window.addEventListener('DOMContentLoaded', function () {
7575
'use strict';
76-
if (document.body.classList.contains('items-new') ||
77-
document.body.classList.contains('items-edit') ||
78-
document.body.classList.contains('items-create') ||
79-
document.body.classList.contains('items-update')) {
76+
if (window.osuny.isInControllerForm('items')) {
8077
window.osuny.communication.menuItems.init();
8178
}
8279
});
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/* global $ */
2+
window.osuny.communication.websites = {
3+
init: function () {
4+
'use strict';
5+
this.languagesCheckboxes = document.querySelectorAll('.js-languages input[type="checkbox"]');
6+
this.defaultLanguageSelect = document.querySelector('.js-default-language');
7+
this.defaultLanguageOptions = this.defaultLanguageSelect.querySelectorAll('option');
8+
this.initEvents();
9+
this.onChangeCheckbox();
10+
},
11+
12+
initEvents: function () {
13+
'use strict';
14+
var i;
15+
for (i = 0 ; i < this.languagesCheckboxes.length ; i += 1) {
16+
this.languagesCheckboxes[i].addEventListener('change', this.onChangeCheckbox.bind(this));
17+
}
18+
},
19+
20+
onChangeCheckbox: function () {
21+
'use strict';
22+
var languageCheckbox,
23+
languageOption,
24+
i;
25+
26+
// Clean options
27+
this.defaultLanguageSelect.innerHTML = "";
28+
29+
// Re-hydrate options
30+
for (i = 0; i < this.defaultLanguageOptions.length; i += 1) {
31+
languageOption = this.defaultLanguageOptions[i];
32+
languageCheckbox = document.querySelector('.js-languages input[type="checkbox"][value="' + languageOption.value + '"]')
33+
if (languageOption.value === "" || languageCheckbox.checked) {
34+
this.defaultLanguageSelect.appendChild(languageOption);
35+
}
36+
}
37+
},
38+
39+
invoke: function () {
40+
'use strict';
41+
return {
42+
init: this.init.bind(this)
43+
};
44+
}
45+
}.invoke();
46+
47+
window.addEventListener('DOMContentLoaded', function () {
48+
'use strict';
49+
if (window.osuny.isInControllerForm('websites')) {
50+
window.osuny.communication.websites.init();
51+
}
52+
});

app/assets/javascripts/admin/pure.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
//= require_tree ./commons
1717
//= require_tree ../application/plugins
1818
//= require_tree ./plugins
19+
//= require_tree ./utils
1920
//= require ./communication/init
2021

2122
window.osuny = {};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
window.osuny.isInControllerForm = function (controllerName) {
2+
return document.body.classList.contains(controllerName + '-new') ||
3+
document.body.classList.contains(controllerName + '-edit') ||
4+
document.body.classList.contains(controllerName + '-create') ||
5+
document.body.classList.contains(controllerName + '-update');
6+
}

app/models/communication/website.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# created_at :datetime not null
1919
# updated_at :datetime not null
2020
# about_id :uuid indexed => [about_type]
21-
# default_language_id :uuid indexed
21+
# default_language_id :uuid not null, indexed
2222
# university_id :uuid not null, indexed
2323
#
2424
# Indexes
@@ -52,7 +52,7 @@ class Communication::Website < ApplicationRecord
5252
gitlab: 1
5353
}
5454

55-
belongs_to :default_language, class_name: "Language", optional: true
55+
belongs_to :default_language, class_name: "Language"
5656
has_and_belongs_to_many :languages,
5757
class_name: 'Language',
5858
join_table: 'communication_websites_languages',

app/models/communication/website/configs/default_languages.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# created_at :datetime not null
1919
# updated_at :datetime not null
2020
# about_id :uuid indexed => [about_type]
21-
# default_language_id :uuid indexed
21+
# default_language_id :uuid not null, indexed
2222
# university_id :uuid not null, indexed
2323
#
2424
# Indexes

app/models/communication/website/configs/default_permalinks.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# created_at :datetime not null
1919
# updated_at :datetime not null
2020
# about_id :uuid indexed => [about_type]
21-
# default_language_id :uuid indexed
21+
# default_language_id :uuid not null, indexed
2222
# university_id :uuid not null, indexed
2323
#
2424
# Indexes

0 commit comments

Comments
 (0)