-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bp/524/verbb navigation plugin support (#506)
- Loading branch information
1 parent
dbec8db
commit fa1665d
Showing
19 changed files
with
1,006 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
/** | ||
* Translations for Craft plugin for Craft CMS 4.x | ||
* | ||
* Translations for Craft eliminates error prone and costly copy/paste workflows for launching human translated Craft CMS web content. | ||
* | ||
* @link http://www.acclaro.com/ | ||
* @copyright Copyright (c) 2018 Acclaro | ||
*/ | ||
|
||
namespace acclaro\translations\assetbundles; | ||
|
||
use craft\web\AssetBundle; | ||
use craft\web\assets\cp\CpAsset; | ||
use verbb\base\assetbundles\CpAsset as VerbbCpAsset; | ||
use acclaro\translations\Constants; | ||
|
||
class NavigationAssets extends AssetBundle | ||
{ | ||
public function init() | ||
{ | ||
$this->sourcePath = Constants::URL_BASE_ASSETS; | ||
|
||
$this->depends = [ | ||
VerbbCpAsset::class, | ||
CpAsset::class, | ||
]; | ||
|
||
$this->js = [ | ||
'js/AddTranslationsToNavigation.js', | ||
]; | ||
|
||
$this->css = []; | ||
|
||
parent::init(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,254 @@ | ||
(function ($) { | ||
if (typeof Craft.Translations === "undefined") { | ||
Craft.Translations = {}; | ||
} | ||
|
||
function unique(array) { | ||
return $.grep(array, function (el, index) { | ||
return index === $.inArray(el, array); | ||
}); | ||
} | ||
|
||
Craft.Translations.AddTranslationsToNavigation = { | ||
assets: [], | ||
$btn: null, | ||
|
||
init: function (orders, navId) { | ||
this.addTranslationOrderButton(orders, navId); | ||
}, | ||
|
||
updateSelectedAssets: function () { | ||
var entries = []; | ||
|
||
$(".elements table.data tbody tr.sel[data-id]").each(function () { | ||
entries.push($(this).data("id")); | ||
}); | ||
|
||
this.assets = unique(entries); | ||
|
||
$(this.$btn[0]).toggleClass("link-disabled", this.assets.length === 0); | ||
$(this.$menubtn[0]).toggleClass( | ||
"link-disabled", | ||
this.assets.length === 0 | ||
); | ||
|
||
this.updateCreateNewLink(); | ||
}, | ||
|
||
updateCreateNewLink: function () { | ||
var href = this.$btn.attr("href").split("?")[0]; | ||
|
||
href += "?sourceSite=" + this.getSourceSite(); | ||
|
||
for (var i = 0; i < this.assets.length; i++) { | ||
href += "&elements[]=" + this.assets[i]; | ||
} | ||
|
||
this.$btn.attr("href", href); | ||
}, | ||
|
||
getSourceSite: function () { | ||
var localeMenu = $(".sitemenubtn").data("menubtn").menu; | ||
|
||
// Figure out the initial locale | ||
var $option = localeMenu.$options.filter(".sel:first"); | ||
|
||
if ($option.length === 0) { | ||
$option = localeMenu.$options.first(); | ||
} | ||
|
||
var siteId = $option.data("site-id").toString(); | ||
|
||
return siteId; | ||
}, | ||
|
||
addTranslationOrderButton: function (orders, assetId) { | ||
var self = this; | ||
|
||
var $btncontainer = document.createElement("div"); | ||
$btncontainer.id = "translations-field"; | ||
$btncontainer.className = "field"; | ||
|
||
var $btngroup = $("<div>", { class: "btngroup translations-dropdown" }); | ||
|
||
$btngroup.prependTo("header#header > div:last"); | ||
|
||
this.$btn = $("<a>", { | ||
class: "btn icon", | ||
href: "#", | ||
"data-icon": "language", | ||
}); | ||
|
||
this.$btn.html( | ||
"<span class='btn-text'>" + | ||
Craft.t("app", "New Translation") + | ||
"</span>" | ||
); | ||
|
||
this.$menubtn = $("<div>", { | ||
class: "btn menubtn", | ||
}); | ||
|
||
this.$btn.addClass("link-disabled"); | ||
this.$menubtn.addClass("link-disabled"); | ||
|
||
this.$btn.appendTo($btngroup); | ||
|
||
this.$menubtn.appendTo($btngroup); | ||
|
||
this.$menubtn.on("click", function (e) { | ||
e.preventDefault(); | ||
}); | ||
|
||
var $menu = $("<div>", { class: "menu" }); | ||
|
||
$menu.appendTo($btngroup); | ||
|
||
var $dropdown = $("<ul>", { class: "" }); | ||
|
||
$dropdown.appendTo($menu); | ||
|
||
if (orders.length == "0") { | ||
var $item = $("<li>"); | ||
|
||
$item.appendTo($dropdown); | ||
|
||
var $link = $("<a>", { | ||
class: "link-disabled", | ||
text: "No saved orders available for this site...", | ||
}); | ||
|
||
$link.appendTo($item); | ||
} | ||
|
||
for (var i = 0; i < orders.length; i++) { | ||
var order = orders[i]; | ||
|
||
var $item = $("<li>"); | ||
|
||
$item.appendTo($dropdown); | ||
|
||
var $link = $("<a>", { | ||
href: "#", | ||
text: "Add to " + order.title, | ||
}); | ||
|
||
$link.appendTo($item); | ||
|
||
$link.data("order", order); | ||
|
||
$link.on("click", function (e) { | ||
e.preventDefault(); | ||
|
||
var order = $(this).data("order"); | ||
|
||
var $form = $("<form>", { | ||
method: "POST", | ||
}); | ||
|
||
$form.hide(); | ||
|
||
$form.appendTo("body"); | ||
|
||
$form.append(Craft.getCsrfInput()); | ||
|
||
var $hiddenAction = $("<input>", { | ||
type: "hidden", | ||
name: "action", | ||
value: "translations/base/add-elements-to-order", | ||
}); | ||
|
||
$hiddenAction.appendTo($form); | ||
|
||
var $hiddenOrderId = $("<input>", { | ||
type: "hidden", | ||
name: "id", | ||
value: order.id, | ||
}); | ||
|
||
$hiddenOrderId.appendTo($form); | ||
|
||
var $hiddenSourceSite = $("<input>", { | ||
type: "hidden", | ||
name: "sourceSite", | ||
value: self.getSourceSite(), | ||
}); | ||
|
||
$hiddenSourceSite.appendTo($form); | ||
|
||
for (var j = 0; j < self.assets.length; j++) { | ||
$("<input>", { | ||
type: "hidden", | ||
name: "elements[]", | ||
value: self.assets[j], | ||
}).appendTo($form); | ||
} | ||
|
||
var $submit = $("<input>", { | ||
type: "submit", | ||
}); | ||
|
||
$submit.appendTo($form); | ||
|
||
$form.submit(); | ||
}); | ||
} | ||
|
||
var $link = Craft.getUrl("translations/orders/create", { | ||
"elements[]": assetId, | ||
sourceSite: self.getSourceSite(), | ||
}); | ||
|
||
this.$btn.attr("href", $link); | ||
|
||
this.$menubtn.menubtn(); | ||
|
||
$(document).on( | ||
"click", | ||
".elements .checkbox, table[data-name=Nodes]", | ||
function () { | ||
self.updateSelectedAssets(); | ||
} | ||
); | ||
|
||
this.$btn.on("click", function (e) { | ||
e.preventDefault(); | ||
|
||
var $form = $("<form>", { | ||
method: "POST", | ||
action: Craft.getUrl("translations/orders/create"), | ||
}); | ||
|
||
$form.hide(); | ||
|
||
$form.appendTo("body"); | ||
|
||
$form.append(Craft.getCsrfInput()); | ||
|
||
var $hiddenSourceSite = $("<input>", { | ||
type: "hidden", | ||
name: "sourceSite", | ||
value: self.getSourceSite(), | ||
}); | ||
|
||
$hiddenSourceSite.appendTo($form); | ||
|
||
for (var j = 0; j < self.assets.length; j++) { | ||
$("<input>", { | ||
type: "hidden", | ||
name: "elements[]", | ||
value: self.assets[j], | ||
}).appendTo($form); | ||
} | ||
|
||
var $submit = $("<input>", { | ||
type: "submit", | ||
}); | ||
|
||
$submit.appendTo($form); | ||
|
||
$form.submit(); | ||
}); | ||
}, | ||
}; | ||
})(jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.