Compare commits
502 Commits
3.0.0-rc.1
...
3.0.8
Author | SHA1 | Date | |
---|---|---|---|
16111a99fb | |||
e33b60065e | |||
3bcfadd2ab | |||
4729583d8d | |||
aa3f457595 | |||
3ad490f840 | |||
eb27ed65ae | |||
d543f62c5b | |||
5d467115ad | |||
6858b266fe | |||
852b1a4c08 | |||
b2324db7b4 | |||
e8c85e2a54 | |||
a4ac74c84a | |||
4e378484ea | |||
c55be70b2c | |||
70898790f5 | |||
bfdb535f5b | |||
996e6b16e7 | |||
0217e21753 | |||
f6f79d42e1 | |||
4bbd26b098 | |||
028179af37 | |||
87283bf838 | |||
c680badaa2 | |||
df4a936e43 | |||
e27946ebcc | |||
13e64c012f | |||
f69302be48 | |||
16edfc16ea | |||
229a9c8102 | |||
490091a7e2 | |||
5f58e5ca82 | |||
16beda530a | |||
f1b373924f | |||
6a73c463cb | |||
0271675cd0 | |||
b7555aa640 | |||
fa9ef6e5bd | |||
1c97b004ca | |||
f0ab42adf1 | |||
165d8358d4 | |||
6bd6e74bcb | |||
b23df9e0a4 | |||
7b12affb77 | |||
8c8c01aa75 | |||
0150e699a2 | |||
e6943e2638 | |||
6f80dcb1de | |||
60ed294302 | |||
e8017b58f5 | |||
c79bf7d337 | |||
ac268c1ec9 | |||
1ef131fa2d | |||
1873007550 | |||
fa2ccb51c9 | |||
8f87d654af | |||
dee6e9fbad | |||
ef90264316 | |||
70bf4be723 | |||
07ef727654 | |||
a346e5be29 | |||
5ce1eadde7 | |||
8a4d5395b1 | |||
b5feed0f46 | |||
11f9579101 | |||
c6000c959a | |||
19e67ea2b0 | |||
0f6619e25d | |||
daf747d3be | |||
7393b1f2cf | |||
efe861a9ba | |||
2c358ab179 | |||
ca157fc91d | |||
1fbe5d7bc6 | |||
71c031ccf9 | |||
6449b7ccca | |||
6a956472fe | |||
d6af88d667 | |||
b9184a202f | |||
f898746967 | |||
68165b7b78 | |||
bb8591a67b | |||
bda71ae78e | |||
abd4f6cac2 | |||
87e6cc2a4f | |||
dde598eb64 | |||
0c4407f43a | |||
b6c864e7a1 | |||
3d9dc6465d | |||
9a6fec094a | |||
61af224d7d | |||
9b41641e97 | |||
4e2e9f6f8f | |||
c29dc8b4c7 | |||
98a3c6b156 | |||
69c540288b | |||
651c9f5692 | |||
9ad3778cf7 | |||
c90e0e9f64 | |||
cb1730c4e2 | |||
3dd8a973fd | |||
c3ea088fca | |||
a11d6d7868 | |||
a596add838 | |||
7e7103ddab | |||
0064970ed7 | |||
9d93f3ea95 | |||
ff2a3cd19e | |||
8419d95ea1 | |||
4ad317ac7b | |||
7cccebbf2c | |||
e4f76ee9eb | |||
7f52f72c25 | |||
44afcbbeaf | |||
e816c59539 | |||
c74421a42a | |||
23eb4633c4 | |||
26241afb86 | |||
92dbf966a1 | |||
db226b54a8 | |||
3af059f5c4 | |||
8706abcdf0 | |||
2129d041ac | |||
2a4a44ebb5 | |||
a4f2d5402c | |||
9f5fc151b4 | |||
8a91eb46e6 | |||
e4ab928e82 | |||
a1b02cb862 | |||
84b942b9d2 | |||
1ca99a6209 | |||
6b61abe8c0 | |||
27028ca1ef | |||
eed88926a2 | |||
b25877c514 | |||
119e574495 | |||
7308d253b2 | |||
1c19b71697 | |||
7551fff93f | |||
b2aa919574 | |||
1102bbe483 | |||
b78dd22ba9 | |||
73110ada46 | |||
74dedd06bc | |||
20c936d13b | |||
f135b89de9 | |||
6a83930ae0 | |||
a1d0acfac2 | |||
04be06c0cb | |||
78d52d6298 | |||
5ff7c28c43 | |||
5526f315d2 | |||
d5e25fdeb1 | |||
90a7bf5179 | |||
bf1f696870 | |||
95551ad049 | |||
1ad90680f4 | |||
d69d3cb421 | |||
9adca07393 | |||
a9d129fddc | |||
b4ac09bea3 | |||
b1a403d9b5 | |||
28504fb5e3 | |||
8ebb8e3c02 | |||
c95c2cd1ae | |||
946bee2194 | |||
1f9bd04308 | |||
33572b2dc7 | |||
680446b77e | |||
bf1d76a3a7 | |||
c915fcfdff | |||
02966c3b93 | |||
84dc48daec | |||
12225004f4 | |||
320dfa2ec5 | |||
b5f3016085 | |||
cd53e369d0 | |||
6fc11af774 | |||
42e3a97616 | |||
6b16aa1692 | |||
03d0de74e4 | |||
c3b643df84 | |||
697f9ba5bc | |||
28c75c5b96 | |||
6f255854f2 | |||
91c5f9c43e | |||
62acd6404a | |||
adc1461771 | |||
66cc0964ce | |||
10d77720ad | |||
475114c6f9 | |||
a0fec7d103 | |||
4d9d92a026 | |||
e51aa8c271 | |||
d44adedade | |||
9fb3c50aa7 | |||
907053a349 | |||
f0f85cfb59 | |||
44d0341fb2 | |||
0cdae52c66 | |||
0cd9c8e416 | |||
9e3010ab52 | |||
d831b2df55 | |||
16ff630e88 | |||
d35763662e | |||
10be411b12 | |||
6ecce192f7 | |||
ee07e60fe9 | |||
a35d7a1154 | |||
ebba8dbfd6 | |||
44c637c06b | |||
d54ba734bf | |||
b45fc22306 | |||
994935d4ae | |||
ceb5ce850c | |||
97b5ed945d | |||
873b322245 | |||
12ad9e41e7 | |||
96b418e455 | |||
8ea7861f77 | |||
821976c881 | |||
6f1443e43d | |||
09fcaecdfc | |||
efd72ca9f6 | |||
550b5e9aed | |||
4b7ae5fcff | |||
fa85e12127 | |||
1cce50902b | |||
2048fa5cf9 | |||
f438c8fd31 | |||
0bfa832dad | |||
483dfbe1ec | |||
561fee491d | |||
97d157192a | |||
6b14a8a057 | |||
d27b187f5e | |||
02d49ba2ca | |||
f3571a5855 | |||
3d5f0df213 | |||
595a201fe7 | |||
c3db7d8148 | |||
4a2187ff32 | |||
279c36a30d | |||
fd65117a5d | |||
9305beace3 | |||
ba86cbfb18 | |||
2ac7d1d4ab | |||
e9c55260c8 | |||
99b6a287f8 | |||
d645f0cad4 | |||
b0343254c0 | |||
cc368f015b | |||
4e508855fc | |||
72c0a6f165 | |||
f266508654 | |||
1893d82b2d | |||
bb1dd6a2ec | |||
7097ea5d9b | |||
b4092e0641 | |||
2c068c7bb6 | |||
a1a4fcb978 | |||
f77620d649 | |||
9e932c9078 | |||
de47dbe41b | |||
6d36d67a60 | |||
607bf51b37 | |||
f38ed0272c | |||
eef969439b | |||
272f552f3c | |||
dff9c1012b | |||
52470360a1 | |||
6c62459ed4 | |||
98482cebf9 | |||
509880119e | |||
195ccb5eed | |||
122af1c943 | |||
169940058b | |||
478e60d60e | |||
9fc0ac8c4f | |||
e86b780479 | |||
42f08bdc65 | |||
c2789cdac3 | |||
8a362f49f8 | |||
784a80d1a5 | |||
922d2b4b5f | |||
91e8461cac | |||
8757598a2d | |||
524aabea1d | |||
513181ff47 | |||
6bc288ed54 | |||
77f3a875dd | |||
6584250d1a | |||
e42db162aa | |||
2762096167 | |||
b2ec3e5f7b | |||
e012bd6cbe | |||
a02e64e805 | |||
e4bb3e1133 | |||
998795e0e0 | |||
ec44b84cc9 | |||
efece061d0 | |||
e347fc74a2 | |||
027418a86c | |||
864187aa02 | |||
59ae6619c0 | |||
6aa0be8d01 | |||
657658ea2b | |||
8647128e12 | |||
c8d92b3cd2 | |||
cc8b7b45ed | |||
5b8b8c8441 | |||
7106c640ef | |||
300b84983d | |||
49c1b92838 | |||
d900827850 | |||
1688d4dbe1 | |||
856c636089 | |||
8f9e8ea185 | |||
b0b88693f1 | |||
9916eb9da8 | |||
79b5426e01 | |||
5807fd2e02 | |||
0ee39143f4 | |||
10c39bd650 | |||
20593cc5a5 | |||
f438eee842 | |||
cb4b599d97 | |||
33733219f6 | |||
737a83cdf3 | |||
9061e1b495 | |||
09199e41a1 | |||
4e91932613 | |||
227de4ecfa | |||
c1ccacf851 | |||
53f7953566 | |||
61ae2da1e3 | |||
36abd8e5e6 | |||
7e9de1fd07 | |||
7ac5e65963 | |||
cf992852b5 | |||
59482b2bfa | |||
053f9e0cdf | |||
e1cc25239b | |||
2f4452ad36 | |||
f453d685d6 | |||
2d2b4ca7f0 | |||
546e012fbf | |||
83adf089c5 | |||
2f45bb05d7 | |||
9ef8ab3e28 | |||
f4db4f05c4 | |||
e7e08dbb3a | |||
02e2f0c07a | |||
c75b6bd7eb | |||
b74be8777a | |||
7463e0d1f1 | |||
a378880cf8 | |||
33fa496913 | |||
eff996e1f8 | |||
28b894b26b | |||
c914aedc0d | |||
1745b67d64 | |||
2d25974fdc | |||
51a02784e2 | |||
b9bdc86fd9 | |||
e580e6b92b | |||
96f77498f7 | |||
62ce7c0437 | |||
c1e542cb5a | |||
544bf0ddfd | |||
609f1b5e67 | |||
4616cf67bf | |||
cc5227ca0d | |||
26bccd95d4 | |||
af58814fe7 | |||
7d9b4b31aa | |||
8a8108b41d | |||
d92b1f57bd | |||
52ef7bece4 | |||
dc11046ad1 | |||
01f41b9798 | |||
9c0d9c31f8 | |||
df499095c4 | |||
05dca3d2ce | |||
ec35b90f3e | |||
1b7e3a997f | |||
c598537025 | |||
6f149e3ec4 | |||
d181bde0e9 | |||
2985705b14 | |||
6ce925fbe8 | |||
b8aceff61f | |||
cd091c2af6 | |||
510cacf2fd | |||
eac6b1b414 | |||
316fa91a10 | |||
7c23415d26 | |||
28320cdbb6 | |||
48f3ae4ea1 | |||
e47c8bc701 | |||
78429d8f91 | |||
80c4eeed5e | |||
5985d659f9 | |||
638de3cf55 | |||
967fa09f4f | |||
a15e1200b5 | |||
a15b46cbab | |||
dcb0b45c21 | |||
14810a22b5 | |||
1b756ef0b2 | |||
5553817f9a | |||
4b7fb3ae3d | |||
efa231b08f | |||
8d8dfaa11f | |||
5ba2c4bc3a | |||
788494ec47 | |||
5e7f9e3edf | |||
2e5554a3af | |||
51fbf29031 | |||
c3c6ce989c | |||
a241d0c7bc | |||
632bce7894 | |||
1151354278 | |||
c12752403f | |||
d3ff174e9f | |||
03df7e723c | |||
6c8fe8413a | |||
89b0b51980 | |||
fa1ab733f8 | |||
127022645e | |||
b1d26b8cee | |||
f07b90adde | |||
b3884d06a8 | |||
abf1d817f4 | |||
c7b7b0abad | |||
8540e5eea9 | |||
09ed3d4fa6 | |||
b96dc8b3f7 | |||
0a4dc3eb38 | |||
a78af28943 | |||
f035d12aaf | |||
6353075f1e | |||
6c91ca9d31 | |||
6f8634570c | |||
0efcfad3d1 | |||
5d7b54ab22 | |||
ad1f6e2a8e | |||
d844b7e47f | |||
36d4e3eb15 | |||
853f686dde | |||
d17486bac4 | |||
4226684c5a | |||
364dd1b2a3 | |||
eaf10e8a96 | |||
bac494ac0d | |||
acd2b9f51e | |||
27c6fa5ff4 | |||
89b51b6215 | |||
7725391eff | |||
a37117cfa3 | |||
856331caa4 | |||
9117ae1a27 | |||
4aae8d56e5 | |||
033d527db9 | |||
b2b1f7ff71 | |||
de261d6179 | |||
a587b0a966 | |||
441aa14bcb | |||
4b4b5dd556 | |||
df9ba7e6c8 | |||
ca4f1c9387 | |||
8c151d2d11 | |||
78fb9ba46f | |||
3a0669e1a2 | |||
c466e53681 | |||
d02aed870e | |||
fad7ff0018 | |||
84a3f98725 | |||
1c3e968ec4 | |||
c090a8260b | |||
65726de7de | |||
33fe302f0d | |||
2d702dd5d3 | |||
18f208cf47 | |||
f7b1016e63 | |||
223fedba72 | |||
bf7e7e414f | |||
618d0c0c9d | |||
49318791fc | |||
a5abdd28e1 | |||
70860a676c | |||
469e9fd8e1 | |||
715b48df8d | |||
27ae0a9f16 | |||
b92329a6b5 | |||
6fe5b7e0c5 | |||
7e0c500e4f | |||
eec35c8ab6 | |||
4096c4b31b | |||
40cbefd1f4 | |||
fb5d43e975 |
@ -55,6 +55,49 @@ jobs:
|
||||
- store_artifacts:
|
||||
path: /tmp/fake-mailer/
|
||||
destination: fake-mailer
|
||||
acceptance_tests:
|
||||
working_directory: /home/circleci/mailpoet
|
||||
machine: true
|
||||
steps:
|
||||
- checkout
|
||||
- run:
|
||||
name: "Set up virtual host"
|
||||
command: echo 127.0.0.1 mailpoet.loc | sudo tee -a /etc/hosts
|
||||
- restore_cache:
|
||||
key: composer-{{ checksum "composer.json" }}-{{ checksum "composer.lock" }}
|
||||
- restore_cache:
|
||||
key: npm-{{ checksum "package.json" }}
|
||||
- run:
|
||||
name: "Set up test environment"
|
||||
command: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install circleci-php-5.6.23
|
||||
sudo rm /usr/bin/php
|
||||
sudo ln -s /opt/circleci/php/5.6.23/bin/php /usr/bin/php
|
||||
# Install NodeJS+NPM
|
||||
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
|
||||
sudo apt-get install nodejs build-essential
|
||||
# install plugin dependencies
|
||||
curl -sS https://getcomposer.org/installer | php
|
||||
php composer.phar install
|
||||
./do install
|
||||
./do compile:all --env production
|
||||
- save_cache:
|
||||
key: composer-{{ checksum "composer.json" }}-{{ checksum "composer.lock" }}
|
||||
paths:
|
||||
- vendor
|
||||
- save_cache:
|
||||
key: npm-{{ checksum "package.json" }}
|
||||
paths:
|
||||
- node_modules
|
||||
- run:
|
||||
name: Run acceptance tests
|
||||
command: |
|
||||
docker-compose run codeception --steps --debug -vvv --html --xml
|
||||
- store_artifacts:
|
||||
path: tests/_output
|
||||
- store_test_results:
|
||||
path: tests/_output
|
||||
php7:
|
||||
working_directory: /home/circleci/mailpoet
|
||||
docker:
|
||||
@ -92,3 +135,4 @@ workflows:
|
||||
jobs:
|
||||
- qa_js_php5
|
||||
- php7
|
||||
- acceptance_tests
|
||||
|
@ -9,89 +9,48 @@
|
||||
},
|
||||
"rules": {
|
||||
"import/no-amd": 0,
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
"space-before-function-paren": 0,
|
||||
"prefer-arrow-callback": 0,
|
||||
"no-undef": 0,
|
||||
"key-spacing": 0,
|
||||
"radix": 0,
|
||||
"no-alert": 0,
|
||||
"block-scoped-var": 0,
|
||||
"guard-for-in": 0,
|
||||
"no-prototype-builtins": 0,
|
||||
"no-restricted-syntax": 0,
|
||||
"newline-per-chained-call": 0,
|
||||
"no-useless-concat": 0,
|
||||
"no-multi-spaces": 0,
|
||||
"no-nested-ternary": 0,
|
||||
"semi-spacing": 0,
|
||||
"no-sequences": 0,
|
||||
"no-useless-return": 0,
|
||||
"array-callback-return": 0,
|
||||
"new-cap": 0,
|
||||
"no-return-assign": 0,
|
||||
"no-continue": 0,
|
||||
"no-new": 0,
|
||||
"no-cond-assign": 0,
|
||||
"space-unary-ops": 0,
|
||||
"no-redeclare": 0,
|
||||
"no-console": 0,
|
||||
"no-empty": 0,
|
||||
"no-extra-semi": 0,
|
||||
"no-useless-escape": 0,
|
||||
"wrap-iife": 0,
|
||||
"no-unused-expressions": 0,
|
||||
"block-spacing": 0,
|
||||
"computed-property-spacing": 0,
|
||||
"no-plusplus": 0,
|
||||
"array-bracket-spacing": 0,
|
||||
"lines-around-directive": 0,
|
||||
"no-unreachable": 0,
|
||||
"default-case": 0,
|
||||
"no-lonely-if": 0,
|
||||
"space-before-blocks": 0,
|
||||
"no-unneeded-ternary": 0,
|
||||
"no-mixed-operators": 0,
|
||||
"eqeqeq": 0,
|
||||
"space-in-parens": 0,
|
||||
"semi": 0,
|
||||
"max-len": 0,
|
||||
"no-multi-assign": 0,
|
||||
"no-trailing-spaces": 0,
|
||||
"global-require": 0,
|
||||
"no-throw-literal": 0,
|
||||
"no-extra-bind": 0,
|
||||
"one-var-declaration-per-line": 0,
|
||||
"consistent-return": 0,
|
||||
"no-shadow": 0,
|
||||
"no-underscore-dangle": 0,
|
||||
"brace-style": 0,
|
||||
"no-else-return": 0,
|
||||
"no-use-before-define": 0,
|
||||
"one-var": 0,
|
||||
"camelcase": 0,
|
||||
"spaced-comment": 0,
|
||||
"quotes": 0,
|
||||
"padded-blocks": 0,
|
||||
"object-curly-spacing": 0,
|
||||
"strict": 0,
|
||||
"vars-on-top": 0,
|
||||
"no-var": 0,
|
||||
"space-infix-ops": 0,
|
||||
"no-unused-vars": 0,
|
||||
"object-shorthand": 0,
|
||||
"new-parens": 0,
|
||||
"no-param-reassign": 0,
|
||||
"keyword-spacing": 0,
|
||||
"eol-last": 0,
|
||||
"dot-notation": 0,
|
||||
"linebreak-style": 0,
|
||||
"indent": 0,
|
||||
"quote-props": 0,
|
||||
"prefer-template": 0,
|
||||
"func-names": 0
|
||||
}
|
||||
|
@ -10,88 +10,61 @@
|
||||
"jsx": true
|
||||
}
|
||||
},
|
||||
"settings": {
|
||||
"import/resolver": "webpack"
|
||||
},
|
||||
"rules": {
|
||||
"comma-dangle": ["error", "always-multiline"],
|
||||
|
||||
|
||||
|
||||
"import/no-amd": 0,
|
||||
|
||||
"react/no-multi-comp": 0,
|
||||
"react/sort-comp": 0,
|
||||
"react/jsx-max-props-per-line": 0,
|
||||
"react/prop-types": 0,
|
||||
"react/jsx-first-prop-new-line": 0,
|
||||
"react/jsx-indent-props": 0,
|
||||
"react/no-is-mounted": 0,
|
||||
"react/jsx-no-target-blank": 0,
|
||||
"react/no-render-return-value": 0,
|
||||
"react/jsx-boolean-value": 0,
|
||||
"react/jsx-indent": 0,
|
||||
"react/jsx-no-bind": 0,
|
||||
"react/no-array-index-key": 0,
|
||||
"react/self-closing-comp": 0,
|
||||
"react/jsx-tag-spacing": 0,
|
||||
"react/jsx-closing-bracket-location": 0,
|
||||
"react/no-string-refs": 0,
|
||||
"react/jsx-curly-spacing": 0,
|
||||
"react/no-did-mount-set-state": 0,
|
||||
"react/prefer-stateless-function": 0,
|
||||
|
||||
"jsx-a11y/label-has-for": 0,
|
||||
"jsx-a11y/no-static-element-interactions": 0,
|
||||
"jsx-a11y/alt-text": 0,
|
||||
|
||||
"func-names": 0,
|
||||
"object-shorthand": 0,
|
||||
"no-bitwise": 0,
|
||||
"arrow-body-style": 0,
|
||||
"prefer-template": 0,
|
||||
"keyword-spacing": 0,
|
||||
"default-case": 0,
|
||||
"quote-props": 0,
|
||||
"array-callback-return": 0,
|
||||
"consistent-return": 0,
|
||||
"no-unreachable": 0,
|
||||
"no-extra-semi": 0,
|
||||
"import/no-unresolved": 0,
|
||||
"import/extensions": 0,
|
||||
"import/no-extraneous-dependencies": 0,
|
||||
"camelcase": 0,
|
||||
"template-curly-spacing": 0,
|
||||
"quotes": 0,
|
||||
"eqeqeq": 0,
|
||||
"no-lonely-if": 0,
|
||||
"space-unary-ops": 0,
|
||||
"block-scoped-var": 0,
|
||||
"no-extra-bind": 0,
|
||||
"no-multi-spaces": 0,
|
||||
"class-methods-use-this": 0,
|
||||
"key-spacing": 0,
|
||||
"no-multiple-empty-lines": 0,
|
||||
"space-in-parens": 0,
|
||||
"no-case-declarations": 0,
|
||||
"array-bracket-spacing": 0,
|
||||
"newline-per-chained-call": 0,
|
||||
"no-else-return": 0,
|
||||
"max-len": 0,
|
||||
"no-useless-concat": 0,
|
||||
"no-unused-expressions": 0,
|
||||
"no-sequences": 0,
|
||||
"no-extra-boolean-cast": 0,
|
||||
"dot-notation": 0,
|
||||
"no-param-reassign": 0,
|
||||
"no-shadow": 0,
|
||||
"one-var": 0,
|
||||
"no-alert": 0,
|
||||
"one-var-declaration-per-line": 0,
|
||||
"no-script-url": 0,
|
||||
"wrap-iife": 0,
|
||||
"vars-on-top": 0,
|
||||
"space-infix-ops": 0,
|
||||
"no-irregular-whitespace": 0,
|
||||
"padded-blocks": 0,
|
||||
"no-underscore-dangle": 0,
|
||||
"no-undef": 0
|
||||
"no-underscore-dangle": 0
|
||||
}
|
||||
}
|
||||
|
@ -8,39 +8,13 @@
|
||||
"ecmaVersion": 6
|
||||
},
|
||||
"rules": {
|
||||
"import/no-amd": 0,
|
||||
|
||||
|
||||
|
||||
"no-undef": 0,
|
||||
"one-var": 0,
|
||||
"indent": 0,
|
||||
"linebreak-style": 0,
|
||||
"no-whitespace-before-property": 0,
|
||||
"object-property-newline": 0,
|
||||
"global-require": 0,
|
||||
"semi": 0,
|
||||
"keyword-spacing": 0,
|
||||
"no-bitwise": 0,
|
||||
"no-multi-assign": 0,
|
||||
"newline-per-chained-call": 0,
|
||||
"no-spaced-func": 0,
|
||||
"func-call-spacing": 0,
|
||||
"max-len": 0,
|
||||
"space-unary-ops": 0,
|
||||
"quotes": 0,
|
||||
"no-unused-vars": 0,
|
||||
"no-unused-expressions": 0,
|
||||
"no-underscore-dangle": 0,
|
||||
"quote-props": 0,
|
||||
"no-shadow": 0,
|
||||
"padded-blocks": 0,
|
||||
"vars-on-top": 0,
|
||||
"space-before-blocks": 0,
|
||||
"object-curly-spacing": 0,
|
||||
"no-param-reassign": 0,
|
||||
"one-var-declaration-per-line": 0,
|
||||
// Exceptions
|
||||
"func-names": 0,
|
||||
"space-before-function-paren": 0
|
||||
// To add
|
||||
"no-bitwise": 0,
|
||||
"max-len": 0,
|
||||
"no-underscore-dangle": 0,
|
||||
"no-shadow": 0,
|
||||
"padded-blocks": 0
|
||||
}
|
||||
}
|
||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,8 +2,8 @@
|
||||
TODO
|
||||
composer.phar
|
||||
/vendor
|
||||
/vendor_backup
|
||||
tests/_output/*
|
||||
tests/acceptance.suite.yml
|
||||
tests/_support/_generated/*
|
||||
node_modules
|
||||
.env
|
||||
|
39
Dockerfile
Normal file
39
Dockerfile
Normal file
@ -0,0 +1,39 @@
|
||||
FROM php:5.6-cli
|
||||
|
||||
ENV COMPOSER_ALLOW_SUPERUSER=1
|
||||
|
||||
RUN apt-get update && \
|
||||
apt-get -y install \
|
||||
git \
|
||||
zlib1g-dev \
|
||||
libssl-dev \
|
||||
mysql-client \
|
||||
sudo less \
|
||||
--no-install-recommends && \
|
||||
apt-get clean && \
|
||||
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
|
||||
docker-php-ext-install bcmath zip mysqli pdo pdo_mysql && \
|
||||
echo "date.timezone = UTC" >> /usr/local/etc/php/php.ini && \
|
||||
curl -sS https://getcomposer.org/installer | php -- \
|
||||
--filename=composer \
|
||||
--install-dir=/usr/local/bin && \
|
||||
composer global require --optimize-autoloader "hirak/prestissimo" && \
|
||||
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar && \
|
||||
chmod +x wp-cli.phar && \
|
||||
mv wp-cli.phar /usr/local/bin/wp
|
||||
|
||||
# Prepare application
|
||||
WORKDIR /repo
|
||||
|
||||
# Install vendor
|
||||
COPY ./composer.json /repo/composer.json
|
||||
|
||||
# Add source-code
|
||||
COPY . /repo
|
||||
|
||||
WORKDIR /wp-core/wp-content/plugins/mailpoet
|
||||
ENV WP_TEST_PATH=/wp-core
|
||||
|
||||
ADD docker-entrypoint.sh /
|
||||
|
||||
RUN ["chmod", "+x", "/docker-entrypoint.sh"]
|
18
README.md
18
README.md
@ -180,3 +180,21 @@ Run 'svn copy ...' to tag the release
|
||||
It's quite literal: you can review the changes to be pushed and if you're satisfied, run the suggested command to finish the release publishing process.
|
||||
|
||||
If you're confident, execute `./do publish --force` and your release will be published to the remote SVN repository without manual intervention (automatically). For easier authentication you might want to set `WP_SVN_USERNAME` and `WP_SVN_PASSWORD` environment variables.
|
||||
|
||||
# Acceptance testing
|
||||
|
||||
We are using Gravity Flow plugin's setup as an example for our acceptance test suite: https://www.stevenhenty.com/learn-acceptance-testing-deeply/
|
||||
|
||||
From the article above:
|
||||
|
||||
_Windows users only: enable hard drive sharing in the Docker settings._
|
||||
|
||||
The browser runs in a docker container. You can use a VNC client to watch the test run, follow instructions in official
|
||||
repo: https://github.com/SeleniumHQ/docker-selenium
|
||||
If you’re on a Mac, you can open vnc://localhost:5900 in Safari to watch the tests running in Chrome. If you’re on Windows, you’ll need a VNC client. Password: secret.
|
||||
|
||||
|
||||
To run tests:
|
||||
```sh
|
||||
$ ./do test:acceptance
|
||||
```
|
44
RoboFile.php
44
RoboFile.php
@ -90,6 +90,7 @@ class RoboFile extends \Robo\Tasks {
|
||||
|
||||
$css_files = array(
|
||||
'assets/css/src/admin.styl',
|
||||
'assets/css/src/admin-global.styl',
|
||||
'assets/css/src/newsletter_editor/newsletter_editor.styl',
|
||||
'assets/css/src/public.styl',
|
||||
'assets/css/src/rtl.styl',
|
||||
@ -154,9 +155,8 @@ class RoboFile extends \Robo\Tasks {
|
||||
|
||||
function testUnit($opts=['file' => null, 'xml' => false]) {
|
||||
$this->loadEnv();
|
||||
$this->_exec('vendor/bin/codecept build');
|
||||
|
||||
$command = 'vendor/bin/codecept run unit -f '.(($opts['file']) ? $opts['file'] : '');
|
||||
$command = 'vendor/bin/codecept run unit -c codeception.unit.yml -f '.(($opts['file']) ? $opts['file'] : '');
|
||||
|
||||
if($opts['xml']) {
|
||||
$command .= ' --xml';
|
||||
@ -166,9 +166,8 @@ class RoboFile extends \Robo\Tasks {
|
||||
|
||||
function testCoverage($opts=['file' => null, 'xml' => false]) {
|
||||
$this->loadEnv();
|
||||
$this->_exec('vendor/bin/codecept build');
|
||||
$command = join(' ', array(
|
||||
'vendor/bin/codecept run',
|
||||
'vendor/bin/codecept run unit -c codeception.unit.yml ',
|
||||
(($opts['file']) ? $opts['file'] : ''),
|
||||
'--coverage',
|
||||
($opts['xml']) ? '--coverage-xml' : '--coverage-html'
|
||||
@ -201,9 +200,9 @@ class RoboFile extends \Robo\Tasks {
|
||||
|
||||
function testDebug($opts=['file' => null, 'xml' => false]) {
|
||||
$this->loadEnv();
|
||||
$this->_exec('vendor/bin/codecept build');
|
||||
$this->_exec('vendor/bin/codecept build -c codeception.unit.yml');
|
||||
|
||||
$command = 'vendor/bin/codecept run unit --debug -f '.(($opts['file']) ? $opts['file'] : '');
|
||||
$command = 'vendor/bin/codecept run unit -c codeception.unit.yml --debug -f '.(($opts['file']) ? $opts['file'] : '');
|
||||
|
||||
if($opts['xml']) {
|
||||
$command .= ' --xml';
|
||||
@ -211,10 +210,14 @@ class RoboFile extends \Robo\Tasks {
|
||||
return $this->_exec($command);
|
||||
}
|
||||
|
||||
function testAcceptance() {
|
||||
return $this->_exec('COMPOSE_HTTP_TIMEOUT=200 docker-compose run codeception --steps --debug -vvv');
|
||||
}
|
||||
|
||||
function testFailed() {
|
||||
$this->loadEnv();
|
||||
$this->_exec('vendor/bin/codecept build');
|
||||
return $this->_exec('vendor/bin/codecept run -g failed');
|
||||
$this->_exec('vendor/bin/codecept build -c codeception.unit.yml');
|
||||
return $this->_exec('vendor/bin/codecept run -c codeception.unit.yml -g failed');
|
||||
}
|
||||
|
||||
function qa() {
|
||||
@ -286,15 +289,16 @@ class RoboFile extends \Robo\Tasks {
|
||||
}
|
||||
|
||||
function svnPublish($opts = ['force' => false]) {
|
||||
$this->loadWPFunctions();
|
||||
$this->loadEnv();
|
||||
|
||||
$svn_dir = ".mp_svn";
|
||||
$plugin_data = get_plugin_data('mailpoet.php', false, false);
|
||||
$plugin_version = $plugin_data['Version'];
|
||||
$plugin_dist_name = sanitize_title_with_dashes($plugin_data['Name']);
|
||||
$plugin_dist_name = explode('-', $plugin_dist_name);
|
||||
$plugin_dist_name = $plugin_dist_name[0];
|
||||
$plugin_version = $this->getPluginVersion('mailpoet.php');
|
||||
$plugin_dist_name = 'mailpoet';
|
||||
$plugin_dist_file = $plugin_dist_name . '.zip';
|
||||
|
||||
if(!$plugin_version) {
|
||||
throw new \Exception('Could not parse plugin version, check the plugin header');
|
||||
}
|
||||
$this->say('Publishing version: ' . $plugin_version);
|
||||
|
||||
// Sanity checks
|
||||
@ -413,13 +417,9 @@ class RoboFile extends \Robo\Tasks {
|
||||
$dotenv->load();
|
||||
}
|
||||
|
||||
protected function loadWPFunctions() {
|
||||
$this->loadEnv();
|
||||
define('ABSPATH', getenv('WP_TEST_PATH') . '/');
|
||||
define('WPINC', 'wp-includes');
|
||||
require_once(ABSPATH . WPINC . '/functions.php');
|
||||
require_once(ABSPATH . WPINC . '/formatting.php');
|
||||
require_once(ABSPATH . WPINC . '/plugin.php');
|
||||
require_once(ABSPATH . 'wp-admin/includes/plugin.php');
|
||||
protected function getPluginVersion($file) {
|
||||
$data = file_get_contents($file);
|
||||
preg_match('/^[ \t*]*Version:(.*)$/mi', $data, $m);
|
||||
return !empty($m[1]) ? trim($m[1]) : false;
|
||||
}
|
||||
}
|
||||
|
15
assets/css/src/admin-global.styl
Normal file
15
assets/css/src/admin-global.styl
Normal file
@ -0,0 +1,15 @@
|
||||
@import 'nib'
|
||||
|
||||
@require 'icons'
|
||||
|
||||
/*
|
||||
Style for Members plugin
|
||||
*/
|
||||
|
||||
.members-tab-title
|
||||
.mailpoet-icon-logo
|
||||
vertical-align: middle;
|
||||
height: 20px;
|
||||
width: 20px;
|
||||
font-size: 20px;
|
||||
margin-right: 3px;
|
24
assets/css/src/icons.styl
Normal file
24
assets/css/src/icons.styl
Normal file
@ -0,0 +1,24 @@
|
||||
icon-font-path ?= "../fonts"
|
||||
|
||||
@font-face
|
||||
font-family 'mailpoet'
|
||||
src url(icon-font-path + '/mailpoet.ttf?mx0b6n') format('truetype'), url(icon-font-path + '/mailpoet.woff?mx0b6n') format('woff'), url(icon-font-path + '/mailpoet.svg?mx0b6n#mailpoet') format('svg')
|
||||
font-weight normal
|
||||
font-style normal
|
||||
|
||||
[class^="mailpoet-icon-"], [class*=" mailpoet-icon-"]
|
||||
font-family 'mailpoet' !important
|
||||
speak none
|
||||
font-style normal
|
||||
font-weight normal
|
||||
font-variant normal
|
||||
text-transform none
|
||||
line-height 1
|
||||
|
||||
/* Better Font Rendering =========== */
|
||||
-webkit-font-smoothing antialiased
|
||||
-moz-osx-font-smoothing grayscale
|
||||
|
||||
.mailpoet-icon-logo
|
||||
&:before
|
||||
content "\e900"
|
@ -45,7 +45,6 @@ body.mailpoet_modal_opened
|
||||
position: absolute
|
||||
z-index: 25
|
||||
top: 48px
|
||||
padding-bottom: 48px
|
||||
margin: 0
|
||||
|
||||
.mailpoet_popup_wrapper
|
||||
@ -54,6 +53,7 @@ body.mailpoet_modal_opened
|
||||
position: relative
|
||||
width: 100%
|
||||
z-index: 0
|
||||
height: 96%
|
||||
|
||||
.mailpoet_overlay_hidden .mailpoet_popup_wrapper
|
||||
border: 1px solid #333
|
||||
@ -75,6 +75,7 @@ body.mailpoet_modal_opened
|
||||
|
||||
.mailpoet_popup_body
|
||||
padding: 10px 10px 10px 10px
|
||||
height: 92%
|
||||
|
||||
// modal panel
|
||||
#mailpoet_modal_overlay.mailpoet_panel_overlay
|
||||
|
@ -179,6 +179,28 @@ select.mailpoet_font-size
|
||||
width: 100%
|
||||
box-sizing: border-box
|
||||
|
||||
.tooltip-help-designer-subject-line div, .tooltip-help-designer-preheader div
|
||||
z-index: 100001
|
||||
|
||||
.tooltip-help-send-preview
|
||||
position: absolute
|
||||
right: 15px
|
||||
|
||||
.tooltip-help-designer-ideal-width
|
||||
color: #656565
|
||||
text-transform: none
|
||||
margin-left: 5px
|
||||
font-weight: normal
|
||||
|
||||
.tooltip-help-designer-styles
|
||||
position: absolute
|
||||
top: 40px
|
||||
|
||||
.tooltip-help-designer-full-width .dashicons
|
||||
line-height 34px
|
||||
.tooltip-help-designer-full-width span
|
||||
line-height 1.4em
|
||||
|
||||
.mailpoet_button_primary
|
||||
border-color: $button-primary-border-color
|
||||
background-color: $button-primary-background-color
|
||||
|
@ -48,3 +48,41 @@ $resize-handle-z-index = 2
|
||||
|
||||
.mailpoet_resize_handle
|
||||
display: inline-block
|
||||
|
||||
|
||||
.mailpoet_image_resize_handle_container
|
||||
position: absolute
|
||||
bottom: 0
|
||||
right: 0
|
||||
width: 20px
|
||||
height: 20px
|
||||
|
||||
.mailpoet_image_resize_handle
|
||||
position: relative
|
||||
background: $resize-handle-background-color
|
||||
border-radius(3px)
|
||||
display: inline-block
|
||||
width: 20px
|
||||
height: 20px
|
||||
cursor: nwse-resize
|
||||
z-index: $resize-handle-z-index
|
||||
|
||||
.mailpoet_image_resize_handle_text,
|
||||
.mailpoet_image_resize_handle_icon
|
||||
pointer-events: none
|
||||
|
||||
.mailpoet_image_resize_handle_icon
|
||||
position: absolute
|
||||
top: 0
|
||||
right: 0
|
||||
|
||||
& > svg
|
||||
width: 100%
|
||||
height: 100%
|
||||
fill: $resize-handle-font-color
|
||||
|
||||
.mailpoet_block.mailpoet_image_resize_active > .mailpoet_block_highlight
|
||||
border: 1px dashed $resize-active-color
|
||||
|
||||
.mailpoet_image_resize_handle
|
||||
display: inline-block
|
||||
|
@ -23,8 +23,10 @@ $block-text-line-height = $text-line-height
|
||||
border: 1px solid $transparent-color
|
||||
|
||||
&:hover > .mailpoet_block_highlight
|
||||
&.mailpoet_highlight > .mailpoet_block_highlight
|
||||
border: 1px dashed $block-hover-highlight-color
|
||||
|
||||
&.mailpoet_highlight > .mailpoet_block_highlight
|
||||
border: 1px dashed $block-hover-highlight-color !important
|
||||
|
||||
.mailpoet_content
|
||||
position: relative
|
||||
|
@ -3,14 +3,19 @@
|
||||
img
|
||||
vertical-align: bottom
|
||||
max-width: 100%
|
||||
width: auto
|
||||
height: auto
|
||||
|
||||
&.mailpoet_full_image
|
||||
padding-left: 0
|
||||
padding-right: 0
|
||||
margin: auto
|
||||
margin-bottom: 0
|
||||
|
||||
.mailpoet_content a:hover
|
||||
cursor: all-scroll
|
||||
.mailpoet_content
|
||||
margin: auto
|
||||
max-width: 100%
|
||||
min-width: 36px
|
||||
|
||||
a:hover
|
||||
cursor: all-scroll
|
||||
|
||||
|
@ -127,9 +127,6 @@ body
|
||||
background-color: $primary-background-color
|
||||
border: 1px solid $content-border-color
|
||||
|
||||
#mailpoet_modal_close
|
||||
display: none
|
||||
|
||||
.wrap > .mailpoet_notice,
|
||||
.notice
|
||||
.update-nag
|
||||
|
@ -2,7 +2,7 @@ animation-slide-open-downwards($max-height = 2000px)
|
||||
transition: all 250ms cubic-bezier(0.420, 0.000, 0.580, 1.000) /* ease-in-out */
|
||||
max-height: $max-height
|
||||
opacity: 1
|
||||
overflow-y: hidden
|
||||
overflow-y: inherit
|
||||
|
||||
&.mailpoet_closed
|
||||
max-height: 0px
|
||||
|
@ -33,3 +33,6 @@ Custom styles for MailPoet pages.
|
||||
|
||||
p.top-space-triple
|
||||
margin-top: 3em
|
||||
|
||||
p.mailpoet-top-text
|
||||
margin-right: 0
|
||||
|
@ -54,11 +54,23 @@
|
||||
#mailpoet_mta_activate
|
||||
visibility hidden
|
||||
|
||||
.tooltip.dashicons.dashicons-editor-help
|
||||
line-height: 1.4
|
||||
|
||||
ul.sending-method-benefits
|
||||
list-style-type: none
|
||||
margin-bottom: 2em
|
||||
margin-top: 2em
|
||||
|
||||
.sending-free-plan-button
|
||||
background: #FF5301
|
||||
border-color: #e64c03
|
||||
text-shadow: 0 -1px 1px #e64c03
|
||||
box-shadow: 0 1px 0 #e64c03
|
||||
margin: 10px 0
|
||||
strong
|
||||
text-transform: uppercase
|
||||
|
||||
.mailpoet_success_item::before
|
||||
content '✔ '
|
||||
|
||||
|
11
assets/fonts/mailpoet.svg
Normal file
11
assets/fonts/mailpoet.svg
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >
|
||||
<svg xmlns="http://www.w3.org/2000/svg">
|
||||
<metadata>Generated by IcoMoon</metadata>
|
||||
<defs>
|
||||
<font id="mailpoet" horiz-adv-x="1024">
|
||||
<font-face units-per-em="1024" ascent="960" descent="-64" />
|
||||
<missing-glyph horiz-adv-x="1024" />
|
||||
<glyph unicode=" " horiz-adv-x="0" d="" />
|
||||
<glyph unicode="" glyph-name="optimised" horiz-adv-x="972" d="M230.188 949.695c-21.982-3.361-41.376-14.741-48.618-28.188l-5.948-11.637 0.517-265.588c0.776-263.779 0.776-265.847 6.206-273.088 11.12-15.258 40.601-22.24 68.79-16.551 16.551 3.621 25.861 9.827 32.584 21.723 3.879 7.499 4.397 23.791 5.689 185.161l1.293 176.628 60.514-161.111c33.102-88.702 63.875-168.612 68.013-177.404 13.707-29.481 35.687-41.376 72.151-39.049 21.206 1.293 39.308 9.827 47.584 22.499 3.361 5.172 35.947 91.806 72.41 192.662s67.237 185.42 68.53 187.49c1.551 2.587 2.587-69.307 2.587-185.937v-190.335l5.948-11.379c8.533-16.809 20.172-21.982 49.652-21.982 27.929 0.259 39.825 4.914 49.911 20.172l6.982 10.603v530.401l-5.689 9.31c-12.671 20.43-50.17 31.033-91.806 25.601-34.394-4.138-53.79-16.292-66.72-41.118-2.587-5.172-35.947-101.89-73.961-214.902s-69.824-206.367-70.6-207.403c-1.034-1.034-32.326 86.115-69.824 193.954-37.757 107.581-71.892 205.075-76.030 216.453-10.086 26.118-25.601 42.929-45.514 48.877-17.326 5.172-46.807 6.982-64.652 4.138zM54.854 243.443c-20.172-3.879-43.963-19.136-51.204-33.619-6.206-11.379-4.914-32.843 2.587-47.841 23.533-46.807 71.634-86.892 126.717-104.736 17.068-5.689 23.274-5.948 120.252-7.499 97.235-1.551 102.926-1.81 116.373-7.241 29.739-11.896 51.204-35.687 61.807-68.013 3.621-11.12 13.964-21.206 25.861-25.344 4.914-1.551 18.361-2.844 29.739-2.844 16.809 0 23.533 1.293 32.584 5.689 11.896 6.206 13.964 9.31 26.895 38.791 11.896 27.671 39.567 49.652 70.858 56.117 8.533 1.81 47.067 2.844 100.856 2.844 99.563 0 113.786 2.068 151.801 20.689 49.652 24.567 96.978 77.84 101.373 113.529 3.104 26.118-17.326 49.394-51.204 58.187-25.601 6.465-41.635-0.517-54.825-24.050-11.12-19.655-29.998-38.015-47.841-46.29l-14.741-6.982-99.563-1.551c-90.77-1.293-101.373-2.068-120.252-6.982-27.154-7.499-58.444-23.016-80.427-40.084l-17.844-13.964-16.809 13.964c-20.689 16.809-51.462 32.584-78.875 39.825-19.136 5.172-28.705 5.948-120.252 7.241l-99.563 1.551-15.775 7.241c-18.102 8.533-32.584 21.982-48.36 45.773-16.034 24.567-26.895 29.998-50.17 25.601z" />
|
||||
</font></defs></svg>
|
After Width: | Height: | Size: 2.4 KiB |
BIN
assets/fonts/mailpoet.ttf
Normal file
BIN
assets/fonts/mailpoet.ttf
Normal file
Binary file not shown.
BIN
assets/fonts/mailpoet.woff
Normal file
BIN
assets/fonts/mailpoet.woff
Normal file
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 819 B After Width: | Height: | Size: 814 B |
@ -1,12 +1,12 @@
|
||||
define('admin', [
|
||||
'jquery'
|
||||
],
|
||||
function(jQuery) {
|
||||
jQuery(function($) {
|
||||
// dom ready
|
||||
$(function() {
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
define('admin', [
|
||||
'jquery'
|
||||
],
|
||||
function (jQuery) {
|
||||
jQuery(function ($) {
|
||||
// dom ready
|
||||
$(function () {
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
|
@ -2,84 +2,86 @@ function requestFailed(errorMessage, xhr) {
|
||||
if (xhr.responseJSON) {
|
||||
return xhr.responseJSON;
|
||||
}
|
||||
var message = errorMessage.replace("%d", xhr.status);
|
||||
return {
|
||||
errors: [
|
||||
{
|
||||
message: message
|
||||
message: errorMessage.replace('%d', xhr.status)
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
define('ajax', ['mailpoet', 'jquery', 'underscore'], function(MailPoet, jQuery, _) {
|
||||
define('ajax', ['mailpoet', 'jquery', 'underscore'], function (mp, jQuery, _) {
|
||||
var MailPoet = mp;
|
||||
|
||||
MailPoet.Ajax = {
|
||||
version: 0.5,
|
||||
options: {},
|
||||
defaults: {
|
||||
url: null,
|
||||
api_version: null,
|
||||
endpoint: null,
|
||||
action: null,
|
||||
token: null,
|
||||
data: {}
|
||||
},
|
||||
post: function(options) {
|
||||
return this.request('post', options);
|
||||
},
|
||||
init: function(options) {
|
||||
// merge options
|
||||
this.options = jQuery.extend({}, this.defaults, options);
|
||||
version: 0.5,
|
||||
options: {},
|
||||
defaults: {
|
||||
url: null,
|
||||
api_version: null,
|
||||
endpoint: null,
|
||||
action: null,
|
||||
token: null,
|
||||
data: {}
|
||||
},
|
||||
post: function (options) {
|
||||
return this.request('post', options);
|
||||
},
|
||||
init: function (options) {
|
||||
// merge options
|
||||
this.options = jQuery.extend({}, this.defaults, options);
|
||||
|
||||
// set default url
|
||||
if(this.options.url === null) {
|
||||
this.options.url = ajaxurl;
|
||||
}
|
||||
// set default url
|
||||
if (this.options.url === null) {
|
||||
this.options.url = window.ajaxurl;
|
||||
}
|
||||
|
||||
// set default token
|
||||
if(this.options.token === null) {
|
||||
this.options.token = window.mailpoet_token;
|
||||
}
|
||||
},
|
||||
getParams: function() {
|
||||
return {
|
||||
action: 'mailpoet',
|
||||
api_version: this.options.api_version,
|
||||
token: this.options.token,
|
||||
endpoint: this.options.endpoint,
|
||||
method: this.options.action,
|
||||
data: this.options.data || {}
|
||||
};
|
||||
},
|
||||
request: function(method, options) {
|
||||
// set options
|
||||
this.init(options);
|
||||
// set default token
|
||||
if (this.options.token === null) {
|
||||
this.options.token = window.mailpoet_token;
|
||||
}
|
||||
},
|
||||
getParams: function () {
|
||||
return {
|
||||
action: 'mailpoet',
|
||||
api_version: this.options.api_version,
|
||||
token: this.options.token,
|
||||
endpoint: this.options.endpoint,
|
||||
method: this.options.action,
|
||||
data: this.options.data || {}
|
||||
};
|
||||
},
|
||||
request: function (method, options) {
|
||||
var params;
|
||||
var deferred;
|
||||
// set options
|
||||
this.init(options);
|
||||
|
||||
// set request params
|
||||
var params = this.getParams();
|
||||
// set request params
|
||||
params = this.getParams();
|
||||
|
||||
// remove null values from the data object
|
||||
if (_.isObject(params.data)) {
|
||||
params.data = _.pick(params.data, function(value) {
|
||||
return (value !== null);
|
||||
});
|
||||
}
|
||||
// remove null values from the data object
|
||||
if (_.isObject(params.data)) {
|
||||
params.data = _.pick(params.data, function (value) {
|
||||
return (value !== null);
|
||||
});
|
||||
}
|
||||
|
||||
// ajax request
|
||||
var deferred = jQuery.post(
|
||||
// ajax request
|
||||
deferred = jQuery.post(
|
||||
this.options.url,
|
||||
params,
|
||||
null,
|
||||
'json'
|
||||
).then(function(data) {
|
||||
).then(function (data) {
|
||||
return data;
|
||||
}, _.partial(requestFailed, MailPoet.I18n.t('ajaxFailedErrorMessage')));
|
||||
|
||||
// clear options
|
||||
this.options = {};
|
||||
this.options = {};
|
||||
|
||||
return deferred;
|
||||
}
|
||||
return deferred;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
@ -17,14 +17,15 @@
|
||||
*/
|
||||
var eventsCache = [];
|
||||
|
||||
function track(name, data){
|
||||
if (typeof window.mixpanel.track !== "function") {
|
||||
function track(name, data) {
|
||||
if (typeof window.mixpanel.track !== 'function') {
|
||||
window.mixpanel.init(window.mixpanelTrackingId);
|
||||
}
|
||||
window.mixpanel.track(name, data);
|
||||
}
|
||||
|
||||
function exportMixpanel(MailPoet) {
|
||||
function exportMixpanel(mp) {
|
||||
var MailPoet = mp;
|
||||
MailPoet.forceTrackEvent = track;
|
||||
|
||||
if (window.mailpoet_analytics_enabled) {
|
||||
@ -37,20 +38,11 @@ function exportMixpanel(MailPoet) {
|
||||
function trackCachedEvents() {
|
||||
eventsCache.map(function (event) {
|
||||
if (window.mailpoet_analytics_enabled || event.forced) {
|
||||
window.mixpanel.track(event.name, event.data)
|
||||
window.mixpanel.track(event.name, event.data);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function initializeMixpanelWhenLoaded() {
|
||||
if (typeof window.mixpanel === "object") {
|
||||
exportMixpanel(MailPoet);
|
||||
trackCachedEvents();
|
||||
} else {
|
||||
setTimeout(initializeMixpanelWhenLoaded, 100);
|
||||
}
|
||||
}
|
||||
|
||||
function cacheEvent(forced, name, data) {
|
||||
eventsCache.push({
|
||||
name: name,
|
||||
@ -61,7 +53,17 @@ function cacheEvent(forced, name, data) {
|
||||
|
||||
define(
|
||||
['mailpoet', 'underscore'],
|
||||
function(MailPoet, _) {
|
||||
function (mp, _) {
|
||||
var MailPoet = mp;
|
||||
|
||||
function initializeMixpanelWhenLoaded() {
|
||||
if (typeof window.mixpanel === 'object') {
|
||||
exportMixpanel(MailPoet);
|
||||
trackCachedEvents();
|
||||
} else {
|
||||
setTimeout(initializeMixpanelWhenLoaded, 100);
|
||||
}
|
||||
}
|
||||
|
||||
MailPoet.trackEvent = _.partial(cacheEvent, false);
|
||||
MailPoet.forceTrackEvent = _.partial(cacheEvent, true);
|
||||
|
@ -3,164 +3,172 @@ define('date',
|
||||
'mailpoet',
|
||||
'jquery',
|
||||
'moment'
|
||||
], function(
|
||||
MailPoet,
|
||||
], function (
|
||||
mp,
|
||||
jQuery,
|
||||
Moment
|
||||
) {
|
||||
'use strict';
|
||||
'use strict';
|
||||
|
||||
MailPoet.Date = {
|
||||
version: 0.1,
|
||||
options: {},
|
||||
defaults: {
|
||||
offset: 0,
|
||||
format: 'F, d Y H:i:s'
|
||||
},
|
||||
init: function(options) {
|
||||
options = options || {};
|
||||
var MailPoet = mp;
|
||||
|
||||
MailPoet.Date = {
|
||||
version: 0.1,
|
||||
options: {},
|
||||
defaults: {
|
||||
offset: 0,
|
||||
format: 'F, d Y H:i:s'
|
||||
},
|
||||
init: function (opts) {
|
||||
var options = opts || {};
|
||||
|
||||
// set UTC offset
|
||||
if (
|
||||
if (
|
||||
options.offset === undefined
|
||||
&& window.mailpoet_date_offset !== undefined
|
||||
) {
|
||||
options.offset = window.mailpoet_date_offset;
|
||||
}
|
||||
options.offset = window.mailpoet_date_offset;
|
||||
}
|
||||
// set date format
|
||||
if (
|
||||
if (
|
||||
options.format === undefined
|
||||
&& window.mailpoet_date_format !== undefined
|
||||
) {
|
||||
options.format = window.mailpoet_date_format;
|
||||
}
|
||||
// merge options
|
||||
this.options = jQuery.extend({}, this.defaults, options);
|
||||
|
||||
return this;
|
||||
},
|
||||
format: function(date, options) {
|
||||
options = options || {};
|
||||
this.init(options);
|
||||
|
||||
var date = Moment(date, this.convertFormat(options.parseFormat));
|
||||
if (options.offset === 0) date = date.utc();
|
||||
return date.format(this.convertFormat(this.options.format));
|
||||
},
|
||||
toDate: function(date, options) {
|
||||
options = options || {};
|
||||
this.init(options);
|
||||
|
||||
return Moment(date, this.convertFormat(options.parseFormat)).toDate();
|
||||
},
|
||||
short: function(date) {
|
||||
return this.format(date, {
|
||||
format: 'F, j Y'
|
||||
});
|
||||
},
|
||||
full: function(date) {
|
||||
return this.format(date, {
|
||||
format: 'F, j Y H:i:s'
|
||||
});
|
||||
},
|
||||
time: function(date) {
|
||||
return this.format(date, {
|
||||
format: 'H:i:s'
|
||||
});
|
||||
},
|
||||
convertFormat: function(format) {
|
||||
var format_mappings = {
|
||||
date: {
|
||||
d: 'DD',
|
||||
D: 'ddd',
|
||||
j: 'D',
|
||||
l: 'dddd',
|
||||
N: 'E',
|
||||
S: 'o',
|
||||
w: 'e',
|
||||
z: 'DDD',
|
||||
W: 'W',
|
||||
F: 'MMMM',
|
||||
m: 'MM',
|
||||
M: 'MMM',
|
||||
n: 'M',
|
||||
t: '', // no equivalent
|
||||
L: '', // no equivalent
|
||||
o: 'YYYY',
|
||||
Y: 'YYYY',
|
||||
y: 'YY',
|
||||
a: 'a',
|
||||
A: 'A',
|
||||
B: '', // no equivalent
|
||||
g: 'h',
|
||||
G: 'H',
|
||||
h: 'hh',
|
||||
H: 'HH',
|
||||
i: 'mm',
|
||||
s: 'ss',
|
||||
u: 'SSS',
|
||||
e: 'zz', // deprecated since version 1.6.0 of moment.js
|
||||
I: '', // no equivalent
|
||||
O: '', // no equivalent
|
||||
P: '', // no equivalent
|
||||
T: '', // no equivalent
|
||||
Z: '', // no equivalent
|
||||
c: '', // no equivalent
|
||||
r: '', // no equivalent
|
||||
U: 'X'
|
||||
},
|
||||
strftime: {
|
||||
a: 'ddd',
|
||||
A: 'dddd',
|
||||
b: 'MMM',
|
||||
B: 'MMMM',
|
||||
d: 'DD',
|
||||
e: 'D',
|
||||
F: 'YYYY-MM-DD',
|
||||
H: 'HH',
|
||||
I: 'hh',
|
||||
j: 'DDDD',
|
||||
k: 'H',
|
||||
l: 'h',
|
||||
m: 'MM',
|
||||
M: 'mm',
|
||||
p: 'A',
|
||||
S: 'ss',
|
||||
u: 'E',
|
||||
w: 'd',
|
||||
W: 'WW',
|
||||
y: 'YY',
|
||||
Y: 'YYYY',
|
||||
z: 'ZZ',
|
||||
Z: 'z'
|
||||
options.format = window.mailpoet_date_format;
|
||||
}
|
||||
};
|
||||
// merge options
|
||||
this.options = jQuery.extend({}, this.defaults, options);
|
||||
|
||||
if (!format || format.length <= 0) return format;
|
||||
return this;
|
||||
},
|
||||
format: function (date, opts) {
|
||||
var options = opts || {};
|
||||
var momentDate;
|
||||
this.init(options);
|
||||
|
||||
var replacements = format_mappings['date'];
|
||||
momentDate = Moment(date, this.convertFormat(options.parseFormat));
|
||||
if (options.offset === 0) momentDate = momentDate.utc();
|
||||
return momentDate.format(this.convertFormat(this.options.format));
|
||||
},
|
||||
toDate: function (date, opts) {
|
||||
var options = opts || {};
|
||||
this.init(options);
|
||||
|
||||
var convertedFormat = [];
|
||||
var escapeToken = false;
|
||||
return Moment(date, this.convertFormat(options.parseFormat)).toDate();
|
||||
},
|
||||
short: function (date) {
|
||||
return this.format(date, {
|
||||
format: 'F, j Y'
|
||||
});
|
||||
},
|
||||
full: function (date) {
|
||||
return this.format(date, {
|
||||
format: 'F, j Y H:i:s'
|
||||
});
|
||||
},
|
||||
time: function (date) {
|
||||
return this.format(date, {
|
||||
format: 'H:i:s'
|
||||
});
|
||||
},
|
||||
convertFormat: function (format) {
|
||||
var replacements;
|
||||
var convertedFormat;
|
||||
var escapeToken;
|
||||
var index;
|
||||
var token;
|
||||
var format_mappings = {
|
||||
date: {
|
||||
d: 'DD',
|
||||
D: 'ddd',
|
||||
j: 'D',
|
||||
l: 'dddd',
|
||||
N: 'E',
|
||||
S: 'o',
|
||||
w: 'e',
|
||||
z: 'DDD',
|
||||
W: 'W',
|
||||
F: 'MMMM',
|
||||
m: 'MM',
|
||||
M: 'MMM',
|
||||
n: 'M',
|
||||
t: '', // no equivalent
|
||||
L: '', // no equivalent
|
||||
o: 'YYYY',
|
||||
Y: 'YYYY',
|
||||
y: 'YY',
|
||||
a: 'a',
|
||||
A: 'A',
|
||||
B: '', // no equivalent
|
||||
g: 'h',
|
||||
G: 'H',
|
||||
h: 'hh',
|
||||
H: 'HH',
|
||||
i: 'mm',
|
||||
s: 'ss',
|
||||
u: 'SSS',
|
||||
e: 'zz', // deprecated since version 1.6.0 of moment.js
|
||||
I: '', // no equivalent
|
||||
O: '', // no equivalent
|
||||
P: '', // no equivalent
|
||||
T: '', // no equivalent
|
||||
Z: '', // no equivalent
|
||||
c: '', // no equivalent
|
||||
r: '', // no equivalent
|
||||
U: 'X'
|
||||
},
|
||||
strftime: {
|
||||
a: 'ddd',
|
||||
A: 'dddd',
|
||||
b: 'MMM',
|
||||
B: 'MMMM',
|
||||
d: 'DD',
|
||||
e: 'D',
|
||||
F: 'YYYY-MM-DD',
|
||||
H: 'HH',
|
||||
I: 'hh',
|
||||
j: 'DDDD',
|
||||
k: 'H',
|
||||
l: 'h',
|
||||
m: 'MM',
|
||||
M: 'mm',
|
||||
p: 'A',
|
||||
S: 'ss',
|
||||
u: 'E',
|
||||
w: 'd',
|
||||
W: 'WW',
|
||||
y: 'YY',
|
||||
Y: 'YYYY',
|
||||
z: 'ZZ',
|
||||
Z: 'z'
|
||||
}
|
||||
};
|
||||
|
||||
for(var index = 0, token = ''; token = format.charAt(index); index++){
|
||||
if (escapeToken === true) {
|
||||
convertedFormat.push('['+token+']');
|
||||
escapeToken = false;
|
||||
} else {
|
||||
if (token === '\\') {
|
||||
// Slash escapes the next symbol to be treated as literal
|
||||
escapeToken = true;
|
||||
continue;
|
||||
} else if (replacements[token] !== undefined) {
|
||||
convertedFormat.push(replacements[token]);
|
||||
if (!format || format.length <= 0) return format;
|
||||
|
||||
replacements = format_mappings['date'];
|
||||
convertedFormat = [];
|
||||
escapeToken = false;
|
||||
|
||||
for (index = 0, token = ''; format.charAt(index); index += 1) {
|
||||
token = format.charAt(index);
|
||||
if (escapeToken === true) {
|
||||
convertedFormat.push('[' + token + ']');
|
||||
escapeToken = false;
|
||||
} else {
|
||||
convertedFormat.push('['+token+']');
|
||||
if (token === '\\') {
|
||||
// Slash escapes the next symbol to be treated as literal
|
||||
escapeToken = true;
|
||||
continue;
|
||||
} else if (replacements[token] !== undefined) {
|
||||
convertedFormat.push(replacements[token]);
|
||||
} else {
|
||||
convertedFormat.push('[' + token + ']');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return convertedFormat.join('');
|
||||
}
|
||||
};
|
||||
});
|
||||
return convertedFormat.join('');
|
||||
}
|
||||
};
|
||||
});
|
||||
|
@ -20,15 +20,15 @@ define([
|
||||
const options = Object.keys(this.props.field.values).map(
|
||||
(value, index) => {
|
||||
return (
|
||||
<p key={ 'checkbox-' + index }>
|
||||
<p key={'checkbox-' + index}>
|
||||
<label>
|
||||
<input
|
||||
ref="checkbox"
|
||||
type="checkbox"
|
||||
value="1"
|
||||
checked={ isChecked }
|
||||
onChange={ this.onValueChange }
|
||||
name={ this.props.field.name }
|
||||
checked={isChecked}
|
||||
onChange={this.onValueChange}
|
||||
name={this.props.field.name}
|
||||
/>
|
||||
{ this.props.field.values[value] }
|
||||
</label>
|
||||
|
@ -12,7 +12,7 @@ define([
|
||||
|
||||
if (this.props.placeholder !== undefined) {
|
||||
years.push((
|
||||
<option value="" key={ 0 }>{ this.props.placeholder }</option>
|
||||
<option value="" key={0}>{ this.props.placeholder }</option>
|
||||
));
|
||||
}
|
||||
|
||||
@ -20,16 +20,16 @@ define([
|
||||
for (let i = currentYear; i >= currentYear - yearsRange; i -= 1) {
|
||||
years.push((
|
||||
<option
|
||||
key={ i }
|
||||
value={ i }
|
||||
key={i}
|
||||
value={i}
|
||||
>{ i }</option>
|
||||
));
|
||||
}
|
||||
return (
|
||||
<select
|
||||
name={ `${this.props.name}[year]` }
|
||||
value={ this.props.year }
|
||||
onChange={ this.props.onValueChange }
|
||||
name={`${this.props.name}[year]`}
|
||||
value={this.props.year}
|
||||
onChange={this.props.onValueChange}
|
||||
>
|
||||
{ years }
|
||||
</select>
|
||||
@ -43,23 +43,23 @@ define([
|
||||
|
||||
if (this.props.placeholder !== undefined) {
|
||||
months.push((
|
||||
<option value="" key={ 0 }>{ this.props.placeholder }</option>
|
||||
<option value="" key={0}>{ this.props.placeholder }</option>
|
||||
));
|
||||
}
|
||||
|
||||
for (let i = 1; i <= 12; i += 1) {
|
||||
months.push((
|
||||
<option
|
||||
key={ i }
|
||||
value={ i }
|
||||
key={i}
|
||||
value={i}
|
||||
>{ this.props.monthNames[i - 1] }</option>
|
||||
));
|
||||
}
|
||||
return (
|
||||
<select
|
||||
name={ `${this.props.name}[month]` }
|
||||
value={ this.props.month }
|
||||
onChange={ this.props.onValueChange }
|
||||
name={`${this.props.name}[month]`}
|
||||
value={this.props.month}
|
||||
onChange={this.props.onValueChange}
|
||||
>
|
||||
{ months }
|
||||
</select>
|
||||
@ -73,24 +73,24 @@ define([
|
||||
|
||||
if (this.props.placeholder !== undefined) {
|
||||
days.push((
|
||||
<option value="" key={ 0 }>{ this.props.placeholder }</option>
|
||||
<option value="" key={0}>{ this.props.placeholder }</option>
|
||||
));
|
||||
}
|
||||
|
||||
for (let i = 1; i <= 31; i += 1) {
|
||||
days.push((
|
||||
<option
|
||||
key={ i }
|
||||
value={ i }
|
||||
key={i}
|
||||
value={i}
|
||||
>{ i }</option>
|
||||
));
|
||||
}
|
||||
|
||||
return (
|
||||
<select
|
||||
name={ `${this.props.name}[day]` }
|
||||
value={ this.props.day }
|
||||
onChange={ this.props.onValueChange }
|
||||
name={`${this.props.name}[day]`}
|
||||
value={this.props.day}
|
||||
onChange={this.props.onValueChange}
|
||||
>
|
||||
{ days }
|
||||
</select>
|
||||
@ -123,7 +123,7 @@ define([
|
||||
? this.props.item[this.props.field.name].trim()
|
||||
: '';
|
||||
|
||||
if(value === '') {
|
||||
if (value === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -140,31 +140,31 @@ define([
|
||||
|
||||
let value;
|
||||
|
||||
switch(dateType) {
|
||||
switch (dateType) {
|
||||
case 'year_month_day':
|
||||
value = {
|
||||
'year': this.state.year,
|
||||
'month': this.state.month,
|
||||
'day': this.state.day,
|
||||
year: this.state.year,
|
||||
month: this.state.month,
|
||||
day: this.state.day,
|
||||
};
|
||||
break;
|
||||
|
||||
case 'year_month':
|
||||
value = {
|
||||
'year': this.state.year,
|
||||
'month': this.state.month,
|
||||
year: this.state.year,
|
||||
month: this.state.month,
|
||||
};
|
||||
break;
|
||||
|
||||
case 'month':
|
||||
value = {
|
||||
'month': this.state.month,
|
||||
month: this.state.month,
|
||||
};
|
||||
break;
|
||||
|
||||
case 'year':
|
||||
value = {
|
||||
'year': this.state.year,
|
||||
year: this.state.year,
|
||||
};
|
||||
break;
|
||||
}
|
||||
@ -202,40 +202,37 @@ define([
|
||||
const dateSelects = dateFormats[dateType][0].split('/');
|
||||
|
||||
const fields = dateSelects.map((type) => {
|
||||
switch(type) {
|
||||
switch (type) {
|
||||
case 'YYYY':
|
||||
return (<FormFieldDateYear
|
||||
onValueChange={ this.onValueChange.bind(this) }
|
||||
ref={ 'year' }
|
||||
key={ 'year' }
|
||||
name={ this.props.field.name }
|
||||
year={ this.state.year }
|
||||
placeholder={ this.props.field.year_placeholder }
|
||||
onValueChange={this.onValueChange.bind(this)}
|
||||
ref={'year'}
|
||||
key={'year'}
|
||||
name={this.props.field.name}
|
||||
year={this.state.year}
|
||||
placeholder={this.props.field.year_placeholder}
|
||||
/>);
|
||||
break;
|
||||
|
||||
case 'MM':
|
||||
return (<FormFieldDateMonth
|
||||
onValueChange={ this.onValueChange.bind(this) }
|
||||
ref={ 'month' }
|
||||
key={ 'month' }
|
||||
name={ this.props.field.name }
|
||||
month={ this.state.month }
|
||||
monthNames={ monthNames }
|
||||
placeholder={ this.props.field.month_placeholder }
|
||||
onValueChange={this.onValueChange.bind(this)}
|
||||
ref={'month'}
|
||||
key={'month'}
|
||||
name={this.props.field.name}
|
||||
month={this.state.month}
|
||||
monthNames={monthNames}
|
||||
placeholder={this.props.field.month_placeholder}
|
||||
/>);
|
||||
break;
|
||||
|
||||
case 'DD':
|
||||
return (<FormFieldDateDay
|
||||
onValueChange={ this.onValueChange.bind(this) }
|
||||
ref={ 'day' }
|
||||
key={ 'day' }
|
||||
name={ this.props.field.name }
|
||||
day={ this.state.day }
|
||||
placeholder={ this.props.field.day_placeholder }
|
||||
onValueChange={this.onValueChange.bind(this)}
|
||||
ref={'day'}
|
||||
key={'day'}
|
||||
name={this.props.field.name}
|
||||
day={this.state.day}
|
||||
placeholder={this.props.field.day_placeholder}
|
||||
/>);
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
@ -245,7 +242,7 @@ define([
|
||||
</div>
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return FormFieldDate;
|
||||
});
|
||||
|
@ -7,6 +7,7 @@ define([
|
||||
'form/fields/checkbox.jsx',
|
||||
'form/fields/selection.jsx',
|
||||
'form/fields/date.jsx',
|
||||
'jquery',
|
||||
],
|
||||
(
|
||||
React,
|
||||
@ -16,24 +17,26 @@ define([
|
||||
FormFieldRadio,
|
||||
FormFieldCheckbox,
|
||||
FormFieldSelection,
|
||||
FormFieldDate
|
||||
FormFieldDate,
|
||||
jQuery
|
||||
) => {
|
||||
const FormField = React.createClass({
|
||||
renderField: function (data, inline = false) {
|
||||
let description = false;
|
||||
if(data.field.description) {
|
||||
if (data.field.description) {
|
||||
description = (
|
||||
<p className="description">{ data.field.description }</p>
|
||||
);
|
||||
}
|
||||
|
||||
let field = false;
|
||||
let dataField = data.field;
|
||||
|
||||
if(data.field['field'] !== undefined) {
|
||||
data.field = jQuery.merge(data.field, data.field.field);
|
||||
if (data.field['field'] !== undefined) {
|
||||
dataField = jQuery.merge(dataField, data.field.field);
|
||||
}
|
||||
|
||||
switch(data.field.type) {
|
||||
switch (dataField.type) {
|
||||
case 'text':
|
||||
field = (<FormFieldText {...data} />);
|
||||
break;
|
||||
@ -67,16 +70,16 @@ define([
|
||||
break;
|
||||
}
|
||||
|
||||
if(inline === true) {
|
||||
if (inline === true) {
|
||||
return (
|
||||
<span key={ 'field-' + (data.index || 0) }>
|
||||
<span key={'field-' + (data.index || 0)}>
|
||||
{ field }
|
||||
{ description }
|
||||
</span>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<div key={ 'field-' + (data.index || 0) }>
|
||||
<div key={'field-' + (data.index || 0)}>
|
||||
{ field }
|
||||
{ description }
|
||||
</div>
|
||||
@ -86,7 +89,7 @@ define([
|
||||
render: function () {
|
||||
let field = false;
|
||||
|
||||
if(this.props.field['fields'] !== undefined) {
|
||||
if (this.props.field['fields'] !== undefined) {
|
||||
field = this.props.field.fields.map((subfield, index) => {
|
||||
return this.renderField({
|
||||
index: index,
|
||||
@ -100,7 +103,7 @@ define([
|
||||
}
|
||||
|
||||
let tip = false;
|
||||
if(this.props.field.tip) {
|
||||
if (this.props.field.tip) {
|
||||
tip = (
|
||||
<p className="description">{ this.props.field.tip }</p>
|
||||
);
|
||||
@ -110,7 +113,7 @@ define([
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label
|
||||
htmlFor={ 'field_'+this.props.field.name }
|
||||
htmlFor={'field_' + this.props.field.name}
|
||||
>
|
||||
{ this.props.field.label }
|
||||
{ tip }
|
||||
|
@ -14,14 +14,14 @@ define([
|
||||
const options = Object.keys(this.props.field.values).map(
|
||||
(value, index) => {
|
||||
return (
|
||||
<p key={ 'radio-' + index }>
|
||||
<p key={'radio-' + index}>
|
||||
<label>
|
||||
<input
|
||||
type="radio"
|
||||
checked={ selected_value === value }
|
||||
value={ value }
|
||||
onChange={ this.props.onValueChange }
|
||||
name={ this.props.field.name } />
|
||||
checked={selected_value === value}
|
||||
value={value}
|
||||
onChange={this.props.onValueChange}
|
||||
name={this.props.field.name} />
|
||||
{ this.props.field.values[value] }
|
||||
</label>
|
||||
</p>
|
||||
|
@ -50,8 +50,8 @@ const FormFieldSelect = React.createClass({
|
||||
|
||||
return (
|
||||
<option
|
||||
key={ 'option-' + index }
|
||||
value={ value }>
|
||||
key={'option-' + index}
|
||||
value={value}>
|
||||
{ this.props.field.values[value] }
|
||||
</option>
|
||||
);
|
||||
@ -60,10 +60,10 @@ const FormFieldSelect = React.createClass({
|
||||
|
||||
return (
|
||||
<select
|
||||
name={ this.props.field.name }
|
||||
id={ 'field_'+this.props.field.name }
|
||||
value={ this.props.item[this.props.field.name] }
|
||||
onChange={ this.props.onValueChange }
|
||||
name={this.props.field.name}
|
||||
id={'field_' + this.props.field.name}
|
||||
value={this.props.item[this.props.field.name]}
|
||||
onChange={this.props.onValueChange}
|
||||
{...this.props.field.validation}
|
||||
>
|
||||
{placeholder}
|
||||
|
@ -26,42 +26,42 @@ define([
|
||||
return (this.state.select2 === true);
|
||||
},
|
||||
componentDidMount: function () {
|
||||
if(this.allowMultipleValues()) {
|
||||
if (this.allowMultipleValues()) {
|
||||
this.setupSelect2();
|
||||
}
|
||||
},
|
||||
componentDidUpdate: function (prevProps) {
|
||||
if(
|
||||
if (
|
||||
(this.props.item !== undefined && prevProps.item !== undefined)
|
||||
&& (this.props.item.id !== prevProps.item.id)
|
||||
) {
|
||||
jQuery('#'+this.refs.select.id)
|
||||
jQuery('#' + this.refs.select.id)
|
||||
.val(this.getSelectedValues())
|
||||
.trigger('change');
|
||||
}
|
||||
},
|
||||
componentWillUnmount: function () {
|
||||
if(this.allowMultipleValues()) {
|
||||
if (this.allowMultipleValues()) {
|
||||
this.destroySelect2();
|
||||
}
|
||||
},
|
||||
destroySelect2: function () {
|
||||
if(this.isSelect2Initialized()) {
|
||||
jQuery('#'+this.refs.select.id).select2('destroy');
|
||||
if (this.isSelect2Initialized()) {
|
||||
jQuery('#' + this.refs.select.id).select2('destroy');
|
||||
}
|
||||
},
|
||||
setupSelect2: function () {
|
||||
if(this.isSelect2Initialized()) {
|
||||
if (this.isSelect2Initialized()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const select2 = jQuery('#'+this.refs.select.id).select2({
|
||||
const select2 = jQuery('#' + this.refs.select.id).select2({
|
||||
width: (this.props.width || ''),
|
||||
templateResult: function (item) {
|
||||
if(item.element && item.element.selected) {
|
||||
if (item.element && item.element.selected) {
|
||||
return null;
|
||||
} else {
|
||||
if(item.title) {
|
||||
if (item.title) {
|
||||
return item.title;
|
||||
} else {
|
||||
return item.text;
|
||||
@ -75,7 +75,7 @@ define([
|
||||
hasRemoved = true;
|
||||
});
|
||||
select2.on('select2:opening', (e) => {
|
||||
if(hasRemoved === true) {
|
||||
if (hasRemoved === true) {
|
||||
hasRemoved = false;
|
||||
e.preventDefault();
|
||||
}
|
||||
@ -86,9 +86,9 @@ define([
|
||||
this.setState({ select2: true });
|
||||
},
|
||||
getSelectedValues: function () {
|
||||
if(this.props.field['selected'] !== undefined) {
|
||||
if (this.props.field['selected'] !== undefined) {
|
||||
return this.props.field['selected'](this.props.item);
|
||||
} else if(this.props.item !== undefined && this.props.field.name !== undefined) {
|
||||
} else if (this.props.item !== undefined && this.props.field.name !== undefined) {
|
||||
if (this.allowMultipleValues()) {
|
||||
if (Array.isArray(this.props.item[this.props.field.name])) {
|
||||
return this.props.item[this.props.field.name].map((item) => {
|
||||
@ -102,11 +102,11 @@ define([
|
||||
return null;
|
||||
},
|
||||
loadCachedItems: function () {
|
||||
if(typeof(window['mailpoet_'+this.props.field.endpoint]) !== 'undefined') {
|
||||
let items = window['mailpoet_'+this.props.field.endpoint];
|
||||
if (typeof (window['mailpoet_' + this.props.field.endpoint]) !== 'undefined') {
|
||||
let items = window['mailpoet_' + this.props.field.endpoint];
|
||||
|
||||
|
||||
if(this.props.field['filter'] !== undefined) {
|
||||
if (this.props.field['filter'] !== undefined) {
|
||||
items = items.filter(this.props.field.filter);
|
||||
}
|
||||
|
||||
@ -116,9 +116,10 @@ define([
|
||||
}
|
||||
},
|
||||
handleChange: function (e) {
|
||||
if(this.props.onValueChange !== undefined) {
|
||||
if(this.props.field.multiple) {
|
||||
value = jQuery('#'+this.refs.select.id).val();
|
||||
let value;
|
||||
if (this.props.onValueChange !== undefined) {
|
||||
if (this.props.field.multiple) {
|
||||
value = jQuery('#' + this.refs.select.id).val();
|
||||
} else {
|
||||
value = e.target.value;
|
||||
}
|
||||
@ -132,19 +133,19 @@ define([
|
||||
}
|
||||
},
|
||||
getLabel: function (item) {
|
||||
if(this.props.field['getLabel'] !== undefined) {
|
||||
if (this.props.field['getLabel'] !== undefined) {
|
||||
return this.props.field.getLabel(item, this.props.item);
|
||||
}
|
||||
return item.name;
|
||||
},
|
||||
getSearchLabel: function (item) {
|
||||
if(this.props.field['getSearchLabel'] !== undefined) {
|
||||
if (this.props.field['getSearchLabel'] !== undefined) {
|
||||
return this.props.field.getSearchLabel(item, this.props.item);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
getValue: function (item) {
|
||||
if(this.props.field['getValue'] !== undefined) {
|
||||
if (this.props.field['getValue'] !== undefined) {
|
||||
return this.props.field.getValue(item, this.props.item);
|
||||
}
|
||||
return item.id;
|
||||
@ -153,7 +154,7 @@ define([
|
||||
// this function may be used to transform the placeholder value into
|
||||
// desired value.
|
||||
transformChangedValue: function (value) {
|
||||
if(typeof this.props.field['transformChangedValue'] === 'function') {
|
||||
if (typeof this.props.field['transformChangedValue'] === 'function') {
|
||||
return this.props.field.transformChangedValue.call(this, value);
|
||||
} else {
|
||||
return value;
|
||||
@ -167,9 +168,9 @@ define([
|
||||
|
||||
return (
|
||||
<option
|
||||
key={ 'option-'+index }
|
||||
value={ value }
|
||||
title={ searchLabel }
|
||||
key={'option-' + index}
|
||||
value={value}
|
||||
title={searchLabel}
|
||||
>
|
||||
{ label }
|
||||
</option>
|
||||
@ -178,11 +179,12 @@ define([
|
||||
|
||||
return (
|
||||
<select
|
||||
id={ this.props.field.id || this.props.field.name }
|
||||
id={this.props.field.id || this.props.field.name}
|
||||
ref="select"
|
||||
data-placeholder={ this.props.field.placeholder }
|
||||
multiple={ this.props.field.multiple }
|
||||
defaultValue={ this.getSelectedValues() }
|
||||
disabled={this.props.field.disabled}
|
||||
data-placeholder={this.props.field.placeholder}
|
||||
multiple={this.props.field.multiple}
|
||||
defaultValue={this.getSelectedValues()}
|
||||
{...this.props.field.validation}
|
||||
>{ options }</select>
|
||||
);
|
||||
|
@ -15,17 +15,17 @@ const FormFieldText = React.createClass({
|
||||
? this.props.field.disabled(this.props.item)
|
||||
: false
|
||||
}
|
||||
className={ (this.props.field.size) ? '' : 'regular-text' }
|
||||
className={(this.props.field.size) ? '' : 'regular-text'}
|
||||
size={
|
||||
(this.props.field.size !== 'auto' && this.props.field.size > 0)
|
||||
? this.props.field.size
|
||||
: false
|
||||
}
|
||||
name={ this.props.field.name }
|
||||
id={ 'field_'+this.props.field.name }
|
||||
value={ value }
|
||||
placeholder={ this.props.field.placeholder }
|
||||
onChange={ this.props.onValueChange }
|
||||
name={this.props.field.name}
|
||||
id={'field_' + this.props.field.name}
|
||||
value={value}
|
||||
placeholder={this.props.field.placeholder}
|
||||
onChange={this.props.onValueChange}
|
||||
{...this.props.field.validation}
|
||||
/>
|
||||
);
|
||||
|
@ -10,12 +10,12 @@ define([
|
||||
<textarea
|
||||
type="text"
|
||||
className="regular-text"
|
||||
name={ this.props.field.name }
|
||||
id={ 'field_'+this.props.field.name }
|
||||
value={ this.props.item[this.props.field.name] }
|
||||
placeholder={ this.props.field.placeholder }
|
||||
defaultValue={ this.props.field.defaultValue }
|
||||
onChange={ this.props.onValueChange }
|
||||
name={this.props.field.name}
|
||||
id={'field_' + this.props.field.name}
|
||||
value={this.props.item[this.props.field.name]}
|
||||
placeholder={this.props.field.placeholder}
|
||||
defaultValue={this.props.field.defaultValue}
|
||||
onChange={this.props.onValueChange}
|
||||
{...this.props.field.validation}
|
||||
/>
|
||||
);
|
||||
|
@ -5,13 +5,15 @@ define(
|
||||
'classnames',
|
||||
'react-router',
|
||||
'form/fields/field.jsx',
|
||||
'jquery',
|
||||
],
|
||||
(
|
||||
React,
|
||||
MailPoet,
|
||||
classNames,
|
||||
Router,
|
||||
FormField
|
||||
FormField,
|
||||
jQuery
|
||||
) => {
|
||||
|
||||
const Form = React.createClass({
|
||||
@ -37,8 +39,8 @@ define(
|
||||
return this.props.errors ? this.props.errors : this.state.errors;
|
||||
},
|
||||
componentDidMount: function () {
|
||||
if(this.isMounted()) {
|
||||
if(this.props.params.id !== undefined) {
|
||||
if (this.isMounted()) {
|
||||
if (this.props.params.id !== undefined) {
|
||||
this.loadItem(this.props.params.id);
|
||||
} else {
|
||||
this.setState({
|
||||
@ -48,7 +50,7 @@ define(
|
||||
}
|
||||
},
|
||||
componentWillReceiveProps: function (props) {
|
||||
if(props.params.id === undefined) {
|
||||
if (props.params.id === undefined) {
|
||||
this.setState({
|
||||
loading: false,
|
||||
item: {},
|
||||
@ -88,8 +90,8 @@ define(
|
||||
e.preventDefault();
|
||||
|
||||
// handle validation
|
||||
if(this.props.isValid !== undefined) {
|
||||
if(this.props.isValid() === false) {
|
||||
if (this.props.isValid !== undefined) {
|
||||
if (this.props.isValid() === false) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -99,7 +101,7 @@ define(
|
||||
// only get values from displayed fields
|
||||
const item = {};
|
||||
this.props.fields.map((field) => {
|
||||
if(field['fields'] !== undefined) {
|
||||
if (field['fields'] !== undefined) {
|
||||
field.fields.map((subfield) => {
|
||||
item[subfield.name] = this.state.item[subfield.name];
|
||||
});
|
||||
@ -108,7 +110,7 @@ define(
|
||||
}
|
||||
});
|
||||
// set id if specified
|
||||
if(this.props.params.id !== undefined) {
|
||||
if (this.props.params.id !== undefined) {
|
||||
item.id = this.props.params.id;
|
||||
}
|
||||
|
||||
@ -120,19 +122,19 @@ define(
|
||||
}).always(() => {
|
||||
this.setState({ loading: false });
|
||||
}).done(() => {
|
||||
if(this.props.onSuccess !== undefined) {
|
||||
if (this.props.onSuccess !== undefined) {
|
||||
this.props.onSuccess();
|
||||
} else {
|
||||
this.context.router.push('/');
|
||||
}
|
||||
|
||||
if(this.props.params.id !== undefined) {
|
||||
if (this.props.params.id !== undefined) {
|
||||
this.props.messages.onUpdate();
|
||||
} else {
|
||||
this.props.messages.onCreate();
|
||||
}
|
||||
}).fail((response) => {
|
||||
if(response.errors.length > 0) {
|
||||
if (response.errors.length > 0) {
|
||||
this.setState({ errors: response.errors });
|
||||
}
|
||||
});
|
||||
@ -154,10 +156,10 @@ define(
|
||||
},
|
||||
render: function () {
|
||||
let errors;
|
||||
if(this.getErrors() !== undefined) {
|
||||
if (this.getErrors() !== undefined) {
|
||||
errors = this.getErrors().map((error, index) => {
|
||||
return (
|
||||
<p key={ 'error-'+index } className="mailpoet_error">
|
||||
<p key={'error-' + index} className="mailpoet_error">
|
||||
{ error.message }
|
||||
</p>
|
||||
);
|
||||
@ -166,7 +168,7 @@ define(
|
||||
|
||||
const formClasses = classNames(
|
||||
'mailpoet_form',
|
||||
{ 'mailpoet_form_loading': this.state.loading || this.props.loading }
|
||||
{ mailpoet_form_loading: this.state.loading || this.props.loading }
|
||||
);
|
||||
|
||||
let beforeFormContent = false;
|
||||
@ -192,15 +194,15 @@ define(
|
||||
|
||||
return (
|
||||
<FormField
|
||||
field={ field }
|
||||
item={ this.getValues() }
|
||||
onValueChange={ onValueChange }
|
||||
key={ 'field-'+i } />
|
||||
field={field}
|
||||
item={this.getValues()}
|
||||
onValueChange={onValueChange}
|
||||
key={'field-' + i} />
|
||||
);
|
||||
});
|
||||
|
||||
let actions = false;
|
||||
if(this.props.children) {
|
||||
if (this.props.children) {
|
||||
actions = this.props.children;
|
||||
} else {
|
||||
actions = (
|
||||
@ -216,9 +218,9 @@ define(
|
||||
<div>
|
||||
{ beforeFormContent }
|
||||
<form
|
||||
id={ this.props.id }
|
||||
id={this.props.id}
|
||||
ref="form"
|
||||
className={ formClasses }
|
||||
className={formClasses}
|
||||
onSubmit={
|
||||
(this.props.onSubmit !== undefined)
|
||||
? this.props.onSubmit
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -2,7 +2,7 @@ import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Router, Route, IndexRoute, useRouterHistory } from 'react-router';
|
||||
import { createHashHistory } from 'history';
|
||||
import FormList from 'forms/list.jsx';
|
||||
import FormList from './list.jsx';
|
||||
|
||||
const history = useRouterHistory(createHashHistory)({ queryKey: false });
|
||||
|
||||
@ -14,12 +14,12 @@ const App = React.createClass({
|
||||
|
||||
const container = document.getElementById('forms_container');
|
||||
|
||||
if(container) {
|
||||
if (container) {
|
||||
ReactDOM.render((
|
||||
<Router history={ history }>
|
||||
<Route path="/" component={ App }>
|
||||
<IndexRoute component={ FormList } />
|
||||
<Route path="*" component={ FormList } />
|
||||
<Router history={history}>
|
||||
<Route path="/" component={App}>
|
||||
<IndexRoute component={FormList} />
|
||||
<Route path="*" component={FormList} />
|
||||
</Route>
|
||||
</Router>
|
||||
), container);
|
||||
|
@ -1,7 +1,8 @@
|
||||
import React from 'react';
|
||||
import Listing from 'listing/listing.jsx';
|
||||
import classNames from 'classnames';
|
||||
import MailPoet from 'mailpoet';
|
||||
import jQuery from 'jquery';
|
||||
import Listing from '../listing/listing.jsx';
|
||||
|
||||
const columns = [
|
||||
{
|
||||
@ -86,7 +87,7 @@ const item_actions = [
|
||||
label: MailPoet.I18n.t('edit'),
|
||||
link: function (item) {
|
||||
return (
|
||||
<a href={ `admin.php?page=mailpoet-form-editor&id=${item.id}` }>{MailPoet.I18n.t('edit')}</a>
|
||||
<a href={`admin.php?page=mailpoet-form-editor&id=${item.id}`}>{MailPoet.I18n.t('edit')}</a>
|
||||
);
|
||||
},
|
||||
},
|
||||
@ -128,7 +129,7 @@ const FormList = React.createClass({
|
||||
endpoint: 'forms',
|
||||
action: 'create',
|
||||
}).done((response) => {
|
||||
window.location = mailpoet_form_edit_url + response.data.id;
|
||||
window.location = window.mailpoet_form_edit_url + response.data.id;
|
||||
}).fail((response) => {
|
||||
if (response.errors.length > 0) {
|
||||
MailPoet.Notice.error(
|
||||
@ -145,7 +146,7 @@ const FormList = React.createClass({
|
||||
'has-row-actions'
|
||||
);
|
||||
|
||||
let segments = mailpoet_segments.filter((segment) => {
|
||||
let segments = window.mailpoet_segments.filter((segment) => {
|
||||
return (jQuery.inArray(segment.id, form.segments) !== -1);
|
||||
}).map((segment) => {
|
||||
return segment.name;
|
||||
@ -157,11 +158,11 @@ const FormList = React.createClass({
|
||||
|
||||
return (
|
||||
<div>
|
||||
<td className={ row_classes }>
|
||||
<td className={row_classes}>
|
||||
<strong>
|
||||
<a
|
||||
className="row-title"
|
||||
href={ `admin.php?page=mailpoet-form-editor&id=${form.id}` }
|
||||
href={`admin.php?page=mailpoet-form-editor&id=${form.id}`}
|
||||
>{ form.name }</a>
|
||||
</strong>
|
||||
{ actions }
|
||||
@ -185,21 +186,21 @@ const FormList = React.createClass({
|
||||
{MailPoet.I18n.t('pageTitle')} <a
|
||||
className="page-title-action"
|
||||
href="javascript:;"
|
||||
onClick={ this.createForm }
|
||||
onClick={this.createForm}
|
||||
>{MailPoet.I18n.t('new')}</a>
|
||||
</h1>
|
||||
|
||||
<Listing
|
||||
limit={ mailpoet_listing_per_page }
|
||||
location={ this.props.location }
|
||||
params={ this.props.params }
|
||||
messages={ messages }
|
||||
search={ false }
|
||||
limit={window.mailpoet_listing_per_page}
|
||||
location={this.props.location}
|
||||
params={this.props.params}
|
||||
messages={messages}
|
||||
search={false}
|
||||
endpoint="forms"
|
||||
onRenderItem={ this.renderItem }
|
||||
columns={ columns }
|
||||
bulk_actions={ bulk_actions }
|
||||
item_actions={ item_actions }
|
||||
onRenderItem={this.renderItem}
|
||||
columns={columns}
|
||||
bulk_actions={bulk_actions}
|
||||
item_actions={item_actions}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
@ -1,117 +1,119 @@
|
||||
define('handlebars_helpers', ['handlebars'], function(Handlebars) {
|
||||
define('handlebars_helpers', ['handlebars'], function (Handlebars) {
|
||||
// Handlebars helpers
|
||||
Handlebars.registerHelper('concat', function() {
|
||||
var size = (arguments.length - 1),
|
||||
output = '';
|
||||
for(var i = 0; i < size; i++) {
|
||||
output += arguments[i];
|
||||
};
|
||||
return output;
|
||||
Handlebars.registerHelper('concat', function () {
|
||||
var size = (arguments.length - 1);
|
||||
var output = '';
|
||||
var i;
|
||||
for (i = 0; i < size; i++) {
|
||||
output += arguments[i];
|
||||
}
|
||||
return output;
|
||||
});
|
||||
|
||||
Handlebars.registerHelper('number_format', function(value, block) {
|
||||
return Number(value).toLocaleString();
|
||||
Handlebars.registerHelper('number_format', function (value) {
|
||||
return Number(value).toLocaleString();
|
||||
});
|
||||
Handlebars.registerHelper('date_format', function(timestamp, block) {
|
||||
if(window.moment) {
|
||||
if(timestamp === undefined || isNaN(timestamp) || timestamp <= 0) {
|
||||
return;
|
||||
}
|
||||
Handlebars.registerHelper('date_format', function (timestamp, block) {
|
||||
var f;
|
||||
if (window.moment) {
|
||||
if (timestamp === undefined || isNaN(timestamp) || timestamp <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// set date format
|
||||
var f = block.hash.format || "MMM Do, YYYY";
|
||||
// check if we passed a timestamp
|
||||
if(parseInt(timestamp, 10) == timestamp) {
|
||||
return moment.unix(timestamp).format(f);
|
||||
} else {
|
||||
return moment.utc(timestamp).format(f);
|
||||
}
|
||||
// set date format
|
||||
f = block.hash.format || 'MMM Do, YYYY';
|
||||
// check if we passed a timestamp
|
||||
if (parseInt(timestamp, 10) == timestamp) {
|
||||
return window.moment.unix(timestamp).format(f);
|
||||
} else {
|
||||
return window.moment.utc(timestamp).format(f);
|
||||
}
|
||||
} else {
|
||||
return timestamp;
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
Handlebars.registerHelper('cycle', function(value, block) {
|
||||
Handlebars.registerHelper('cycle', function (value, block) {
|
||||
var values = value.split(' ');
|
||||
return values[block.data.index % (values.length + 1)];
|
||||
});
|
||||
|
||||
Handlebars.registerHelper('ifCond', function (v1, operator, v2, options) {
|
||||
switch (operator) {
|
||||
case '==':
|
||||
return (v1 == v2) ? options.fn(this) : options.inverse(this);
|
||||
case '===':
|
||||
return (v1 === v2) ? options.fn(this) : options.inverse(this);
|
||||
case '!=':
|
||||
return (v1 != v2) ? options.fn(this) : options.inverse(this);
|
||||
case '!==':
|
||||
return (v1 !== v2) ? options.fn(this) : options.inverse(this);
|
||||
case '<':
|
||||
return (v1 < v2) ? options.fn(this) : options.inverse(this);
|
||||
case '<=':
|
||||
return (v1 <= v2) ? options.fn(this) : options.inverse(this);
|
||||
case '>':
|
||||
return (v1 > v2) ? options.fn(this) : options.inverse(this);
|
||||
case '>=':
|
||||
return (v1 >= v2) ? options.fn(this) : options.inverse(this);
|
||||
case '&&':
|
||||
return (v1 && v2) ? options.fn(this) : options.inverse(this);
|
||||
case '||':
|
||||
return (v1 || v2) ? options.fn(this) : options.inverse(this);
|
||||
case 'in':
|
||||
var values = v2.split(',');
|
||||
return (v2.indexOf(v1) !== -1) ? options.fn(this) : options.inverse(this);
|
||||
default:
|
||||
return options.inverse(this);
|
||||
}
|
||||
switch (operator) {
|
||||
case '==':
|
||||
return (v1 == v2) ? options.fn(this) : options.inverse(this);
|
||||
case '===':
|
||||
return (v1 === v2) ? options.fn(this) : options.inverse(this);
|
||||
case '!=':
|
||||
return (v1 != v2) ? options.fn(this) : options.inverse(this);
|
||||
case '!==':
|
||||
return (v1 !== v2) ? options.fn(this) : options.inverse(this);
|
||||
case '<':
|
||||
return (v1 < v2) ? options.fn(this) : options.inverse(this);
|
||||
case '<=':
|
||||
return (v1 <= v2) ? options.fn(this) : options.inverse(this);
|
||||
case '>':
|
||||
return (v1 > v2) ? options.fn(this) : options.inverse(this);
|
||||
case '>=':
|
||||
return (v1 >= v2) ? options.fn(this) : options.inverse(this);
|
||||
case '&&':
|
||||
return (v1 && v2) ? options.fn(this) : options.inverse(this);
|
||||
case '||':
|
||||
return (v1 || v2) ? options.fn(this) : options.inverse(this);
|
||||
case 'in':
|
||||
return (v2.indexOf(v1) !== -1) ? options.fn(this) : options.inverse(this);
|
||||
default:
|
||||
return options.inverse(this);
|
||||
}
|
||||
});
|
||||
|
||||
Handlebars.registerHelper('nl2br', function(value, block) {
|
||||
return value.gsub("\n", "<br />");
|
||||
Handlebars.registerHelper('nl2br', function (value) {
|
||||
return value.gsub('\n', '<br />');
|
||||
});
|
||||
|
||||
Handlebars.registerHelper('json_encode', function(value, block) {
|
||||
return JSON.stringify(value);
|
||||
Handlebars.registerHelper('json_encode', function (value) {
|
||||
return JSON.stringify(value);
|
||||
});
|
||||
|
||||
Handlebars.registerHelper('json_decode', function(value, block) {
|
||||
return JSON.parse(value);
|
||||
Handlebars.registerHelper('json_decode', function (value) {
|
||||
return JSON.parse(value);
|
||||
});
|
||||
Handlebars.registerHelper('url', function(value, block) {
|
||||
var url = window.location.protocol + "//" + window.location.host + window.location.pathname;
|
||||
Handlebars.registerHelper('url', function (value) {
|
||||
var url = window.location.protocol + '//' + window.location.host + window.location.pathname;
|
||||
|
||||
return url + value;
|
||||
return url + value;
|
||||
});
|
||||
Handlebars.registerHelper('emailFromMailto', function(value) {
|
||||
var mailtoMatchingRegex = /^mailto\:/i;
|
||||
if (typeof value === 'string' && value.match(mailtoMatchingRegex)) {
|
||||
return value.replace(mailtoMatchingRegex, '');
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
Handlebars.registerHelper('emailFromMailto', function (value) {
|
||||
var mailtoMatchingRegex = /^mailto\:/i;
|
||||
if (typeof value === 'string' && value.match(mailtoMatchingRegex)) {
|
||||
return value.replace(mailtoMatchingRegex, '');
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
});
|
||||
Handlebars.registerHelper('lookup', function(obj, field, options) {
|
||||
return obj && obj[field];
|
||||
Handlebars.registerHelper('lookup', function (obj, field) {
|
||||
return obj && obj[field];
|
||||
});
|
||||
|
||||
|
||||
Handlebars.registerHelper('rsa_key', function(value, block) {
|
||||
// extract all lines into an array
|
||||
if(value === undefined) return '';
|
||||
Handlebars.registerHelper('rsa_key', function (value) {
|
||||
var lines;
|
||||
// extract all lines into an array
|
||||
if (value === undefined) return '';
|
||||
|
||||
var lines = value.trim().split("\n");
|
||||
lines = value.trim().split('\n');
|
||||
|
||||
// remove header & footer
|
||||
lines.shift();
|
||||
lines.pop();
|
||||
lines.shift();
|
||||
lines.pop();
|
||||
|
||||
// return concatenated lines
|
||||
return lines.join('');
|
||||
return lines.join('');
|
||||
});
|
||||
|
||||
Handlebars.registerHelper('trim', function(value, block) {
|
||||
if(value === null || value === undefined) return '';
|
||||
return value.trim();
|
||||
Handlebars.registerHelper('trim', function (value) {
|
||||
if (value === null || value === undefined) return '';
|
||||
return value.trim();
|
||||
});
|
||||
|
||||
/**
|
||||
@ -125,32 +127,33 @@ define('handlebars_helpers', ['handlebars'], function(Handlebars) {
|
||||
* @return {String} The truncated string.
|
||||
*/
|
||||
Handlebars.registerHelper('ellipsis', function (str, limit, append) {
|
||||
if (append === undefined) {
|
||||
append = '';
|
||||
}
|
||||
var sanitized = str.replace(/(<([^>]+)>)/g, '');
|
||||
if (sanitized.length > limit) {
|
||||
return sanitized.substr(0, limit - append.length) + append;
|
||||
} else {
|
||||
return sanitized;
|
||||
}
|
||||
var strAppend = append;
|
||||
var sanitized = str.replace(/(<([^>]+)>)/g, '');
|
||||
if (strAppend === undefined) {
|
||||
strAppend = '';
|
||||
}
|
||||
if (sanitized.length > limit) {
|
||||
return sanitized.substr(0, limit - strAppend.length) + strAppend;
|
||||
} else {
|
||||
return sanitized;
|
||||
}
|
||||
});
|
||||
|
||||
Handlebars.registerHelper('getNumber', function (string) {
|
||||
return parseInt(string, 10);
|
||||
return parseInt(string, 10);
|
||||
});
|
||||
|
||||
Handlebars.registerHelper('fontWithFallback', function(font) {
|
||||
switch(font) {
|
||||
Handlebars.registerHelper('fontWithFallback', function (font) {
|
||||
switch (font) {
|
||||
case 'Arial': return new Handlebars.SafeString("Arial, 'Helvetica Neue', Helvetica, sans-serif");
|
||||
case 'Comic Sans MS': return new Handlebars.SafeString("'Comic Sans MS', 'Marker Felt-Thin', Arial, sans-serif");
|
||||
case 'Courier New': return new Handlebars.SafeString("'Courier New', Courier, 'Lucida Sans Typewriter', 'Lucida Typewriter', monospace");
|
||||
case 'Georgia': return new Handlebars.SafeString("Georgia, Times, 'Times New Roman', serif");
|
||||
case 'Lucida': return new Handlebars.SafeString("'Lucida Sans Unicode', 'Lucida Grande', sans-serif");
|
||||
case 'Tahoma': return new Handlebars.SafeString("Tahoma, Verdana, Segoe, sans-serif");
|
||||
case 'Tahoma': return new Handlebars.SafeString('Tahoma, Verdana, Segoe, sans-serif');
|
||||
case 'Times New Roman': return new Handlebars.SafeString("'Times New Roman', Times, Baskerville, Georgia, serif");
|
||||
case 'Trebuchet MS': return new Handlebars.SafeString("'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Tahoma, sans-serif");
|
||||
case 'Verdana': return new Handlebars.SafeString("Verdana, Geneva, sans-serif");
|
||||
case 'Verdana': return new Handlebars.SafeString('Verdana, Geneva, sans-serif');
|
||||
default: return font;
|
||||
}
|
||||
});
|
||||
|
22
assets/js/src/help-tooltip.js
Normal file
22
assets/js/src/help-tooltip.js
Normal file
@ -0,0 +1,22 @@
|
||||
define('helpTooltip', ['mailpoet', 'react', 'react-dom', 'help-tooltip.jsx'],
|
||||
function (mp, React, ReactDOM, TooltipComponent) {
|
||||
'use strict';
|
||||
|
||||
var MailPoet = mp;
|
||||
|
||||
MailPoet.helpTooltip = {
|
||||
show: function (domContainerNode, opts) {
|
||||
|
||||
ReactDOM.render(React.createElement(
|
||||
TooltipComponent, {
|
||||
tooltip: opts.tooltip,
|
||||
tooltipId: opts.tooltipId,
|
||||
place: opts.place
|
||||
}
|
||||
), domContainerNode);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
);
|
||||
|
63
assets/js/src/help-tooltip.jsx
Normal file
63
assets/js/src/help-tooltip.jsx
Normal file
@ -0,0 +1,63 @@
|
||||
import React from 'react';
|
||||
import ReactTooltip from 'react-tooltip';
|
||||
import ReactHtmlParser from 'react-html-parser';
|
||||
|
||||
function Tooltip(props) {
|
||||
let tooltipId = props.tooltipId;
|
||||
let tooltip = props.tooltip;
|
||||
// tooltip ID must be unique, defaults to tooltip text
|
||||
if (!props.tooltipId && typeof props.tooltip === 'string') {
|
||||
tooltipId = props.tooltip;
|
||||
}
|
||||
|
||||
if (typeof props.tooltip === 'string') {
|
||||
tooltip = (<span
|
||||
style={{
|
||||
pointerEvents: 'all',
|
||||
maxWidth: '400',
|
||||
display: 'inline-block',
|
||||
}}
|
||||
>
|
||||
{ReactHtmlParser(props.tooltip)}
|
||||
</span>);
|
||||
}
|
||||
|
||||
return (
|
||||
<span className={props.className}>
|
||||
<span
|
||||
style={{
|
||||
cursor: 'pointer',
|
||||
}}
|
||||
className="tooltip dashicons dashicons-editor-help"
|
||||
data-event="click"
|
||||
data-tip
|
||||
data-for={tooltipId}
|
||||
>
|
||||
</span>
|
||||
<ReactTooltip
|
||||
globalEventOff="click"
|
||||
multiline={true}
|
||||
id={tooltipId}
|
||||
efect="solid"
|
||||
place={props.place}
|
||||
>
|
||||
{tooltip}
|
||||
</ReactTooltip>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
Tooltip.propTypes = {
|
||||
tooltipId: React.PropTypes.string,
|
||||
tooltip: React.PropTypes.node.isRequired,
|
||||
place: React.PropTypes.string,
|
||||
className: React.PropTypes.string,
|
||||
};
|
||||
|
||||
Tooltip.defaultProps = {
|
||||
tooltipId: undefined,
|
||||
place: undefined,
|
||||
className: undefined,
|
||||
};
|
||||
|
||||
module.exports = Tooltip;
|
@ -16,15 +16,15 @@ const App = React.createClass({
|
||||
|
||||
const container = document.getElementById('help_container');
|
||||
|
||||
if(container) {
|
||||
if (container) {
|
||||
|
||||
ReactDOM.render((
|
||||
<Router history={ history }>
|
||||
<Route path="/" component={ App }>
|
||||
<Router history={history}>
|
||||
<Route path="/" component={App}>
|
||||
<IndexRedirect to="knowledgeBase" />
|
||||
{/* Pages */}
|
||||
<Route path="knowledgeBase(/)**" params={{ tab: 'knowledgeBase' }} component={ KnowledgeBase } />
|
||||
<Route path="systemInfo(/)**" params={{ tab: 'systemInfo' }} component={ SystemInfo } />
|
||||
<Route path="knowledgeBase(/)**" params={{ tab: 'knowledgeBase' }} component={KnowledgeBase} />
|
||||
<Route path="systemInfo(/)**" params={{ tab: 'systemInfo' }} component={SystemInfo} />
|
||||
</Route>
|
||||
</Router>
|
||||
), container);
|
||||
|
@ -24,6 +24,6 @@ function KnowledgeBase() {
|
||||
<a target="_blank" href="http://beta.docs.mailpoet.com/" className="button button-primary">{MailPoet.I18n.t('knowledgeBaseButton')}</a>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = KnowledgeBase;
|
||||
|
@ -17,10 +17,10 @@ function printData(data) {
|
||||
return (<textarea
|
||||
readOnly={true}
|
||||
onFocus={handleFocus}
|
||||
value={printableData.join("\n")}
|
||||
value={printableData.join('\n')}
|
||||
style={{
|
||||
width: "100%",
|
||||
height: "400px",
|
||||
width: '100%',
|
||||
height: '400px',
|
||||
}}
|
||||
/>);
|
||||
} else {
|
||||
@ -35,13 +35,13 @@ function KnowledgeBase() {
|
||||
|
||||
<Tabs tab="systemInfo" />
|
||||
|
||||
<div className="mailpoet_notice notice inline notice-success" style={{ marginTop: "1em" }}>
|
||||
<div className="mailpoet_notice notice inline notice-success" style={{ marginTop: '1em' }}>
|
||||
<p>{MailPoet.I18n.t('systemInfoIntro')}</p>
|
||||
</div>
|
||||
|
||||
{printData(data)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = KnowledgeBase;
|
||||
|
@ -26,9 +26,9 @@ function Tabs(props) {
|
||||
|
||||
return (
|
||||
<Link
|
||||
key={ 'tab-'+index }
|
||||
className={ tabClasses }
|
||||
to={ tab.link }
|
||||
key={'tab-' + index}
|
||||
className={tabClasses}
|
||||
to={tab.link}
|
||||
>{ tab.label }</Link>
|
||||
);
|
||||
});
|
||||
@ -38,9 +38,9 @@ function Tabs(props) {
|
||||
{ tabLinks }
|
||||
</h2>
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
Tabs.propTypes = { tab: React.PropTypes.string };
|
||||
Tabs.defaultProps = { tab: "knowledgeBase" };
|
||||
Tabs.defaultProps = { tab: 'knowledgeBase' };
|
||||
|
||||
module.exports = Tabs;
|
||||
|
@ -1,3 +0,0 @@
|
||||
define([], function() {
|
||||
!function(e, o, n){window.HSCW=o, window.HS=n, n.beacon=n.beacon||{};var t=n.beacon;t.userConfig={}, t.readyQueue=[], t.config=function(e){this.userConfig=e}, t.ready=function(e){this.readyQueue.push(e)}, o.config={docs:{enabled:!0, baseUrl:"//mailpoet3.helpscoutdocs.com/"}, contact:{enabled:!0, formId:"aa21ca80-a4f5-11e6-91aa-0a5fecc78a4d"}};var r=e.getElementsByTagName("script")[0], c=e.createElement("script");c.type="text/javascript", c.async=!0, c.src="https://djtflbt20bdde.cloudfront.net/", r.parentNode.insertBefore(c, r)}(document, window.HSCW||{}, window.HS||{});
|
||||
});
|
@ -1,23 +1,25 @@
|
||||
define('i18n',
|
||||
[
|
||||
'mailpoet'
|
||||
], function(
|
||||
MailPoet
|
||||
], function (
|
||||
mp
|
||||
) {
|
||||
'use strict';
|
||||
'use strict';
|
||||
|
||||
var translations = {};
|
||||
var MailPoet = mp;
|
||||
|
||||
MailPoet.I18n = {
|
||||
add: function(key, value) {
|
||||
translations[key] = value;
|
||||
},
|
||||
t: function(key) {
|
||||
return translations[key] || 'TRANSLATION "%$1s" NOT FOUND'.replace("%$1s", key);
|
||||
},
|
||||
all: function() {
|
||||
return translations;
|
||||
}
|
||||
};
|
||||
var translations = {};
|
||||
|
||||
});
|
||||
MailPoet.I18n = {
|
||||
add: function (key, value) {
|
||||
translations[key] = value;
|
||||
},
|
||||
t: function (key) {
|
||||
return translations[key] || 'TRANSLATION "%$1s" NOT FOUND'.replace('%$1s', key);
|
||||
},
|
||||
all: function () {
|
||||
return translations;
|
||||
}
|
||||
};
|
||||
|
||||
});
|
||||
|
@ -1,21 +1,24 @@
|
||||
define('iframe', ['mailpoet', 'jquery'], function(MailPoet, jQuery) {
|
||||
define('iframe', ['mailpoet'], function (mp) {
|
||||
'use strict';
|
||||
|
||||
var MailPoet = mp;
|
||||
MailPoet.Iframe = {
|
||||
marginY: 20,
|
||||
autoSize: function(iframe) {
|
||||
if(!iframe) return;
|
||||
autoSize: function (iframe) {
|
||||
if (!iframe) return;
|
||||
|
||||
this.setSize(
|
||||
iframe,
|
||||
iframe.contentWindow.document.body.scrollHeight
|
||||
);
|
||||
},
|
||||
setSize: function(iframe, i) {
|
||||
if(!iframe) return;
|
||||
setSize: function (sizeIframe, i) {
|
||||
var iframe = sizeIframe;
|
||||
if (!iframe) return;
|
||||
|
||||
iframe.style.height = (
|
||||
parseInt(i) + this.marginY
|
||||
) + "px";
|
||||
parseInt(i, 10) + this.marginY
|
||||
) + 'px';
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -2,9 +2,10 @@ define(
|
||||
[
|
||||
'jquery'
|
||||
],
|
||||
function(
|
||||
$
|
||||
function (
|
||||
jQuery
|
||||
) {
|
||||
var $ = jQuery;
|
||||
// Combination of jQuery.deparam and jQuery.serializeObject by Ben Alman.
|
||||
/*!
|
||||
* jQuery BBQ: Back Button & Query Library - v1.2.1 - 2/17/2010
|
||||
@ -22,31 +23,31 @@ define(
|
||||
* Dual licensed under the MIT and GPL licenses.
|
||||
* http://benalman.com/about/license/
|
||||
*/
|
||||
$.fn.serializeObject = function(coerce) {
|
||||
var obj = {},
|
||||
coerce_types = { 'true': !0, 'false': !1, 'null': null };
|
||||
$.fn.serializeObject = function (coerce) {
|
||||
var obj = {};
|
||||
var coerce_types = { true: !0, false: !1, null: null };
|
||||
|
||||
// Iterate over all name=value pairs.
|
||||
$.each( this.serializeArray(), function(j, v){
|
||||
var key = v.name,
|
||||
val = v.value,
|
||||
cur = obj,
|
||||
i = 0,
|
||||
$.each(this.serializeArray(), function (j, v) {
|
||||
var key = v.name;
|
||||
var val = v.value;
|
||||
var cur = obj;
|
||||
var i = 0;
|
||||
|
||||
// If key is more complex than 'foo', like 'a[]' or 'a[b][c]', split it
|
||||
// into its component parts.
|
||||
keys = key.split( '][' ),
|
||||
keys_last = keys.length - 1;
|
||||
// If key is more complex than 'foo', like 'a[]' or 'a[b][c]', split it
|
||||
// into its component parts.
|
||||
var keys = key.split('][');
|
||||
var keys_last = keys.length - 1;
|
||||
|
||||
// If the first keys part contains [ and the last ends with ], then []
|
||||
// are correctly balanced.
|
||||
if ( /\[/.test( keys[0] ) && /\]$/.test( keys[ keys_last ] ) ) {
|
||||
if (/\[/.test(keys[0]) && /\]$/.test(keys[keys_last])) {
|
||||
// Remove the trailing ] from the last keys part.
|
||||
keys[ keys_last ] = keys[ keys_last ].replace( /\]$/, '' );
|
||||
keys[keys_last] = keys[keys_last].replace(/\]$/, '');
|
||||
|
||||
// Split first keys part into two parts on the [ and add them back onto
|
||||
// the beginning of the keys array.
|
||||
keys = keys.shift().split('[').concat( keys );
|
||||
keys = keys.shift().split('[').concat(keys);
|
||||
|
||||
keys_last = keys.length - 1;
|
||||
} else {
|
||||
@ -55,14 +56,14 @@ define(
|
||||
}
|
||||
|
||||
// Coerce values.
|
||||
if ( coerce ) {
|
||||
val = val && !isNaN(val) ? +val // number
|
||||
: val === 'undefined' ? undefined // undefined
|
||||
if (coerce) {
|
||||
val = val && !isNaN(val) ? +val // number
|
||||
: val === 'undefined' ? undefined // undefined
|
||||
: coerce_types[val] !== undefined ? coerce_types[val] // true, false, null
|
||||
: val; // string
|
||||
}
|
||||
|
||||
if ( keys_last ) {
|
||||
if (keys_last) {
|
||||
// Complex key, build deep object structure based on a few rules:
|
||||
// * The 'cur' pointer starts at the object top-level.
|
||||
// * [] = array push (n is set to array length), [n] = array if n is
|
||||
@ -72,25 +73,26 @@ define(
|
||||
// object or array based on the type of the next keys part.
|
||||
// * Move the 'cur' pointer to the next level.
|
||||
// * Rinse & repeat.
|
||||
for ( ; i <= keys_last; i++ ) {
|
||||
for (; i <= keys_last; i++) {
|
||||
key = keys[i] === '' ? cur.length : keys[i];
|
||||
cur = cur[key] = i < keys_last
|
||||
? cur[key] || ( keys[i+1] && isNaN( keys[i+1] ) ? {} : [] )
|
||||
cur[key] = i < keys_last
|
||||
? cur[key] || (keys[i + 1] && isNaN(keys[i + 1]) ? {} : [])
|
||||
: val;
|
||||
cur = cur[key];
|
||||
}
|
||||
|
||||
} else {
|
||||
// Simple key, even simpler rules, since only scalars and shallow
|
||||
// arrays are allowed.
|
||||
|
||||
if ( $.isArray( obj[key] ) ) {
|
||||
if ($.isArray(obj[key])) {
|
||||
// val is already an array, so push on the next value.
|
||||
obj[key].push( val );
|
||||
obj[key].push(val);
|
||||
|
||||
} else if ( obj[key] !== undefined ) {
|
||||
} else if (obj[key] !== undefined) {
|
||||
// val isn't an array, but since a second value has been specified,
|
||||
// convert val into an array.
|
||||
obj[key] = [ obj[key], val ];
|
||||
obj[key] = [obj[key], val];
|
||||
|
||||
} else {
|
||||
// val is a scalar.
|
||||
@ -104,4 +106,4 @@ define(
|
||||
|
||||
return $;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
@ -21,7 +21,7 @@ define([
|
||||
const action = this.getSelectedAction();
|
||||
|
||||
// action on select callback
|
||||
if(action !== null && action['onSelect'] !== undefined) {
|
||||
if (action !== null && action['onSelect'] !== undefined) {
|
||||
this.setState({
|
||||
extra: action.onSelect(e),
|
||||
});
|
||||
@ -33,7 +33,7 @@ define([
|
||||
|
||||
const action = this.getSelectedAction();
|
||||
|
||||
if(action === null) {
|
||||
if (action === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -48,15 +48,15 @@ define([
|
||||
data.action = this.state.action;
|
||||
|
||||
let onSuccess = function () {};
|
||||
if(action['onSuccess'] !== undefined) {
|
||||
if (action['onSuccess'] !== undefined) {
|
||||
onSuccess = action.onSuccess;
|
||||
}
|
||||
|
||||
if(data.action) {
|
||||
if (data.action) {
|
||||
const promise = this.props.onBulkAction(selected_ids, data);
|
||||
if (promise !== false) {
|
||||
promise.then(onSuccess);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
this.setState({
|
||||
@ -66,19 +66,19 @@ define([
|
||||
},
|
||||
getSelectedAction: function () {
|
||||
const selected_action = this.refs.action.value;
|
||||
if(selected_action.length > 0) {
|
||||
if (selected_action.length > 0) {
|
||||
const action = this.props.bulk_actions.filter((action) => {
|
||||
return (action.name === selected_action);
|
||||
});
|
||||
|
||||
if(action.length > 0) {
|
||||
if (action.length > 0) {
|
||||
return action[0];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
render: function () {
|
||||
if(this.props.bulk_actions.length === 0) {
|
||||
if (this.props.bulk_actions.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -93,26 +93,26 @@ define([
|
||||
<select
|
||||
name="bulk_actions"
|
||||
ref="action"
|
||||
value={ this.state.action }
|
||||
value={this.state.action}
|
||||
onChange={this.handleChangeAction}
|
||||
>
|
||||
<option value="">{MailPoet.I18n.t('bulkActions')}</option>
|
||||
{ this.props.bulk_actions.map((action, index) => {
|
||||
return (
|
||||
<option
|
||||
value={ action.name }
|
||||
key={ 'action-' + index }
|
||||
value={action.name}
|
||||
key={'action-' + index}
|
||||
>{ action.label }</option>
|
||||
);
|
||||
}) }
|
||||
</select>
|
||||
<input
|
||||
onClick={ this.handleApplyAction }
|
||||
onClick={this.handleApplyAction}
|
||||
type="submit"
|
||||
defaultValue={MailPoet.I18n.t('apply')}
|
||||
className="button action" />
|
||||
|
||||
{ this.state.extra }
|
||||
{ this.state.extra }
|
||||
</div>
|
||||
);
|
||||
},
|
||||
|
@ -12,7 +12,7 @@ define([
|
||||
handleFilterAction: function () {
|
||||
const filters = {};
|
||||
this.getAvailableFilters().map((filter, i) => {
|
||||
filters[this.refs['filter-'+i].name] = this.refs['filter-'+i].value;
|
||||
filters[this.refs['filter-' + i].name] = this.refs['filter-' + i].value;
|
||||
});
|
||||
if (this.props.onBeforeSelectFilter) {
|
||||
this.props.onBeforeSelectFilter(filters);
|
||||
@ -39,7 +39,7 @@ define([
|
||||
this.getAvailableFilters().map(
|
||||
(filter, i) => {
|
||||
if (selected_filters[filter] !== undefined && selected_filters[filter]) {
|
||||
jQuery(this.refs['filter-'+i])
|
||||
jQuery(this.refs['filter-' + i])
|
||||
.val(selected_filters[filter])
|
||||
.trigger('change');
|
||||
}
|
||||
@ -52,18 +52,18 @@ define([
|
||||
.map((filter, i) => {
|
||||
return (
|
||||
<select
|
||||
ref={ `filter-${i}` }
|
||||
key={ `filter-${i}` }
|
||||
name={ filter }
|
||||
ref={`filter-${i}`}
|
||||
key={`filter-${i}`}
|
||||
name={filter}
|
||||
>
|
||||
{ filters[filter].map((option, j) => {
|
||||
return (
|
||||
<option
|
||||
value={ option.value }
|
||||
key={ 'filter-option-' + j }
|
||||
{ filters[filter].map((option, j) => {
|
||||
return (
|
||||
<option
|
||||
value={option.value}
|
||||
key={'filter-option-' + j}
|
||||
>{ option.label }</option>
|
||||
);
|
||||
}) }
|
||||
);
|
||||
}) }
|
||||
</select>
|
||||
);
|
||||
});
|
||||
@ -74,7 +74,7 @@ define([
|
||||
button = (
|
||||
<input
|
||||
id="post-query-submit"
|
||||
onClick={ this.handleFilterAction }
|
||||
onClick={this.handleFilterAction}
|
||||
type="submit"
|
||||
defaultValue={MailPoet.I18n.t('filter')}
|
||||
className="button" />
|
||||
@ -85,7 +85,7 @@ define([
|
||||
if (this.props.group === 'trash') {
|
||||
empty_trash = (
|
||||
<input
|
||||
onClick={ this.handleEmptyTrash }
|
||||
onClick={this.handleEmptyTrash}
|
||||
type="submit"
|
||||
value={MailPoet.I18n.t('emptyTrash')}
|
||||
className="button"
|
||||
|
@ -6,31 +6,31 @@ define(['react', 'classnames'], (React, classNames) => {
|
||||
},
|
||||
render: function () {
|
||||
const groups = this.props.groups.map((group, index) => {
|
||||
if(group.name === 'trash' && group.count === 0) {
|
||||
if (group.name === 'trash' && group.count === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const classes = classNames(
|
||||
{ 'current' : (group.name === this.props.group) }
|
||||
{ current: (group.name === this.props.group) }
|
||||
);
|
||||
|
||||
return (
|
||||
<li key={index}>
|
||||
{(index > 0) ? ' |' : ''}
|
||||
<a
|
||||
href="javascript:;"
|
||||
className={classes}
|
||||
onClick={this.handleSelect.bind(this, group.name)} >
|
||||
{group.label} <span className="count">({ group.count.toLocaleString() })</span>
|
||||
</a>
|
||||
</li>
|
||||
<li key={index}>
|
||||
{(index > 0) ? ' |' : ''}
|
||||
<a
|
||||
href="javascript:;"
|
||||
className={classes}
|
||||
onClick={this.handleSelect.bind(this, group.name)} >
|
||||
{group.label} <span className="count">({ group.count.toLocaleString() })</span>
|
||||
</a>
|
||||
</li>
|
||||
);
|
||||
});
|
||||
|
||||
return (
|
||||
<ul className="subsubsub">
|
||||
{ groups }
|
||||
</ul>
|
||||
<ul className="subsubsub">
|
||||
{ groups }
|
||||
</ul>
|
||||
);
|
||||
},
|
||||
});
|
||||
|
@ -10,22 +10,23 @@ const ListingHeader = React.createClass({
|
||||
},
|
||||
render: function () {
|
||||
const columns = this.props.columns.map((column, index) => {
|
||||
column.is_primary = (index === 0);
|
||||
column.sorted = (this.props.sort_by === column.name)
|
||||
const renderColumn = column;
|
||||
renderColumn.is_primary = (index === 0);
|
||||
renderColumn.sorted = (this.props.sort_by === column.name)
|
||||
? this.props.sort_order
|
||||
: 'desc';
|
||||
return (
|
||||
<ListingColumn
|
||||
onSort={this.props.onSort}
|
||||
sort_by={this.props.sort_by}
|
||||
key={ 'column-' + index }
|
||||
column={column} />
|
||||
key={'column-' + index}
|
||||
column={renderColumn} />
|
||||
);
|
||||
});
|
||||
|
||||
let checkbox;
|
||||
|
||||
if(this.props.is_selectable === true) {
|
||||
if (this.props.is_selectable === true) {
|
||||
checkbox = (
|
||||
<th
|
||||
className="manage-column column-cb check-column">
|
||||
@ -36,8 +37,8 @@ const ListingHeader = React.createClass({
|
||||
type="checkbox"
|
||||
name="select_all"
|
||||
ref="toggle"
|
||||
checked={ this.props.selection }
|
||||
onChange={ this.handleSelectItems } />
|
||||
checked={this.props.selection}
|
||||
onChange={this.handleSelectItems} />
|
||||
</th>
|
||||
);
|
||||
}
|
||||
@ -61,15 +62,15 @@ const ListingColumn = React.createClass({
|
||||
const classes = classNames(
|
||||
'manage-column',
|
||||
{ 'column-primary': this.props.column.is_primary },
|
||||
{ 'sortable': this.props.column.sortable },
|
||||
{ sortable: this.props.column.sortable },
|
||||
this.props.column.sorted,
|
||||
{ 'sorted': (this.props.sort_by === this.props.column.name) }
|
||||
{ sorted: (this.props.sort_by === this.props.column.name) }
|
||||
);
|
||||
let label;
|
||||
|
||||
if(this.props.column.sortable === true) {
|
||||
if (this.props.column.sortable === true) {
|
||||
label = (
|
||||
<a onClick={ this.handleSort }>
|
||||
<a onClick={this.handleSort}>
|
||||
<span>{ this.props.column.label }</span>
|
||||
<span className="sorting-indicator"></span>
|
||||
</a>
|
||||
@ -79,10 +80,10 @@ const ListingColumn = React.createClass({
|
||||
}
|
||||
return (
|
||||
<th
|
||||
className={ classes }
|
||||
id={this.props.column.name }
|
||||
className={classes}
|
||||
id={this.props.column.name}
|
||||
scope="col"
|
||||
width={ this.props.column.width || null }
|
||||
width={this.props.column.width || null}
|
||||
>{label}</th>
|
||||
);
|
||||
},
|
||||
|
@ -48,12 +48,12 @@ const ListingItem = React.createClass({
|
||||
}</label>
|
||||
<input
|
||||
type="checkbox"
|
||||
value={ this.props.item.id }
|
||||
value={this.props.item.id}
|
||||
checked={
|
||||
this.props.item.selected || this.props.selection === 'all'
|
||||
}
|
||||
onChange={ this.handleSelectItem }
|
||||
disabled={ this.props.selection === 'all' } />
|
||||
onChange={this.handleSelectItem}
|
||||
disabled={this.props.selection === 'all'} />
|
||||
</th>
|
||||
);
|
||||
}
|
||||
@ -74,14 +74,14 @@ const ListingItem = React.createClass({
|
||||
|
||||
if (action.name === 'trash') {
|
||||
custom_action = (
|
||||
<span key={ 'action-'+index } className="trash">
|
||||
<span key={'action-' + index} className="trash">
|
||||
{(!is_first) ? ' | ' : ''}
|
||||
<a
|
||||
href="javascript:;"
|
||||
onClick={ this.handleTrashItem.bind(
|
||||
onClick={this.handleTrashItem.bind(
|
||||
null,
|
||||
this.props.item.id
|
||||
) }>
|
||||
)}>
|
||||
{MailPoet.I18n.t('moveToTrash')}
|
||||
</a>
|
||||
</span>
|
||||
@ -89,8 +89,8 @@ const ListingItem = React.createClass({
|
||||
} else if (action.refresh) {
|
||||
custom_action = (
|
||||
<span
|
||||
onClick={ this.props.onRefreshItems }
|
||||
key={ 'action-'+index } className={ action.name }>
|
||||
onClick={this.props.onRefreshItems}
|
||||
key={'action-' + index} className={action.name}>
|
||||
{(!is_first) ? ' | ' : ''}
|
||||
{ action.link(this.props.item) }
|
||||
</span>
|
||||
@ -98,7 +98,7 @@ const ListingItem = React.createClass({
|
||||
} else if (action.link) {
|
||||
custom_action = (
|
||||
<span
|
||||
key={ 'action-'+index } className={ action.name }>
|
||||
key={'action-' + index} className={action.name}>
|
||||
{(!is_first) ? ' | ' : ''}
|
||||
{ action.link(this.props.item) }
|
||||
</span>
|
||||
@ -106,7 +106,7 @@ const ListingItem = React.createClass({
|
||||
} else {
|
||||
custom_action = (
|
||||
<span
|
||||
key={ 'action-'+index } className={ action.name }>
|
||||
key={'action-' + index} className={action.name}>
|
||||
{(!is_first) ? ' | ' : ''}
|
||||
<a href="javascript:;" onClick={
|
||||
(action.onClick !== undefined)
|
||||
@ -129,7 +129,7 @@ const ListingItem = React.createClass({
|
||||
} else {
|
||||
item_actions = (
|
||||
<span className="edit">
|
||||
<Link to={ `/edit/${ this.props.item.id }` }>{MailPoet.I18n.t('edit')}</Link>
|
||||
<Link to={`/edit/${this.props.item.id}`}>{MailPoet.I18n.t('edit')}</Link>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@ -143,7 +143,7 @@ const ListingItem = React.createClass({
|
||||
<span>
|
||||
<a
|
||||
href="javascript:;"
|
||||
onClick={ this.handleRestoreItem.bind(
|
||||
onClick={this.handleRestoreItem.bind(
|
||||
null,
|
||||
this.props.item.id
|
||||
)}
|
||||
@ -154,7 +154,7 @@ const ListingItem = React.createClass({
|
||||
<a
|
||||
className="submitdelete"
|
||||
href="javascript:;"
|
||||
onClick={ this.handleDeleteItem.bind(
|
||||
onClick={this.handleDeleteItem.bind(
|
||||
null,
|
||||
this.props.item.id
|
||||
)}
|
||||
@ -162,7 +162,7 @@ const ListingItem = React.createClass({
|
||||
</span>
|
||||
</div>
|
||||
<button
|
||||
onClick={ this.handleToggleItem.bind(null, this.props.item.id) }
|
||||
onClick={this.handleToggleItem.bind(null, this.props.item.id)}
|
||||
className="toggle-row" type="button">
|
||||
<span className="screen-reader-text">{MailPoet.I18n.t('showMoreDetails')}</span>
|
||||
</button>
|
||||
@ -175,7 +175,7 @@ const ListingItem = React.createClass({
|
||||
{ item_actions }
|
||||
</div>
|
||||
<button
|
||||
onClick={ this.handleToggleItem.bind(null, this.props.item.id) }
|
||||
onClick={this.handleToggleItem.bind(null, this.props.item.id)}
|
||||
className="toggle-row" type="button">
|
||||
<span className="screen-reader-text">{MailPoet.I18n.t('showMoreDetails')}</span>
|
||||
</button>
|
||||
@ -186,7 +186,7 @@ const ListingItem = React.createClass({
|
||||
const row_classes = classNames({ 'is-expanded': this.state.expanded });
|
||||
|
||||
return (
|
||||
<tr className={ row_classes }>
|
||||
<tr className={row_classes}>
|
||||
{ checkbox }
|
||||
{ this.props.onRenderItem(this.props.item, actions) }
|
||||
</tr>
|
||||
@ -226,7 +226,7 @@ const ListingItems = React.createClass({
|
||||
} else {
|
||||
const select_all_classes = classNames(
|
||||
'mailpoet_select_all',
|
||||
{ 'mailpoet_hidden': (
|
||||
{ mailpoet_hidden: (
|
||||
this.props.selection === false
|
||||
|| (this.props.count <= this.props.limit)
|
||||
),
|
||||
@ -235,7 +235,7 @@ const ListingItems = React.createClass({
|
||||
|
||||
return (
|
||||
<tbody>
|
||||
<tr className={ select_all_classes }>
|
||||
<tr className={select_all_classes}>
|
||||
<td colSpan={
|
||||
this.props.columns.length
|
||||
+ (this.props.is_selectable ? 1 : 0)
|
||||
@ -250,7 +250,7 @@ const ListingItems = React.createClass({
|
||||
}
|
||||
|
||||
<a
|
||||
onClick={ this.props.onSelectAll }
|
||||
onClick={this.props.onSelectAll}
|
||||
href="javascript:;">{
|
||||
(this.props.selection !== 'all')
|
||||
? MailPoet.I18n.t('selectAllLink')
|
||||
@ -260,24 +260,25 @@ const ListingItems = React.createClass({
|
||||
</tr>
|
||||
|
||||
{this.props.items.map((item, index) => {
|
||||
item.id = parseInt(item.id, 10);
|
||||
item.selected = (this.props.selected_ids.indexOf(item.id) !== -1);
|
||||
const renderItem = item;
|
||||
renderItem.id = parseInt(item.id, 10);
|
||||
renderItem.selected = (this.props.selected_ids.indexOf(renderItem.id) !== -1);
|
||||
|
||||
return (
|
||||
<ListingItem
|
||||
columns={ this.props.columns }
|
||||
onSelectItem={ this.props.onSelectItem }
|
||||
onRenderItem={ this.props.onRenderItem }
|
||||
onDeleteItem={ this.props.onDeleteItem }
|
||||
onRestoreItem={ this.props.onRestoreItem }
|
||||
onTrashItem={ this.props.onTrashItem }
|
||||
onRefreshItems={ this.props.onRefreshItems }
|
||||
selection={ this.props.selection }
|
||||
is_selectable={ this.props.is_selectable }
|
||||
item_actions={ this.props.item_actions }
|
||||
group={ this.props.group }
|
||||
key={ `item-${item.id}-${index}` }
|
||||
item={ item } />
|
||||
columns={this.props.columns}
|
||||
onSelectItem={this.props.onSelectItem}
|
||||
onRenderItem={this.props.onRenderItem}
|
||||
onDeleteItem={this.props.onDeleteItem}
|
||||
onRestoreItem={this.props.onRestoreItem}
|
||||
onTrashItem={this.props.onTrashItem}
|
||||
onRefreshItems={this.props.onRefreshItems}
|
||||
selection={this.props.selection}
|
||||
is_selectable={this.props.is_selectable}
|
||||
item_actions={this.props.item_actions}
|
||||
group={this.props.group}
|
||||
key={`item-${renderItem.id}-${index}`}
|
||||
item={renderItem} />
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
@ -320,7 +321,7 @@ const Listing = React.createClass({
|
||||
if (params.splat) {
|
||||
params.splat.split('/').map((param) => {
|
||||
const [key, value] = this.getParam(param);
|
||||
switch(key) {
|
||||
switch (key) {
|
||||
case 'filter':
|
||||
const filters = {};
|
||||
value.split('&').map((pair) => {
|
||||
@ -412,22 +413,23 @@ const Listing = React.createClass({
|
||||
|
||||
if (base_url !== null) {
|
||||
base_url = this.setBaseUrlParams(base_url);
|
||||
return `/${ base_url }/${ params }`;
|
||||
return `/${base_url}/${params}`;
|
||||
} else {
|
||||
return `/${ params }`;
|
||||
return `/${params}`;
|
||||
}
|
||||
},
|
||||
setBaseUrlParams: function (base_url) {
|
||||
if (base_url.indexOf(':') !== -1) {
|
||||
let ret = base_url;
|
||||
if (ret.indexOf(':') !== -1) {
|
||||
const params = this.getParams();
|
||||
Object.keys(params).map((key) => {
|
||||
if (base_url.indexOf(':'+key) !== -1) {
|
||||
base_url = base_url.replace(':'+key, params[key]);
|
||||
if (ret.indexOf(':' + key) !== -1) {
|
||||
ret = ret.replace(':' + key, params[key]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return base_url;
|
||||
return ret;
|
||||
},
|
||||
componentDidMount: function () {
|
||||
if (this.isMounted()) {
|
||||
@ -487,7 +489,7 @@ const Listing = React.createClass({
|
||||
}
|
||||
});
|
||||
}).fail((response) => {
|
||||
if(response.errors.length > 0) {
|
||||
if (response.errors.length > 0) {
|
||||
MailPoet.Notice.error(
|
||||
response.errors.map((error) => { return error.message; }),
|
||||
{ scroll: true }
|
||||
@ -629,7 +631,7 @@ const Listing = React.createClass({
|
||||
}).done(() => {
|
||||
this.getItems();
|
||||
}).fail((response) => {
|
||||
if(response.errors.length > 0) {
|
||||
if (response.errors.length > 0) {
|
||||
MailPoet.Notice.error(
|
||||
response.errors.map((error) => { return error.message; }),
|
||||
{ scroll: true }
|
||||
@ -656,11 +658,11 @@ const Listing = React.createClass({
|
||||
});
|
||||
},
|
||||
handleSelectItem: function (id, is_checked) {
|
||||
let selected_ids = this.state.selected_ids,
|
||||
selection = false;
|
||||
let selected_ids = this.state.selected_ids;
|
||||
let selection = false;
|
||||
|
||||
if (is_checked) {
|
||||
selected_ids = jQuery.merge(selected_ids, [ id ]);
|
||||
selected_ids = jQuery.merge(selected_ids, [id]);
|
||||
// check whether all items on the page are selected
|
||||
if (
|
||||
jQuery('tbody .check-column :checkbox:not(:checked)').length === 0
|
||||
@ -781,14 +783,14 @@ const Listing = React.createClass({
|
||||
'widefat',
|
||||
'fixed',
|
||||
'striped',
|
||||
{ 'mailpoet_listing_loading': this.state.loading }
|
||||
{ mailpoet_listing_loading: this.state.loading }
|
||||
);
|
||||
|
||||
// search
|
||||
let search = (
|
||||
<ListingSearch
|
||||
onSearch={ this.handleSearch }
|
||||
search={ this.state.search }
|
||||
onSearch={this.handleSearch}
|
||||
search={this.state.search}
|
||||
/>
|
||||
);
|
||||
if (this.props.search === false) {
|
||||
@ -798,9 +800,9 @@ const Listing = React.createClass({
|
||||
// groups
|
||||
let groups = (
|
||||
<ListingGroups
|
||||
groups={ this.state.groups }
|
||||
group={ this.state.group }
|
||||
onSelectGroup={ this.handleGroup }
|
||||
groups={this.state.groups}
|
||||
group={this.state.group}
|
||||
onSelectGroup={this.handleGroup}
|
||||
/>
|
||||
);
|
||||
if (this.props.groups === false) {
|
||||
@ -819,81 +821,81 @@ const Listing = React.createClass({
|
||||
{ search }
|
||||
<div className="tablenav top clearfix">
|
||||
<ListingBulkActions
|
||||
count={ this.state.count }
|
||||
bulk_actions={ bulk_actions }
|
||||
selection={ this.state.selection }
|
||||
selected_ids={ this.state.selected_ids }
|
||||
onBulkAction={ this.handleBulkAction } />
|
||||
count={this.state.count}
|
||||
bulk_actions={bulk_actions}
|
||||
selection={this.state.selection}
|
||||
selected_ids={this.state.selected_ids}
|
||||
onBulkAction={this.handleBulkAction} />
|
||||
<ListingFilters
|
||||
filters={ this.state.filters }
|
||||
filter={ this.state.filter }
|
||||
group={ this.state.group }
|
||||
onBeforeSelectFilter={ this.props.onBeforeSelectFilter || null }
|
||||
onSelectFilter={ this.handleFilter }
|
||||
onEmptyTrash={ this.handleEmptyTrash }
|
||||
filters={this.state.filters}
|
||||
filter={this.state.filter}
|
||||
group={this.state.group}
|
||||
onBeforeSelectFilter={this.props.onBeforeSelectFilter || null}
|
||||
onSelectFilter={this.handleFilter}
|
||||
onEmptyTrash={this.handleEmptyTrash}
|
||||
/>
|
||||
<ListingPages
|
||||
count={ this.state.count }
|
||||
page={ this.state.page }
|
||||
limit={ this.state.limit }
|
||||
onSetPage={ this.handleSetPage } />
|
||||
count={this.state.count}
|
||||
page={this.state.page}
|
||||
limit={this.state.limit}
|
||||
onSetPage={this.handleSetPage} />
|
||||
</div>
|
||||
<table className={ table_classes }>
|
||||
<table className={table_classes}>
|
||||
<thead>
|
||||
<ListingHeader
|
||||
onSort={ this.handleSort }
|
||||
onSelectItems={ this.handleSelectItems }
|
||||
selection={ this.state.selection }
|
||||
sort_by={ sort_by }
|
||||
sort_order={ sort_order }
|
||||
columns={ columns }
|
||||
is_selectable={ bulk_actions.length > 0 } />
|
||||
onSort={this.handleSort}
|
||||
onSelectItems={this.handleSelectItems}
|
||||
selection={this.state.selection}
|
||||
sort_by={sort_by}
|
||||
sort_order={sort_order}
|
||||
columns={columns}
|
||||
is_selectable={bulk_actions.length > 0} />
|
||||
</thead>
|
||||
|
||||
<ListingItems
|
||||
onRenderItem={ this.handleRenderItem }
|
||||
onDeleteItem={ this.handleDeleteItem }
|
||||
onRestoreItem={ this.handleRestoreItem }
|
||||
onTrashItem={ this.handleTrashItem }
|
||||
onRefreshItems={ this.handleRefreshItems }
|
||||
columns={ columns }
|
||||
is_selectable={ bulk_actions.length > 0 }
|
||||
onSelectItem={ this.handleSelectItem }
|
||||
onSelectAll={ this.handleSelectAll }
|
||||
selection={ this.state.selection }
|
||||
selected_ids={ this.state.selected_ids }
|
||||
loading={ this.state.loading }
|
||||
group={ this.state.group }
|
||||
count={ this.state.count }
|
||||
limit={ this.state.limit }
|
||||
item_actions={ item_actions }
|
||||
messages={ messages }
|
||||
items={ items } />
|
||||
onRenderItem={this.handleRenderItem}
|
||||
onDeleteItem={this.handleDeleteItem}
|
||||
onRestoreItem={this.handleRestoreItem}
|
||||
onTrashItem={this.handleTrashItem}
|
||||
onRefreshItems={this.handleRefreshItems}
|
||||
columns={columns}
|
||||
is_selectable={bulk_actions.length > 0}
|
||||
onSelectItem={this.handleSelectItem}
|
||||
onSelectAll={this.handleSelectAll}
|
||||
selection={this.state.selection}
|
||||
selected_ids={this.state.selected_ids}
|
||||
loading={this.state.loading}
|
||||
group={this.state.group}
|
||||
count={this.state.count}
|
||||
limit={this.state.limit}
|
||||
item_actions={item_actions}
|
||||
messages={messages}
|
||||
items={items} />
|
||||
|
||||
<tfoot>
|
||||
<ListingHeader
|
||||
onSort={ this.handleSort }
|
||||
onSelectItems={ this.handleSelectItems }
|
||||
selection={ this.state.selection }
|
||||
sort_by={ sort_by }
|
||||
sort_order={ sort_order }
|
||||
columns={ columns }
|
||||
is_selectable={ bulk_actions.length > 0 } />
|
||||
onSort={this.handleSort}
|
||||
onSelectItems={this.handleSelectItems}
|
||||
selection={this.state.selection}
|
||||
sort_by={sort_by}
|
||||
sort_order={sort_order}
|
||||
columns={columns}
|
||||
is_selectable={bulk_actions.length > 0} />
|
||||
</tfoot>
|
||||
|
||||
</table>
|
||||
<div className="tablenav bottom">
|
||||
<ListingBulkActions
|
||||
count={ this.state.count }
|
||||
bulk_actions={ bulk_actions }
|
||||
selection={ this.state.selection }
|
||||
selected_ids={ this.state.selected_ids }
|
||||
onBulkAction={ this.handleBulkAction } />
|
||||
count={this.state.count}
|
||||
bulk_actions={bulk_actions}
|
||||
selection={this.state.selection}
|
||||
selected_ids={this.state.selected_ids}
|
||||
onBulkAction={this.handleBulkAction} />
|
||||
<ListingPages
|
||||
count={ this.state.count }
|
||||
page={ this.state.page }
|
||||
limit={ this.state.limit }
|
||||
onSetPage={ this.handleSetPage } />
|
||||
count={this.state.count}
|
||||
page={this.state.page}
|
||||
limit={this.state.limit}
|
||||
onSetPage={this.handleSetPage} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
@ -41,7 +41,7 @@ define([
|
||||
return Math.min(Math.max(1, Math.abs(~~page)), this.getLastPage());
|
||||
},
|
||||
handleSetManualPage: function (e) {
|
||||
if(e.which === 13) {
|
||||
if (e.which === 13) {
|
||||
this.setPage(this.state.page);
|
||||
}
|
||||
},
|
||||
@ -57,7 +57,7 @@ define([
|
||||
return Math.ceil(this.props.count / this.props.limit);
|
||||
},
|
||||
render: function () {
|
||||
if(this.props.count === 0) {
|
||||
if (this.props.count === 0) {
|
||||
return false;
|
||||
} else {
|
||||
let pagination = false;
|
||||
@ -74,11 +74,11 @@ define([
|
||||
<span aria-hidden="true" className="tablenav-pages-navspan">»</span>
|
||||
);
|
||||
|
||||
if(this.props.limit > 0 && this.props.count > this.props.limit) {
|
||||
if(this.props.page > 1) {
|
||||
if (this.props.limit > 0 && this.props.count > this.props.limit) {
|
||||
if (this.props.page > 1) {
|
||||
previousPage = (
|
||||
<a href="javascript:;"
|
||||
onClick={ this.setPreviousPage }
|
||||
onClick={this.setPreviousPage}
|
||||
className="prev-page">
|
||||
<span className="screen-reader-text">{MailPoet.I18n.t('previousPage')}</span>
|
||||
<span aria-hidden="true">‹</span>
|
||||
@ -86,10 +86,10 @@ define([
|
||||
);
|
||||
}
|
||||
|
||||
if(this.props.page > 2) {
|
||||
if (this.props.page > 2) {
|
||||
firstPage = (
|
||||
<a href="javascript:;"
|
||||
onClick={ this.setFirstPage }
|
||||
onClick={this.setFirstPage}
|
||||
className="first-page">
|
||||
<span className="screen-reader-text">{MailPoet.I18n.t('firstPage')}</span>
|
||||
<span aria-hidden="true">«</span>
|
||||
@ -97,10 +97,10 @@ define([
|
||||
);
|
||||
}
|
||||
|
||||
if(this.props.page < this.getLastPage()) {
|
||||
if (this.props.page < this.getLastPage()) {
|
||||
nextPage = (
|
||||
<a href="javascript:;"
|
||||
onClick={ this.setNextPage }
|
||||
onClick={this.setNextPage}
|
||||
className="next-page">
|
||||
<span className="screen-reader-text">{MailPoet.I18n.t('nextPage')}</span>
|
||||
<span aria-hidden="true">›</span>
|
||||
@ -108,10 +108,10 @@ define([
|
||||
);
|
||||
}
|
||||
|
||||
if(this.props.page < this.getLastPage() - 1) {
|
||||
if (this.props.page < this.getLastPage() - 1) {
|
||||
lastPage = (
|
||||
<a href="javascript:;"
|
||||
onClick={ this.setLastPage }
|
||||
onClick={this.setLastPage}
|
||||
className="last-page">
|
||||
<span className="screen-reader-text">{MailPoet.I18n.t('lastPage')}</span>
|
||||
<span aria-hidden="true">»</span>
|
||||
@ -119,8 +119,8 @@ define([
|
||||
);
|
||||
}
|
||||
|
||||
let pageValue = this.props.page;
|
||||
if(this.state.page !== null) {
|
||||
let pageValue = this.props.page;
|
||||
if (this.state.page !== null) {
|
||||
pageValue = this.state.page;
|
||||
}
|
||||
|
||||
@ -136,13 +136,13 @@ define([
|
||||
htmlFor="current-page-selector">{MailPoet.I18n.t('currentPage')}</label>
|
||||
<input
|
||||
type="text"
|
||||
onChange={ this.handleChangeManualPage }
|
||||
onKeyUp={ this.handleSetManualPage }
|
||||
onBlur={ this.handleBlurManualPage }
|
||||
onChange={this.handleChangeManualPage}
|
||||
onKeyUp={this.handleSetManualPage}
|
||||
onBlur={this.handleBlurManualPage}
|
||||
aria-describedby="table-paging"
|
||||
size="2"
|
||||
ref="page"
|
||||
value={ pageValue }
|
||||
value={pageValue}
|
||||
name="paged"
|
||||
id="current-page-selector"
|
||||
className="current-page" />
|
||||
@ -172,7 +172,7 @@ define([
|
||||
.replace('%$1d', this.props.count.toLocaleString());
|
||||
}
|
||||
return (
|
||||
<div className={ classes }>
|
||||
<div className={classes}>
|
||||
<span className="displaying-num">{ numberOfItemsLabel }</span>
|
||||
{ pagination }
|
||||
</div>
|
||||
|
@ -17,14 +17,14 @@ define([
|
||||
this.refs.search.value = nextProps.search;
|
||||
},
|
||||
render: function () {
|
||||
if(this.props.search === false) {
|
||||
if (this.props.search === false) {
|
||||
return false;
|
||||
} else {
|
||||
return (
|
||||
<form name="search" onSubmit={this.handleSearch}>
|
||||
<p className="search-box">
|
||||
<label htmlFor="search_input" className="screen-reader-text">
|
||||
{MailPoet.I18n.t('searchLabel')}
|
||||
{MailPoet.I18n.t('searchLabel')}
|
||||
</label>
|
||||
<input
|
||||
type="search"
|
||||
|
@ -1,4 +1,4 @@
|
||||
define('mailpoet', [], function() {
|
||||
define('mailpoet', [], function () {
|
||||
// A placeholder for MailPoet object
|
||||
var MailPoet = {};
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,7 @@
|
||||
define('mp2migrator', ['mailpoet', 'jquery'], function(MailPoet, jQuery) {
|
||||
define('mp2migrator', ['mailpoet', 'jquery'], function (mp, jQuery) {
|
||||
'use strict';
|
||||
|
||||
var MailPoet = mp;
|
||||
MailPoet.MP2Migrator = {
|
||||
|
||||
fatal_error: '',
|
||||
@ -10,7 +12,7 @@ define('mp2migrator', ['mailpoet', 'jquery'], function(MailPoet, jQuery) {
|
||||
clearTimeout(MailPoet.MP2Migrator.displayLogs_timeout);
|
||||
clearTimeout(MailPoet.MP2Migrator.updateProgressbar_timeout);
|
||||
clearTimeout(MailPoet.MP2Migrator.update_wordpress_info_timeout);
|
||||
setTimeout(MailPoet.MP2Migrator.updateDisplay, 1000)
|
||||
setTimeout(MailPoet.MP2Migrator.updateDisplay, 1000);
|
||||
},
|
||||
|
||||
stopLogger: function () {
|
||||
@ -24,25 +26,26 @@ define('mp2migrator', ['mailpoet', 'jquery'], function(MailPoet, jQuery) {
|
||||
|
||||
displayLogs: function () {
|
||||
jQuery.ajax({
|
||||
url: mailpoet_mp2_migrator.log_file_url,
|
||||
url: window.mailpoet_mp2_migrator.log_file_url,
|
||||
cache: false
|
||||
}).done(function (result) {
|
||||
jQuery("#logger").html('');
|
||||
result.split("\n").forEach(function (row) {
|
||||
if(row.substr(0, 7) === '[ERROR]' || row.substr(0, 9) === '[WARNING]' || row === MailPoet.I18n.t('import_stopped_by_user')) {
|
||||
jQuery('#logger').html('');
|
||||
result.split('\n').forEach(function (resultRow) {
|
||||
var row = resultRow;
|
||||
if (row.substr(0, 7) === '[ERROR]' || row.substr(0, 9) === '[WARNING]' || row === MailPoet.I18n.t('import_stopped_by_user')) {
|
||||
row = '<span class="error_msg">' + row + '</span>'; // Mark the errors in red
|
||||
}
|
||||
// Test if the import is complete
|
||||
else if(row === MailPoet.I18n.t('import_complete')) {
|
||||
else if (row === MailPoet.I18n.t('import_complete')) {
|
||||
jQuery('#import-actions').hide();
|
||||
jQuery('#upgrade-completed').show();
|
||||
}
|
||||
jQuery("#logger").append(row + "<br />\n");
|
||||
jQuery('#logger').append(row + '<br />\n');
|
||||
|
||||
});
|
||||
jQuery("#logger").append('<span class="error_msg">' + MailPoet.MP2Migrator.fatal_error + '</span>' + "<br />\n");
|
||||
jQuery('#logger').append('<span class="error_msg">' + MailPoet.MP2Migrator.fatal_error + '</span>' + '<br />\n');
|
||||
}).always(function () {
|
||||
if(MailPoet.MP2Migrator.is_logging) {
|
||||
if (MailPoet.MP2Migrator.is_logging) {
|
||||
MailPoet.MP2Migrator.displayLogs_timeout = setTimeout(MailPoet.MP2Migrator.displayLogs, 1000);
|
||||
}
|
||||
});
|
||||
@ -50,23 +53,23 @@ define('mp2migrator', ['mailpoet', 'jquery'], function(MailPoet, jQuery) {
|
||||
|
||||
updateProgressbar: function () {
|
||||
jQuery.ajax({
|
||||
url: mailpoet_mp2_migrator.progress_url,
|
||||
url: window.mailpoet_mp2_migrator.progress_url,
|
||||
cache: false,
|
||||
dataType: 'json'
|
||||
}).always(function (result) {
|
||||
// Move the progress bar
|
||||
var progress = 0;
|
||||
if((result.total !== undefined) && (Number(result.total) !== 0)) {
|
||||
if ((result.total !== undefined) && (Number(result.total) !== 0)) {
|
||||
progress = Math.round(Number(result.current) / Number(result.total) * 100);
|
||||
}
|
||||
jQuery('#progressbar').progressbar('option', 'value', progress);
|
||||
jQuery('#progresslabel').html(progress + '%');
|
||||
if(Number(result.current) !== 0) {
|
||||
if (Number(result.current) !== 0) {
|
||||
jQuery('#skip-import').hide();
|
||||
jQuery('#progressbar').show();
|
||||
jQuery('#logger-container').show();
|
||||
}
|
||||
if(MailPoet.MP2Migrator.is_logging) {
|
||||
if (MailPoet.MP2Migrator.is_logging) {
|
||||
MailPoet.MP2Migrator.updateProgressbar_timeout = setTimeout(MailPoet.MP2Migrator.updateProgressbar, 1000);
|
||||
}
|
||||
});
|
||||
@ -97,16 +100,16 @@ define('mp2migrator', ['mailpoet', 'jquery'], function(MailPoet, jQuery) {
|
||||
MailPoet.MP2Migrator.updateDisplay(); // Get the latest information after the import was stopped
|
||||
MailPoet.MP2Migrator.reactivateImportButton();
|
||||
}).done(function (response) {
|
||||
if(response) {
|
||||
if (response) {
|
||||
MailPoet.MP2Migrator.fatal_error = response.data;
|
||||
}
|
||||
}).fail(function (response) {
|
||||
if(response.errors.length > 0) {
|
||||
if (response.errors.length > 0) {
|
||||
MailPoet.Notice.error(
|
||||
response.errors.map(function (error) {
|
||||
return error.message;
|
||||
}),
|
||||
{scroll: true}
|
||||
{ scroll: true }
|
||||
);
|
||||
}
|
||||
});
|
||||
@ -132,12 +135,12 @@ define('mp2migrator', ['mailpoet', 'jquery'], function(MailPoet, jQuery) {
|
||||
MailPoet.MP2Migrator.reactivateImportButton();
|
||||
MailPoet.MP2Migrator.updateDisplay(); // Get the latest information after the import was stopped
|
||||
}).fail(function (response) {
|
||||
if(response.errors.length > 0) {
|
||||
if (response.errors.length > 0) {
|
||||
MailPoet.Notice.error(
|
||||
response.errors.map(function (error) {
|
||||
return error.message;
|
||||
}),
|
||||
{scroll: true}
|
||||
{ scroll: true }
|
||||
);
|
||||
}
|
||||
});
|
||||
@ -155,12 +158,12 @@ define('mp2migrator', ['mailpoet', 'jquery'], function(MailPoet, jQuery) {
|
||||
}).done(function () {
|
||||
MailPoet.MP2Migrator.gotoWelcomePage();
|
||||
}).fail(function (response) {
|
||||
if(response.errors.length > 0) {
|
||||
if (response.errors.length > 0) {
|
||||
MailPoet.Notice.error(
|
||||
response.errors.map(function (error) {
|
||||
return error.message;
|
||||
}),
|
||||
{scroll: true}
|
||||
{ scroll: true }
|
||||
);
|
||||
}
|
||||
});
|
||||
@ -173,33 +176,33 @@ define('mp2migrator', ['mailpoet', 'jquery'], function(MailPoet, jQuery) {
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Actions to run when the DOM is ready
|
||||
*/
|
||||
jQuery(function () {
|
||||
jQuery('#progressbar').progressbar({value: 0});
|
||||
jQuery('#progressbar').progressbar({ value: 0 });
|
||||
|
||||
// Import button
|
||||
jQuery('#import').click(function() {
|
||||
jQuery('#import').click(function () {
|
||||
MailPoet.MP2Migrator.startImport();
|
||||
});
|
||||
|
||||
|
||||
// Stop import button
|
||||
jQuery('#stop-import').click(function() {
|
||||
jQuery('#stop-import').click(function () {
|
||||
MailPoet.MP2Migrator.stopImport();
|
||||
});
|
||||
|
||||
// Skip import link
|
||||
jQuery('#skip-import').click(function() {
|
||||
jQuery('#skip-import').click(function () {
|
||||
MailPoet.MP2Migrator.skipImport();
|
||||
});
|
||||
|
||||
// Go to welcome page
|
||||
jQuery('#goto-welcome').click(function() {
|
||||
jQuery('#goto-welcome').click(function () {
|
||||
MailPoet.MP2Migrator.gotoWelcomePage();
|
||||
});
|
||||
|
||||
|
||||
// Update the display
|
||||
MailPoet.MP2Migrator.updateDisplay();
|
||||
});
|
||||
|
@ -1,12 +1,9 @@
|
||||
define([
|
||||
'backbone',
|
||||
'backbone.marionette',
|
||||
'backbone.radio',
|
||||
'jquery',
|
||||
'underscore',
|
||||
'handlebars',
|
||||
'handlebars_helpers'
|
||||
], function(Backbone, Marionette, Radio, jQuery, _, Handlebars) {
|
||||
'backbone',
|
||||
'backbone.marionette',
|
||||
'backbone.radio'
|
||||
], function (Backbone, Marionette, BackboneRadio) {
|
||||
var Radio = BackboneRadio;
|
||||
|
||||
var AppView = Marionette.View.extend({
|
||||
el: '#mailpoet_editor',
|
||||
@ -22,13 +19,15 @@ define([
|
||||
var EditorApplication = Marionette.Application.extend({
|
||||
region: '#mailpoet_editor',
|
||||
|
||||
onStart: function() {
|
||||
onStart: function () {
|
||||
this._appView = new AppView();
|
||||
this.showView(this._appView);
|
||||
},
|
||||
|
||||
getChannel: function(channel) {
|
||||
if (channel === undefined) channel = 'global';
|
||||
getChannel: function (channel) {
|
||||
if (channel === undefined) {
|
||||
return Radio.channel('global');
|
||||
}
|
||||
return Radio.channel(channel);
|
||||
}
|
||||
});
|
||||
|
@ -5,11 +5,11 @@
|
||||
* For more check: http://marionettejs.com/docs/marionette.behaviors.html#behaviorslookup
|
||||
*/
|
||||
define([
|
||||
'backbone.marionette'
|
||||
], function(Marionette) {
|
||||
|
||||
'backbone.marionette'
|
||||
], function (BackboneMarionette) {
|
||||
var Marionette = BackboneMarionette;
|
||||
var BehaviorsLookup = {};
|
||||
Marionette.Behaviors.behaviorsLookup = function() {
|
||||
Marionette.Behaviors.behaviorsLookup = function () {
|
||||
return BehaviorsLookup;
|
||||
};
|
||||
|
||||
|
@ -4,22 +4,43 @@
|
||||
* Adds a color picker integration with the view
|
||||
*/
|
||||
define([
|
||||
'backbone.marionette',
|
||||
'newsletter_editor/behaviors/BehaviorsLookup',
|
||||
'mailpoet',
|
||||
'spectrum'
|
||||
], function(Marionette, BehaviorsLookup, MailPoet, Spectrum) {
|
||||
'backbone.marionette',
|
||||
'newsletter_editor/behaviors/BehaviorsLookup',
|
||||
'mailpoet',
|
||||
'spectrum'
|
||||
], function (Marionette, BehaviorsLookup, MailPoet) {
|
||||
var BL = BehaviorsLookup;
|
||||
|
||||
BehaviorsLookup.ColorPickerBehavior = Marionette.Behavior.extend({
|
||||
onRender: function() {
|
||||
this.view.$('.mailpoet_color').spectrum({
|
||||
clickoutFiresChange: true,
|
||||
showInput: true,
|
||||
showInitial: true,
|
||||
preferredFormat: "hex6",
|
||||
allowEmpty: true,
|
||||
chooseText: MailPoet.I18n.t('selectColor'),
|
||||
cancelText: MailPoet.I18n.t('cancelColorSelection')
|
||||
BL.ColorPickerBehavior = Marionette.Behavior.extend({
|
||||
onRender: function () {
|
||||
var that = this;
|
||||
var preferredFormat = 'hex6';
|
||||
this.view.$('.mailpoet_color').each(function () {
|
||||
var $input = that.view.$(this);
|
||||
var updateColorInput = function (color) {
|
||||
if (color && color.getAlpha() > 0) {
|
||||
$input.val(color.toString(preferredFormat));
|
||||
} else {
|
||||
$input.val('');
|
||||
}
|
||||
$input.trigger('change');
|
||||
};
|
||||
$input.spectrum({
|
||||
clickoutFiresChange: true,
|
||||
showInput: true,
|
||||
showInitial: true,
|
||||
showPalette: true,
|
||||
showSelectionPalette: true,
|
||||
palette: [],
|
||||
localStorageKey: 'newsletter_editor.spectrum.palette',
|
||||
preferredFormat: preferredFormat,
|
||||
allowEmpty: true,
|
||||
chooseText: MailPoet.I18n.t('selectColor'),
|
||||
cancelText: MailPoet.I18n.t('cancelColorSelection'),
|
||||
change: updateColorInput,
|
||||
move: updateColorInput,
|
||||
hide: updateColorInput
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -1,3 +1,4 @@
|
||||
|
||||
/**
|
||||
* ContainerDropZoneBehavior
|
||||
*
|
||||
@ -6,28 +7,29 @@
|
||||
* accept droppables
|
||||
*/
|
||||
define([
|
||||
'backbone.marionette',
|
||||
'underscore',
|
||||
'jquery',
|
||||
'newsletter_editor/behaviors/BehaviorsLookup',
|
||||
'interact'
|
||||
], function(Marionette, _, jQuery, BehaviorsLookup, interact) {
|
||||
'backbone.marionette',
|
||||
'underscore',
|
||||
'jquery',
|
||||
'newsletter_editor/behaviors/BehaviorsLookup',
|
||||
'interact'
|
||||
], function (Marionette, _, jQuery, BL, interact) {
|
||||
var BehaviorsLookup = BL;
|
||||
|
||||
BehaviorsLookup.ContainerDropZoneBehavior = Marionette.Behavior.extend({
|
||||
defaults: {
|
||||
columnLimit: 3
|
||||
},
|
||||
onRender: function() {
|
||||
onRender: function () {
|
||||
var dragAndDropDisabled = _.isObject(this.view.options.renderOptions) && this.view.options.renderOptions.disableDragAndDrop === true;
|
||||
if (!dragAndDropDisabled) {
|
||||
this.addDropZone();
|
||||
this.addDropZone();
|
||||
}
|
||||
},
|
||||
addDropZone: function(_event) {
|
||||
var that = this,
|
||||
view = this.view,
|
||||
domElement = that.$el.get(0),
|
||||
acceptableElementSelector;
|
||||
addDropZone: function () {
|
||||
var that = this;
|
||||
var view = this.view;
|
||||
var domElement = that.$el.get(0);
|
||||
var acceptableElementSelector;
|
||||
|
||||
// TODO: Extract this limitation code to be controlled from containers
|
||||
if (this.view.renderOptions.depth === 0) {
|
||||
@ -45,36 +47,42 @@ define([
|
||||
interact(domElement).dropzone({
|
||||
accept: acceptableElementSelector,
|
||||
overlap: 'pointer', // Mouse pointer denotes location of a droppable
|
||||
ondragenter: function(event) {
|
||||
ondragenter: function () {
|
||||
// 1. Visually mark block as active for dropping
|
||||
view.$el.addClass('mailpoet_drop_active');
|
||||
},
|
||||
ondragleave: function(event) {
|
||||
ondragleave: function () {
|
||||
// 1. Remove visual markings of active dropping container
|
||||
// 2. Remove visual markings of drop position visualization
|
||||
that.cleanup();
|
||||
},
|
||||
ondropmove: function(event) {
|
||||
ondropmove: function (event) {
|
||||
// 1. Compute actual location of the mouse within the container
|
||||
// 2. Check if insertion is regular (between blocks) or special (with container insertion)
|
||||
// 3a. If insertion is regular, compute position where insertion should happen
|
||||
// 3b. If insertion is special, compute position (which side) and which cell the insertion belongs to
|
||||
// 4. If insertion at that position is not visualized, display position visualization there, remove other visualizations from this container
|
||||
var dropPosition = that.getDropPosition(
|
||||
event.dragmove.pageX,
|
||||
event.dragmove.pageY,
|
||||
view.$el,
|
||||
view.model.get('orientation'),
|
||||
view.model.get('blocks').length
|
||||
),
|
||||
element = view.$el,
|
||||
markerWidth = '',
|
||||
markerHeight = '',
|
||||
containerOffset = element.offset(),
|
||||
viewCollection = that.getCollection(),
|
||||
marker, targetModel, targetView, targetElement,
|
||||
topOffset, leftOffset, isLastBlockInsertion,
|
||||
$targetBlock, margin;
|
||||
event.dragmove.pageX,
|
||||
event.dragmove.pageY,
|
||||
view.$el,
|
||||
view.model.get('orientation'),
|
||||
view.model.get('blocks').length
|
||||
);
|
||||
var element = view.$el;
|
||||
var markerWidth = '';
|
||||
var markerHeight = '';
|
||||
var containerOffset = element.offset();
|
||||
var viewCollection = that.getCollection();
|
||||
var marker;
|
||||
var targetModel;
|
||||
var targetView;
|
||||
var targetElement;
|
||||
var topOffset;
|
||||
var leftOffset;
|
||||
var isLastBlockInsertion;
|
||||
var $targetBlock;
|
||||
var margin;
|
||||
|
||||
if (dropPosition === undefined) return;
|
||||
|
||||
@ -148,7 +156,7 @@ define([
|
||||
// compensated for to position marker right in the middle of two
|
||||
// blocks
|
||||
if (dropPosition.position === 'before') {
|
||||
$targetBlock = that.getChildren().findByModel(viewCollection.at(dropPosition.index-1)).$el;
|
||||
$targetBlock = that.getChildren().findByModel(viewCollection.at(dropPosition.index - 1)).$el;
|
||||
} else {
|
||||
$targetBlock = that.getChildren().findByModel(viewCollection.at(dropPosition.index)).$el;
|
||||
}
|
||||
@ -161,7 +169,7 @@ define([
|
||||
|
||||
element.append(marker);
|
||||
},
|
||||
ondrop: function(event) {
|
||||
ondrop: function (event) {
|
||||
// 1. Compute actual location of the mouse
|
||||
// 2. Check if insertion is regular (between blocks) or special (with container insertion)
|
||||
// 3a. If insertion is regular
|
||||
@ -176,15 +184,19 @@ define([
|
||||
// 4. Perform cleanup actions
|
||||
|
||||
var dropPosition = that.getDropPosition(
|
||||
event.dragEvent.pageX,
|
||||
event.dragEvent.pageY,
|
||||
view.$el,
|
||||
view.model.get('orientation'),
|
||||
view.model.get('blocks').length
|
||||
),
|
||||
droppableModel = event.draggable.getDropModel(),
|
||||
viewCollection = that.getCollection(),
|
||||
droppedView, droppedModel, index, tempCollection, tempCollection2;
|
||||
event.dragEvent.pageX,
|
||||
event.dragEvent.pageY,
|
||||
view.$el,
|
||||
view.model.get('orientation'),
|
||||
view.model.get('blocks').length
|
||||
);
|
||||
var droppableModel = event.draggable.getDropModel();
|
||||
var viewCollection = that.getCollection();
|
||||
var droppedView;
|
||||
var index;
|
||||
var tempCollection;
|
||||
var tempCollection2;
|
||||
var tempModel;
|
||||
|
||||
if (dropPosition === undefined) return;
|
||||
|
||||
@ -194,42 +206,43 @@ define([
|
||||
|
||||
if (view.model.get('orientation') === 'horizontal' && droppableModel.get('type') !== 'container') {
|
||||
// Regular blocks always need to be inserted into columns - vertical containers
|
||||
tempCollection = new (EditorApplication.getBlockTypeModel('container'))({
|
||||
orientation: 'vertical'
|
||||
|
||||
tempCollection = new (window.EditorApplication.getBlockTypeModel('container'))({
|
||||
orientation: 'vertical'
|
||||
});
|
||||
tempCollection.get('blocks').add(droppableModel);
|
||||
viewCollection.add(tempCollection, {at: index});
|
||||
viewCollection.add(tempCollection, { at: index });
|
||||
} else {
|
||||
viewCollection.add(droppableModel, {at: index});
|
||||
viewCollection.add(droppableModel, { at: index });
|
||||
}
|
||||
|
||||
droppedView = that.getChildren().findByModel(droppableModel);
|
||||
} else {
|
||||
// Special insertion by replacing target block with collection
|
||||
// and inserting dropModel into that
|
||||
var tempModel = viewCollection.at(dropPosition.index);
|
||||
tempModel = viewCollection.at(dropPosition.index);
|
||||
|
||||
tempCollection = new (EditorApplication.getBlockTypeModel('container'))({
|
||||
orientation: (view.model.get('orientation') === 'vertical') ? 'horizontal' : 'vertical'
|
||||
tempCollection = new (window.EditorApplication.getBlockTypeModel('container'))({
|
||||
orientation: (view.model.get('orientation') === 'vertical') ? 'horizontal' : 'vertical'
|
||||
});
|
||||
|
||||
viewCollection.remove(tempModel);
|
||||
|
||||
if (tempCollection.get('orientation') === 'horizontal') {
|
||||
if (dropPosition.position === 'before') {
|
||||
tempCollection2 = new (EditorApplication.getBlockTypeModel('container'))({
|
||||
tempCollection2 = new (window.EditorApplication.getBlockTypeModel('container'))({
|
||||
orientation: 'vertical'
|
||||
});
|
||||
tempCollection2.get('blocks').add(droppableModel);
|
||||
tempCollection.get('blocks').add(tempCollection2);
|
||||
}
|
||||
tempCollection2 = new (EditorApplication.getBlockTypeModel('container'))({
|
||||
tempCollection2 = new (window.EditorApplication.getBlockTypeModel('container'))({
|
||||
orientation: 'vertical'
|
||||
});
|
||||
tempCollection2.get('blocks').add(tempModel);
|
||||
tempCollection.get('blocks').add(tempCollection2);
|
||||
if (dropPosition.position === 'after') {
|
||||
tempCollection2 = new (EditorApplication.getBlockTypeModel('container'))({
|
||||
tempCollection2 = new (window.EditorApplication.getBlockTypeModel('container'))({
|
||||
orientation: 'vertical'
|
||||
});
|
||||
tempCollection2.get('blocks').add(droppableModel);
|
||||
@ -244,7 +257,7 @@ define([
|
||||
tempCollection.get('blocks').add(droppableModel);
|
||||
}
|
||||
}
|
||||
viewCollection.add(tempCollection, {at: dropPosition.index});
|
||||
viewCollection.add(tempCollection, { at: dropPosition.index });
|
||||
|
||||
// Call post add actions
|
||||
droppedView = that.getChildren().findByModel(tempCollection).children.findByModel(droppableModel);
|
||||
@ -261,36 +274,40 @@ define([
|
||||
}
|
||||
});
|
||||
},
|
||||
cleanup: function() {
|
||||
cleanup: function () {
|
||||
// 1. Remove visual markings of active dropping container
|
||||
this.view.$el.removeClass('mailpoet_drop_active');
|
||||
|
||||
// 2. Remove visual markings of drop position visualization
|
||||
this.view.$('.mailpoet_drop_marker').remove();
|
||||
},
|
||||
getDropPosition: function(eventX, eventY, unsafe) {
|
||||
var SPECIAL_AREA_INSERTION_WIDTH = 0.00, // Disable special insertion. Default: 0.3
|
||||
getDropPosition: function (eventX, eventY, is_unsafe) {
|
||||
var SPECIAL_AREA_INSERTION_WIDTH = 0.00; // Disable special insertion. Default: 0.3
|
||||
|
||||
element = this.view.$el,
|
||||
orientation = this.view.model.get('orientation'),
|
||||
var element = this.view.$el;
|
||||
var orientation = this.view.model.get('orientation');
|
||||
|
||||
elementOffset = element.offset(),
|
||||
elementPageX = elementOffset.left,
|
||||
elementPageY = elementOffset.top,
|
||||
elementWidth = element.outerWidth(true),
|
||||
elementHeight = element.outerHeight(true),
|
||||
var elementOffset = element.offset();
|
||||
var elementPageX = elementOffset.left;
|
||||
var elementPageY = elementOffset.top;
|
||||
var elementWidth = element.outerWidth(true);
|
||||
var elementHeight = element.outerHeight(true);
|
||||
|
||||
relativeX = eventX - elementPageX,
|
||||
relativeY = eventY - elementPageY,
|
||||
var relativeX = eventX - elementPageX;
|
||||
var relativeY = eventY - elementPageY;
|
||||
|
||||
relativeOffset, elementLength,
|
||||
var relativeOffset;
|
||||
var elementLength;
|
||||
|
||||
canAcceptNormalInsertion = this._canAcceptNormalInsertion(),
|
||||
canAcceptSpecialInsertion = this._canAcceptSpecialInsertion(),
|
||||
var canAcceptNormalInsertion = this._canAcceptNormalInsertion();
|
||||
var canAcceptSpecialInsertion = this._canAcceptSpecialInsertion();
|
||||
|
||||
insertionType, index, position, indexAndPosition;
|
||||
var insertionType;
|
||||
var index;
|
||||
var position;
|
||||
var indexAndPosition;
|
||||
|
||||
unsafe = !!unsafe;
|
||||
var unsafe = !!is_unsafe;
|
||||
|
||||
if (this.getCollection().length === 0) {
|
||||
return {
|
||||
@ -350,18 +367,20 @@ define([
|
||||
position: position // 'inside'|'before'|'after'
|
||||
};
|
||||
},
|
||||
_computeNormalIndex: function(eventX, eventY) {
|
||||
_computeNormalIndex: function (eventX, eventY) {
|
||||
// Normal insertion inserts dropModel before target element if
|
||||
// event happens on the first half of the element and after the
|
||||
// target element if event happens on the second half of the element.
|
||||
// Halves depend on orientation.
|
||||
|
||||
var index = this._computeCellIndex(eventX, eventY),
|
||||
// TODO: Handle case when there are no children, container is empty
|
||||
targetView = this.getChildren().findByModel(this.getCollection().at(index)),
|
||||
orientation = this.view.model.get('orientation'),
|
||||
element = targetView.$el,
|
||||
eventOffset, closeOffset, elementDimension;
|
||||
var index = this._computeCellIndex(eventX, eventY);
|
||||
// TODO: Handle case when there are no children, container is empty
|
||||
var targetView = this.getChildren().findByModel(this.getCollection().at(index));
|
||||
var orientation = this.view.model.get('orientation');
|
||||
var element = targetView.$el;
|
||||
var eventOffset;
|
||||
var closeOffset;
|
||||
var elementDimension;
|
||||
|
||||
if (orientation === 'vertical') {
|
||||
eventOffset = eventY;
|
||||
@ -376,63 +395,64 @@ define([
|
||||
if (eventOffset <= closeOffset + elementDimension / 2) {
|
||||
// First half of the element
|
||||
return {
|
||||
index: index,
|
||||
position: 'before'
|
||||
index: index,
|
||||
position: 'before'
|
||||
};
|
||||
} else {
|
||||
// Second half of the element
|
||||
return {
|
||||
index: index,
|
||||
position: 'after'
|
||||
index: index,
|
||||
position: 'after'
|
||||
};
|
||||
}
|
||||
},
|
||||
_computeSpecialIndex: function(eventX, eventY) {
|
||||
_computeSpecialIndex: function (eventX, eventY) {
|
||||
return this._computeCellIndex(eventX, eventY);
|
||||
},
|
||||
_computeCellIndex: function(eventX, eventY) {
|
||||
var orientation = this.view.model.get('orientation'),
|
||||
eventOffset = (orientation === 'vertical') ? eventY : eventX,
|
||||
resultView = this.getChildren().find(function(view) {
|
||||
var element = view.$el,
|
||||
closeOffset, farOffset;
|
||||
_computeCellIndex: function (eventX, eventY) {
|
||||
var orientation = this.view.model.get('orientation');
|
||||
var eventOffset = (orientation === 'vertical') ? eventY : eventX;
|
||||
var resultView = this.getChildren().find(function (view) {
|
||||
var element = view.$el;
|
||||
var closeOffset;
|
||||
var farOffset;
|
||||
|
||||
if (orientation === 'vertical') {
|
||||
closeOffset = element.offset().top;
|
||||
farOffset = element.outerHeight(true);
|
||||
} else {
|
||||
closeOffset = element.offset().left;
|
||||
farOffset = element.outerWidth(true);
|
||||
}
|
||||
farOffset += closeOffset;
|
||||
if (orientation === 'vertical') {
|
||||
closeOffset = element.offset().top;
|
||||
farOffset = element.outerHeight(true);
|
||||
} else {
|
||||
closeOffset = element.offset().left;
|
||||
farOffset = element.outerWidth(true);
|
||||
}
|
||||
farOffset += closeOffset;
|
||||
|
||||
return closeOffset <= eventOffset && eventOffset <= farOffset;
|
||||
});
|
||||
return closeOffset <= eventOffset && eventOffset <= farOffset;
|
||||
});
|
||||
|
||||
var index = (typeof resultView === 'object') ? resultView._index : 0;
|
||||
|
||||
return index;
|
||||
},
|
||||
_canAcceptNormalInsertion: function() {
|
||||
var orientation = this.view.model.get('orientation'),
|
||||
depth = this.view.renderOptions.depth,
|
||||
childCount = this.getChildren().length;
|
||||
_canAcceptNormalInsertion: function () {
|
||||
var orientation = this.view.model.get('orientation');
|
||||
var depth = this.view.renderOptions.depth;
|
||||
var childCount = this.getChildren().length;
|
||||
// Note that depth is zero indexed. Root container has depth=0
|
||||
return orientation === 'vertical' || (orientation === 'horizontal' && depth === 1 && childCount < this.options.columnLimit);
|
||||
},
|
||||
_canAcceptSpecialInsertion: function() {
|
||||
var orientation = this.view.model.get('orientation'),
|
||||
depth = this.view.renderOptions.depth,
|
||||
childCount = this.getChildren().length;
|
||||
_canAcceptSpecialInsertion: function () {
|
||||
var orientation = this.view.model.get('orientation');
|
||||
var depth = this.view.renderOptions.depth;
|
||||
var childCount = this.getChildren().length;
|
||||
return depth === 0 || (depth === 1 && orientation === 'horizontal' && childCount <= this.options.columnLimit);
|
||||
},
|
||||
getCollectionView: function() {
|
||||
getCollectionView: function () {
|
||||
return this.view.getChildView('blocks');
|
||||
},
|
||||
getChildren: function() {
|
||||
getChildren: function () {
|
||||
return this.getCollectionView().children;
|
||||
},
|
||||
getCollection: function() {
|
||||
getCollection: function () {
|
||||
return this.getCollectionView().collection;
|
||||
}
|
||||
});
|
||||
|
@ -5,14 +5,15 @@
|
||||
* Part of the drag&drop behavior.
|
||||
*/
|
||||
define([
|
||||
'backbone.marionette',
|
||||
'underscore',
|
||||
'jquery',
|
||||
'newsletter_editor/behaviors/BehaviorsLookup',
|
||||
'interact'
|
||||
], function(Marionette, _, jQuery, BehaviorsLookup, interact) {
|
||||
'backbone.marionette',
|
||||
'underscore',
|
||||
'jquery',
|
||||
'newsletter_editor/behaviors/BehaviorsLookup',
|
||||
'interact'
|
||||
], function (Marionette, _, jQuery, BehaviorsLookup, interact) {
|
||||
var BL = BehaviorsLookup;
|
||||
|
||||
BehaviorsLookup.DraggableBehavior = Marionette.Behavior.extend({
|
||||
BL.DraggableBehavior = Marionette.Behavior.extend({
|
||||
defaults: {
|
||||
cloneOriginal: false,
|
||||
hideOriginal: false,
|
||||
@ -23,22 +24,22 @@ define([
|
||||
*
|
||||
* @return Backbone.Model A model that will be passed to the receiver
|
||||
*/
|
||||
getDropModel: function() {
|
||||
getDropModel: function () {
|
||||
throw "Missing 'drop' function for DraggableBehavior";
|
||||
},
|
||||
|
||||
onDrop: function(model, view) {},
|
||||
testAttachToInstance: function(model, view) { return true; }
|
||||
onDrop: function () {},
|
||||
testAttachToInstance: function () { return true; }
|
||||
},
|
||||
onRender: function() {
|
||||
var that = this,
|
||||
interactable;
|
||||
onRender: function () {
|
||||
var that = this;
|
||||
var interactable;
|
||||
|
||||
// Give instances more control over whether Draggable should be applied
|
||||
if (!this.options.testAttachToInstance(this.view.model, this.view)) return;
|
||||
|
||||
interactable = interact(this.$el.get(0), {
|
||||
ignoreFrom: this.options.ignoreSelector
|
||||
ignoreFrom: this.options.ignoreSelector
|
||||
}).draggable({
|
||||
// allow dragging of multple elements at the same time
|
||||
max: Infinity,
|
||||
@ -46,17 +47,21 @@ define([
|
||||
// Scroll when dragging near edges of a window
|
||||
autoScroll: true,
|
||||
|
||||
onstart: function(event) {
|
||||
onstart: function (startEvent) {
|
||||
var event = startEvent;
|
||||
var centerXOffset;
|
||||
var centerYOffset;
|
||||
var tempClone;
|
||||
var clone;
|
||||
var $clone;
|
||||
|
||||
if (that.options.cloneOriginal === true) {
|
||||
// Use substitution instead of a clone
|
||||
var tempClone = (_.isFunction(that.options.onDragSubstituteBy)) ? that.options.onDragSubstituteBy(that) : undefined,
|
||||
// Or use a clone
|
||||
clone = tempClone ? tempClone : event.target.cloneNode(true),
|
||||
|
||||
$original = jQuery(event.target),
|
||||
$clone = jQuery(clone),
|
||||
centerXOffset, centerYOffset, parentOffset;
|
||||
tempClone = (_.isFunction(that.options.onDragSubstituteBy)) ? that.options.onDragSubstituteBy(that) : undefined;
|
||||
// Or use a clone
|
||||
clone = tempClone || event.target.cloneNode(true);
|
||||
jQuery(event.target);
|
||||
$clone = jQuery(clone);
|
||||
|
||||
$clone.addClass('mailpoet_droppable_active');
|
||||
$clone.css('position', 'absolute');
|
||||
@ -69,7 +74,7 @@ define([
|
||||
// Accurate dimensions can only be taken after insertion to document
|
||||
centerXOffset = $clone.width() / 2;
|
||||
centerYOffset = $clone.height() / 2;
|
||||
$clone.css('top', event.pageY - centerYOffset);
|
||||
$clone.css('top', event.pageY - centerYOffset);
|
||||
$clone.css('left', event.pageX - centerXOffset);
|
||||
|
||||
event.interaction.element = clone;
|
||||
@ -83,15 +88,14 @@ define([
|
||||
},
|
||||
// call this function on every dragmove event
|
||||
onmove: function (event) {
|
||||
var target = event.target,
|
||||
// keep the dragged position in the data-x/data-y attributes
|
||||
x = (parseFloat(target.getAttribute('data-x')) || 0) + event.dx,
|
||||
y = (parseFloat(target.getAttribute('data-y')) || 0) + event.dy;
|
||||
var target = event.target;
|
||||
// keep the dragged position in the data-x/data-y attributes
|
||||
var x = (parseFloat(target.getAttribute('data-x')) || 0) + event.dx;
|
||||
var y = (parseFloat(target.getAttribute('data-y')) || 0) + event.dy;
|
||||
|
||||
// translate the element
|
||||
target.style.webkitTransform =
|
||||
target.style.transform =
|
||||
'translate(' + x + 'px, ' + y + 'px)';
|
||||
target.style.transform = 'translate(' + x + 'px, ' + y + 'px)';
|
||||
target.style.webkitTransform = target.style.transform;
|
||||
|
||||
// update the posiion attributes
|
||||
target.setAttribute('data-x', x);
|
||||
@ -99,7 +103,8 @@ define([
|
||||
},
|
||||
onend: function (event) {
|
||||
var target = event.target;
|
||||
target.style.webkitTransform = target.style.transform = '';
|
||||
target.style.transform = '';
|
||||
target.style.webkitTransform = target.style.transform;
|
||||
target.removeAttribute('data-x');
|
||||
target.removeAttribute('data-y');
|
||||
jQuery(event.interaction.element).addClass('mailpoet_droppable_active');
|
||||
@ -129,7 +134,8 @@ define([
|
||||
} else {
|
||||
interactable.getDropModel = this.view.getDropFunc();
|
||||
}
|
||||
interactable.onDrop = function(options) {
|
||||
interactable.onDrop = function (opts) {
|
||||
var options = opts;
|
||||
if (_.isObject(options)) {
|
||||
// Inject Draggable behavior if possible
|
||||
options.dragBehavior = that;
|
||||
|
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Highlight Container Behavior
|
||||
*
|
||||
* Highlights a container block when hovering over its tools
|
||||
*/
|
||||
define([
|
||||
'backbone.marionette',
|
||||
'newsletter_editor/behaviors/BehaviorsLookup'
|
||||
], function (Marionette, BehaviorsLookup) {
|
||||
var BL = BehaviorsLookup;
|
||||
|
||||
BL.HighlightContainerBehavior = Marionette.Behavior.extend({
|
||||
events: {
|
||||
'mouseenter @ui.tools': 'enableHighlight',
|
||||
'mouseleave @ui.tools': 'disableHighlight'
|
||||
},
|
||||
enableHighlight: function () {
|
||||
this.$el.addClass('mailpoet_highlight');
|
||||
},
|
||||
disableHighlight: function () {
|
||||
if (!this.view._isBeingEdited) {
|
||||
this.$el.removeClass('mailpoet_highlight');
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
@ -4,19 +4,22 @@
|
||||
* Highlights a block that is being edited
|
||||
*/
|
||||
define([
|
||||
'backbone.marionette',
|
||||
'newsletter_editor/behaviors/BehaviorsLookup'
|
||||
], function(Marionette, BehaviorsLookup) {
|
||||
'backbone.marionette',
|
||||
'newsletter_editor/behaviors/BehaviorsLookup'
|
||||
], function (Marionette, BehaviorsLookup) {
|
||||
var BL = BehaviorsLookup;
|
||||
|
||||
BehaviorsLookup.HighlightEditingBehavior = Marionette.Behavior.extend({
|
||||
BL.HighlightEditingBehavior = Marionette.Behavior.extend({
|
||||
modelEvents: {
|
||||
'startEditing': 'enableHighlight',
|
||||
'stopEditing': 'disableHighlight'
|
||||
startEditing: 'enableHighlight',
|
||||
stopEditing: 'disableHighlight'
|
||||
},
|
||||
enableHighlight: function() {
|
||||
enableHighlight: function () {
|
||||
this.view._isBeingEdited = true;
|
||||
this.$el.addClass('mailpoet_highlight');
|
||||
},
|
||||
disableHighlight: function() {
|
||||
disableHighlight: function () {
|
||||
this.view._isBeingEdited = false;
|
||||
this.$el.removeClass('mailpoet_highlight');
|
||||
}
|
||||
});
|
||||
|
@ -4,62 +4,68 @@
|
||||
* Allows resizing elements within a block
|
||||
*/
|
||||
define([
|
||||
'backbone.marionette',
|
||||
'newsletter_editor/behaviors/BehaviorsLookup',
|
||||
'interact'
|
||||
], function(Marionette, BehaviorsLookup, interact) {
|
||||
'backbone.marionette',
|
||||
'newsletter_editor/behaviors/BehaviorsLookup',
|
||||
'interact'
|
||||
], function (Marionette, BehaviorsLookup, interact) {
|
||||
var BL = BehaviorsLookup;
|
||||
|
||||
BehaviorsLookup.ResizableBehavior = Marionette.Behavior.extend({
|
||||
BL.ResizableBehavior = Marionette.Behavior.extend({
|
||||
defaults: {
|
||||
elementSelector: null,
|
||||
resizeHandleSelector: true, // true will use edges of the element itself
|
||||
transformationFunction: function(y) { return y; },
|
||||
transformationFunction: function (y) { return y; }, // for blocks that use the default onResize function
|
||||
minLength: 0,
|
||||
modelField: 'styles.block.height'
|
||||
maxLength: Infinity,
|
||||
modelField: 'styles.block.height',
|
||||
onResize: function (event) {
|
||||
var currentLength = parseFloat(this.view.model.get(this.options.modelField));
|
||||
var newLength = currentLength + this.options.transformationFunction(event.dy);
|
||||
newLength = Math.min(this.options.maxLength, Math.max(this.options.minLength, newLength));
|
||||
this.view.model.set(this.options.modelField, newLength + 'px');
|
||||
}
|
||||
},
|
||||
events: {
|
||||
"mouseenter": 'showResizeHandle',
|
||||
"mouseleave": 'hideResizeHandle'
|
||||
mouseenter: 'showResizeHandle',
|
||||
mouseleave: 'hideResizeHandle'
|
||||
},
|
||||
onRender: function() {
|
||||
onRender: function () {
|
||||
this.attachResize();
|
||||
|
||||
if (this.isBeingResized !== true) {
|
||||
this.hideResizeHandle();
|
||||
}
|
||||
},
|
||||
attachResize: function() {
|
||||
var domElement = (this.options.elementSelector === null) ? this.view.$el.get(0) : this.view.$(this.options.elementSelector).get(0),
|
||||
that = this;
|
||||
attachResize: function () {
|
||||
var domElement = (this.options.elementSelector === null) ? this.view.$el.get(0) : this.view.$(this.options.elementSelector).get(0);
|
||||
var that = this;
|
||||
interact(domElement).resizable({
|
||||
//axis: 'y',
|
||||
// axis: 'y',
|
||||
edges: {
|
||||
top: false,
|
||||
left: false,
|
||||
right: false,
|
||||
bottom: (typeof this.options.resizeHandleSelector === 'string') ? this.view.$(this.options.resizeHandleSelector).get(0) : this.options.resizeHandleSelector
|
||||
}
|
||||
}).on('resizestart', function(event) {
|
||||
})
|
||||
.on('resizestart', function () {
|
||||
that.isBeingResized = true;
|
||||
that.$el.addClass('mailpoet_resize_active');
|
||||
}).on('resizemove', function(event) {
|
||||
var currentLength = parseFloat(that.view.model.get(that.options.modelField)),
|
||||
newLength = currentLength + that.options.transformationFunction(event.dy);
|
||||
|
||||
if (newLength < that.options.minLength) newLength = that.options.minLength;
|
||||
|
||||
that.view.model.set(that.options.modelField, newLength + 'px');
|
||||
}).on('resizeend', function(event) {
|
||||
}).on('resizemove', function (event) {
|
||||
var onResize = that.options.onResize.bind(that);
|
||||
return onResize(event);
|
||||
})
|
||||
.on('resizeend', function () {
|
||||
that.isBeingResized = null;
|
||||
that.$el.removeClass('mailpoet_resize_active');
|
||||
});
|
||||
},
|
||||
showResizeHandle: function() {
|
||||
showResizeHandle: function () {
|
||||
if (typeof this.options.resizeHandleSelector === 'string') {
|
||||
this.view.$(this.options.resizeHandleSelector).removeClass('mailpoet_hidden');
|
||||
}
|
||||
},
|
||||
hideResizeHandle: function() {
|
||||
hideResizeHandle: function () {
|
||||
if (typeof this.options.resizeHandleSelector === 'string') {
|
||||
this.view.$(this.options.resizeHandleSelector).addClass('mailpoet_hidden');
|
||||
}
|
||||
|
@ -4,24 +4,25 @@
|
||||
* Opens up settings of a BlockView if contents are clicked upon
|
||||
*/
|
||||
define([
|
||||
'backbone.marionette',
|
||||
'jquery',
|
||||
'newsletter_editor/behaviors/BehaviorsLookup'
|
||||
], function(Marionette, jQuery, BehaviorsLookup) {
|
||||
'backbone.marionette',
|
||||
'jquery',
|
||||
'newsletter_editor/behaviors/BehaviorsLookup'
|
||||
], function (Marionette, jQuery, BehaviorsLookup) {
|
||||
var BL = BehaviorsLookup;
|
||||
|
||||
BehaviorsLookup.ShowSettingsBehavior = Marionette.Behavior.extend({
|
||||
BL.ShowSettingsBehavior = Marionette.Behavior.extend({
|
||||
defaults: {
|
||||
ignoreFrom: '' // selector
|
||||
},
|
||||
events: {
|
||||
'click .mailpoet_content': 'showSettings'
|
||||
},
|
||||
showSettings: function(event) {
|
||||
if(!this.isIgnoredElement(event.target)) {
|
||||
showSettings: function (event) {
|
||||
if (!this.isIgnoredElement(event.target)) {
|
||||
this.view.triggerMethod('showSettings');
|
||||
}
|
||||
},
|
||||
isIgnoredElement: function(element) {
|
||||
isIgnoredElement: function (element) {
|
||||
return this.options.ignoreFrom
|
||||
&& this.options.ignoreFrom.length > 0
|
||||
&& jQuery(element).is(this.options.ignoreFrom);
|
||||
|
@ -4,28 +4,29 @@
|
||||
* Allows sorting elements within a collection
|
||||
*/
|
||||
define([
|
||||
'backbone.marionette',
|
||||
'underscore',
|
||||
'newsletter_editor/behaviors/BehaviorsLookup'
|
||||
], function(Marionette, _, BehaviorsLookup) {
|
||||
'backbone.marionette',
|
||||
'underscore',
|
||||
'newsletter_editor/behaviors/BehaviorsLookup'
|
||||
], function (Marionette, _, BehaviorsLookup) {
|
||||
var BL = BehaviorsLookup;
|
||||
|
||||
BehaviorsLookup.SortableBehavior = Marionette.Behavior.extend({
|
||||
onRender: function() {
|
||||
BL.SortableBehavior = Marionette.Behavior.extend({
|
||||
onRender: function () {
|
||||
var collection = this.view.collection;
|
||||
|
||||
if (_.isFunction(this.$el.sortable)) {
|
||||
this.$el.sortable({
|
||||
cursor: "move",
|
||||
start: function(event, ui) {
|
||||
cursor: 'move',
|
||||
start: function (event, ui) {
|
||||
ui.item.data('previousIndex', ui.item.index());
|
||||
},
|
||||
end: function(event, ui) {
|
||||
end: function (event, ui) {
|
||||
ui.item.removeData('previousIndex');
|
||||
},
|
||||
update: function(event, ui) {
|
||||
var previousIndex = ui.item.data('previousIndex'),
|
||||
newIndex = ui.item.index(),
|
||||
model = collection.at(previousIndex);
|
||||
update: function (event, ui) {
|
||||
var previousIndex = ui.item.data('previousIndex');
|
||||
var newIndex = ui.item.index();
|
||||
var model = collection.at(previousIndex);
|
||||
|
||||
// Replicate DOM changes. Move target model to a new position
|
||||
// within the collection
|
||||
|
@ -4,23 +4,24 @@
|
||||
* Adds TinyMCE text editing capabilities to a view
|
||||
*/
|
||||
define([
|
||||
'backbone.marionette',
|
||||
'underscore',
|
||||
'newsletter_editor/behaviors/BehaviorsLookup'
|
||||
], function(Marionette, _, BehaviorsLookup) {
|
||||
'backbone.marionette',
|
||||
'underscore',
|
||||
'newsletter_editor/behaviors/BehaviorsLookup'
|
||||
], function (Marionette, _, BehaviorsLookup) {
|
||||
var BL = BehaviorsLookup;
|
||||
|
||||
BehaviorsLookup.TextEditorBehavior = Marionette.Behavior.extend({
|
||||
BL.TextEditorBehavior = Marionette.Behavior.extend({
|
||||
defaults: {
|
||||
selector: '.mailpoet_content',
|
||||
toolbar1: "bold italic link unlink forecolor mailpoet_shortcodes",
|
||||
toolbar2: "",
|
||||
validElements: "p[class|style],span[class|style],a[href|class|title|target|style],strong[class|style],em[class|style],strike,br",
|
||||
invalidElements: "script",
|
||||
toolbar1: 'bold italic link unlink forecolor mailpoet_shortcodes',
|
||||
toolbar2: '',
|
||||
validElements: 'p[class|style],span[class|style],a[href|class|title|target|style],strong[class|style],em[class|style],strike,br',
|
||||
invalidElements: 'script',
|
||||
blockFormats: 'Paragraph=p',
|
||||
plugins: "link textcolor colorpicker mailpoet_shortcodes",
|
||||
configurationFilter: function(originalConfig) { return originalConfig; }
|
||||
plugins: 'link textcolor colorpicker mailpoet_shortcodes',
|
||||
configurationFilter: function (originalConfig) { return originalConfig; }
|
||||
},
|
||||
onDomRefresh: function() {
|
||||
onDomRefresh: function () {
|
||||
var that = this;
|
||||
if (this.view.disableTextEditor === true) {
|
||||
return;
|
||||
@ -33,13 +34,15 @@ define([
|
||||
toolbar1: this.options.toolbar1,
|
||||
toolbar2: this.options.toolbar2,
|
||||
|
||||
browser_spellcheck: true,
|
||||
|
||||
valid_elements: this.options.validElements,
|
||||
invalid_elements: this.options.invalidElements,
|
||||
block_formats: this.options.blockFormats,
|
||||
relative_urls: false,
|
||||
remove_script_host: false,
|
||||
convert_urls: true,
|
||||
urlconverter_callback: function(url, node, on_save, name) {
|
||||
urlconverter_callback: function (url) {
|
||||
if (url.match(/\[.+\]/g)) {
|
||||
// Do not convert URLs with shortcodes
|
||||
return url;
|
||||
@ -53,27 +56,27 @@ define([
|
||||
|
||||
plugins: this.options.plugins,
|
||||
|
||||
setup: function(editor) {
|
||||
editor.on('change', function(e) {
|
||||
setup: function (editor) {
|
||||
editor.on('change', function () {
|
||||
that.view.triggerMethod('text:editor:change', editor.getContent());
|
||||
});
|
||||
|
||||
editor.on('click', function(e) {
|
||||
editor.on('click', function (e) {
|
||||
editor.focus();
|
||||
if (that._isActivationClick) {
|
||||
editor.selection.setRng(
|
||||
tinymce.dom.RangeUtils.getCaretRangeFromPoint(e.clientX, e.clientY, editor.getDoc())
|
||||
window.tinymce.dom.RangeUtils.getCaretRangeFromPoint(e.clientX, e.clientY, editor.getDoc())
|
||||
);
|
||||
that._isActivationClick = false;
|
||||
}
|
||||
});
|
||||
|
||||
editor.on('focus', function(e) {
|
||||
editor.on('focus', function () {
|
||||
that.view.triggerMethod('text:editor:focus');
|
||||
that._isActivationClick = true;
|
||||
that._isActivationClick = true;
|
||||
});
|
||||
|
||||
editor.on('blur', function(e) {
|
||||
editor.on('blur', function () {
|
||||
that.view.triggerMethod('text:editor:blur');
|
||||
});
|
||||
}
|
||||
|
@ -7,34 +7,34 @@
|
||||
* block settings view.
|
||||
*/
|
||||
define([
|
||||
'newsletter_editor/App',
|
||||
'newsletter_editor/blocks/base',
|
||||
'newsletter_editor/blocks/button',
|
||||
'newsletter_editor/blocks/divider',
|
||||
'newsletter_editor/components/communication',
|
||||
'mailpoet',
|
||||
'backbone.supermodel',
|
||||
'underscore',
|
||||
'jquery'
|
||||
], function(
|
||||
App,
|
||||
BaseBlock,
|
||||
ButtonBlock,
|
||||
DividerBlock,
|
||||
CommunicationComponent,
|
||||
MailPoet,
|
||||
SuperModel,
|
||||
_,
|
||||
jQuery
|
||||
'newsletter_editor/App',
|
||||
'newsletter_editor/blocks/base',
|
||||
'newsletter_editor/blocks/button',
|
||||
'newsletter_editor/blocks/divider',
|
||||
'newsletter_editor/components/communication',
|
||||
'mailpoet',
|
||||
'backbone.supermodel',
|
||||
'underscore',
|
||||
'jquery'
|
||||
], function (
|
||||
App,
|
||||
BaseBlock,
|
||||
ButtonBlock,
|
||||
DividerBlock,
|
||||
CommunicationComponent,
|
||||
MailPoet,
|
||||
SuperModel,
|
||||
_,
|
||||
jQuery
|
||||
) {
|
||||
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var Module = {},
|
||||
base = BaseBlock;
|
||||
var Module = {};
|
||||
var base = BaseBlock;
|
||||
|
||||
Module.ALCSupervisor = SuperModel.extend({
|
||||
initialize: function() {
|
||||
initialize: function () {
|
||||
var DELAY_REFRESH_FOR_MS = 500;
|
||||
this.listenTo(
|
||||
App.getChannel(),
|
||||
@ -42,13 +42,14 @@ define([
|
||||
_.debounce(this.refresh, DELAY_REFRESH_FOR_MS)
|
||||
);
|
||||
},
|
||||
refresh: function() {
|
||||
var models = App.findModels(function(model) {
|
||||
refresh: function () {
|
||||
var blocks;
|
||||
var models = App.findModels(function (model) {
|
||||
return model.get('type') === 'automatedLatestContent';
|
||||
}) || [];
|
||||
|
||||
if (models.length === 0) return;
|
||||
var blocks = _.map(models, function(model) {
|
||||
blocks = _.map(models, function (model) {
|
||||
return model.toJSON();
|
||||
});
|
||||
|
||||
@ -56,12 +57,12 @@ define([
|
||||
blocks: blocks
|
||||
}).then(_.partial(this.refreshBlocks, models));
|
||||
},
|
||||
refreshBlocks: function(models, renderedBlocks) {
|
||||
refreshBlocks: function (models, renderedBlocks) {
|
||||
_.each(
|
||||
_.zip(models, renderedBlocks),
|
||||
function(args) {
|
||||
var model = args[0],
|
||||
contents = args[1];
|
||||
function (args) {
|
||||
var model = args[0];
|
||||
var contents = args[1];
|
||||
model.trigger('refreshPosts', contents);
|
||||
}
|
||||
);
|
||||
@ -70,7 +71,7 @@ define([
|
||||
|
||||
Module.AutomatedLatestContentBlockModel = base.BlockModel.extend({
|
||||
stale: ['_container'],
|
||||
defaults: function() {
|
||||
defaults: function () {
|
||||
return this._getDefaults({
|
||||
type: 'automatedLatestContent',
|
||||
amount: '5',
|
||||
@ -83,7 +84,7 @@ define([
|
||||
titleIsLink: false, // false|true
|
||||
imageFullWidth: false, // true|false
|
||||
featuredImagePosition: 'belowTitle', // 'aboveTitle'|'belowTitle'|'none'
|
||||
//imageAlignment: 'centerPadded', // 'centerFull'|'centerPadded'|'left'|'right'|'alternate'|'none'
|
||||
// imageAlignment: 'centerPadded', // 'centerFull'|'centerPadded'|'left'|'right'|'alternate'|'none'
|
||||
showAuthor: 'no', // 'no'|'aboveText'|'belowText'
|
||||
authorPrecededBy: 'Author:',
|
||||
showCategories: 'no', // 'no'|'aboveText'|'belowText'
|
||||
@ -100,14 +101,14 @@ define([
|
||||
_container: new (App.getBlockTypeModel('container'))()
|
||||
}, App.getConfig().get('blockDefaults.automatedLatestContent'));
|
||||
},
|
||||
relations: function() {
|
||||
relations: function () {
|
||||
return {
|
||||
readMoreButton: App.getBlockTypeModel('button'),
|
||||
divider: App.getBlockTypeModel('divider'),
|
||||
_container: App.getBlockTypeModel('container')
|
||||
};
|
||||
},
|
||||
initialize: function() {
|
||||
initialize: function () {
|
||||
base.BlockView.prototype.initialize.apply(this, arguments);
|
||||
this.on('change:amount change:contentType change:terms change:inclusionType change:displayType change:titleFormat change:featuredImagePosition change:titleAlignment change:titleIsLink change:imageFullWidth change:showAuthor change:authorPrecededBy change:showCategories change:categoriesPrecededBy change:readMoreType change:readMoreText change:sortBy change:showDivider', this._scheduleFetchPosts, this);
|
||||
this.listenTo(this.get('readMoreButton'), 'change', this._scheduleFetchPosts);
|
||||
@ -115,27 +116,27 @@ define([
|
||||
this.on('add remove update reset', this._scheduleFetchPosts);
|
||||
this.on('refreshPosts', this.updatePosts, this);
|
||||
},
|
||||
updatePosts: function(posts) {
|
||||
this.get('_container.blocks').reset(posts, {parse: true});
|
||||
updatePosts: function (posts) {
|
||||
this.get('_container.blocks').reset(posts, { parse: true });
|
||||
},
|
||||
/**
|
||||
* Batch more changes during a specific time, instead of fetching
|
||||
* ALC posts on each model change
|
||||
*/
|
||||
_scheduleFetchPosts: function() {
|
||||
_scheduleFetchPosts: function () {
|
||||
App.getChannel().trigger('automatedLatestContentRefresh');
|
||||
}
|
||||
});
|
||||
|
||||
Module.AutomatedLatestContentBlockView = base.BlockView.extend({
|
||||
className: "mailpoet_block mailpoet_automated_latest_content_block mailpoet_droppable_block",
|
||||
initialize: function() {
|
||||
className: 'mailpoet_block mailpoet_automated_latest_content_block mailpoet_droppable_block',
|
||||
initialize: function () {
|
||||
function replaceButtonStylesHandler(data) {
|
||||
this.model.set({"readMoreButton": data});
|
||||
this.model.set({ readMoreButton: data });
|
||||
}
|
||||
App.getChannel().on("replaceAllButtonStyles", replaceButtonStylesHandler.bind(this));
|
||||
App.getChannel().on('replaceAllButtonStyles', replaceButtonStylesHandler.bind(this));
|
||||
},
|
||||
getTemplate: function() { return templates.automatedLatestContentBlock; },
|
||||
getTemplate: function () { return window.templates.automatedLatestContentBlock; },
|
||||
regions: {
|
||||
toolsRegion: '.mailpoet_tools',
|
||||
postsRegion: '.mailpoet_automated_latest_content_block_posts'
|
||||
@ -143,19 +144,19 @@ define([
|
||||
modelEvents: _.extend(
|
||||
_.omit(base.BlockView.prototype.modelEvents, 'change'),
|
||||
{
|
||||
'postsChanged': 'render'
|
||||
postsChanged: 'render'
|
||||
}),
|
||||
events: _.extend(base.BlockView.prototype.events, {
|
||||
'click .mailpoet_automated_latest_content_block_overlay': 'showSettings'
|
||||
}),
|
||||
onDragSubstituteBy: function() { return Module.AutomatedLatestContentWidgetView; },
|
||||
onRender: function() {
|
||||
var ContainerView = App.getBlockTypeView('container'),
|
||||
renderOptions = {
|
||||
disableTextEditor: true,
|
||||
disableDragAndDrop: true,
|
||||
emptyContainerMessage: MailPoet.I18n.t('noPostsToDisplay')
|
||||
};
|
||||
onDragSubstituteBy: function () { return Module.AutomatedLatestContentWidgetView; },
|
||||
onRender: function () {
|
||||
var ContainerView = App.getBlockTypeView('container');
|
||||
var renderOptions = {
|
||||
disableTextEditor: true,
|
||||
disableDragAndDrop: true,
|
||||
emptyContainerMessage: MailPoet.I18n.t('noPostsToDisplay')
|
||||
};
|
||||
this.toolsView = new Module.AutomatedLatestContentBlockToolsView({ model: this.model });
|
||||
this.showChildView('toolsRegion', this.toolsView);
|
||||
this.showChildView('postsRegion', new ContainerView({ model: this.model.get('_container'), renderOptions: renderOptions }));
|
||||
@ -163,39 +164,39 @@ define([
|
||||
});
|
||||
|
||||
Module.AutomatedLatestContentBlockToolsView = base.BlockToolsView.extend({
|
||||
getSettingsView: function() { return Module.AutomatedLatestContentBlockSettingsView; }
|
||||
getSettingsView: function () { return Module.AutomatedLatestContentBlockSettingsView; }
|
||||
});
|
||||
|
||||
// Sidebar view container
|
||||
Module.AutomatedLatestContentBlockSettingsView = base.BlockSettingsView.extend({
|
||||
getTemplate: function() { return templates.automatedLatestContentBlockSettings; },
|
||||
events: function() {
|
||||
getTemplate: function () { return window.templates.automatedLatestContentBlockSettings; },
|
||||
events: function () {
|
||||
return {
|
||||
"click .mailpoet_automated_latest_content_hide_display_options": 'toggleDisplayOptions',
|
||||
"click .mailpoet_automated_latest_content_show_display_options": 'toggleDisplayOptions',
|
||||
"click .mailpoet_automated_latest_content_select_button": 'showButtonSettings',
|
||||
"click .mailpoet_automated_latest_content_select_divider": 'showDividerSettings',
|
||||
"change .mailpoet_automated_latest_content_read_more_type": 'changeReadMoreType',
|
||||
"change .mailpoet_automated_latest_content_display_type": 'changeDisplayType',
|
||||
"change .mailpoet_automated_latest_content_title_format": 'changeTitleFormat',
|
||||
"change .mailpoet_automated_latest_content_title_as_links": _.partial(this.changeBoolField, 'titleIsLink'),
|
||||
"change .mailpoet_automated_latest_content_show_divider": _.partial(this.changeBoolField, 'showDivider'),
|
||||
"input .mailpoet_automated_latest_content_show_amount": _.partial(this.changeField, "amount"),
|
||||
"change .mailpoet_automated_latest_content_content_type": _.partial(this.changeField, "contentType"),
|
||||
"change .mailpoet_automated_latest_content_include_or_exclude": _.partial(this.changeField, "inclusionType"),
|
||||
"change .mailpoet_automated_latest_content_title_alignment": _.partial(this.changeField, "titleAlignment"),
|
||||
"change .mailpoet_automated_latest_content_image_full_width": _.partial(this.changeBoolField, "imageFullWidth"),
|
||||
"change .mailpoet_automated_latest_content_featured_image_position": _.partial(this.changeField, "featuredImagePosition"),
|
||||
"change .mailpoet_automated_latest_content_show_author": _.partial(this.changeField, "showAuthor"),
|
||||
"input .mailpoet_automated_latest_content_author_preceded_by": _.partial(this.changeField, "authorPrecededBy"),
|
||||
"change .mailpoet_automated_latest_content_show_categories": _.partial(this.changeField, "showCategories"),
|
||||
"input .mailpoet_automated_latest_content_categories": _.partial(this.changeField, "categoriesPrecededBy"),
|
||||
"input .mailpoet_automated_latest_content_read_more_text": _.partial(this.changeField, "readMoreText"),
|
||||
"change .mailpoet_automated_latest_content_sort_by": _.partial(this.changeField, "sortBy"),
|
||||
"click .mailpoet_done_editing": "close"
|
||||
'click .mailpoet_automated_latest_content_hide_display_options': 'toggleDisplayOptions',
|
||||
'click .mailpoet_automated_latest_content_show_display_options': 'toggleDisplayOptions',
|
||||
'click .mailpoet_automated_latest_content_select_button': 'showButtonSettings',
|
||||
'click .mailpoet_automated_latest_content_select_divider': 'showDividerSettings',
|
||||
'change .mailpoet_automated_latest_content_read_more_type': 'changeReadMoreType',
|
||||
'change .mailpoet_automated_latest_content_display_type': 'changeDisplayType',
|
||||
'change .mailpoet_automated_latest_content_title_format': 'changeTitleFormat',
|
||||
'change .mailpoet_automated_latest_content_title_as_links': _.partial(this.changeBoolField, 'titleIsLink'),
|
||||
'change .mailpoet_automated_latest_content_show_divider': _.partial(this.changeBoolField, 'showDivider'),
|
||||
'input .mailpoet_automated_latest_content_show_amount': _.partial(this.changeField, 'amount'),
|
||||
'change .mailpoet_automated_latest_content_content_type': _.partial(this.changeField, 'contentType'),
|
||||
'change .mailpoet_automated_latest_content_include_or_exclude': _.partial(this.changeField, 'inclusionType'),
|
||||
'change .mailpoet_automated_latest_content_title_alignment': _.partial(this.changeField, 'titleAlignment'),
|
||||
'change .mailpoet_automated_latest_content_image_full_width': _.partial(this.changeBoolField, 'imageFullWidth'),
|
||||
'change .mailpoet_automated_latest_content_featured_image_position': _.partial(this.changeField, 'featuredImagePosition'),
|
||||
'change .mailpoet_automated_latest_content_show_author': _.partial(this.changeField, 'showAuthor'),
|
||||
'input .mailpoet_automated_latest_content_author_preceded_by': _.partial(this.changeField, 'authorPrecededBy'),
|
||||
'change .mailpoet_automated_latest_content_show_categories': _.partial(this.changeField, 'showCategories'),
|
||||
'input .mailpoet_automated_latest_content_categories': _.partial(this.changeField, 'categoriesPrecededBy'),
|
||||
'input .mailpoet_automated_latest_content_read_more_text': _.partial(this.changeField, 'readMoreText'),
|
||||
'change .mailpoet_automated_latest_content_sort_by': _.partial(this.changeField, 'sortBy'),
|
||||
'click .mailpoet_done_editing': 'close'
|
||||
};
|
||||
},
|
||||
onRender: function() {
|
||||
onRender: function () {
|
||||
var that = this;
|
||||
|
||||
// Dynamically update available post types
|
||||
@ -211,35 +212,36 @@ define([
|
||||
term: params.term
|
||||
};
|
||||
},
|
||||
transport: function(options, success, failure) {
|
||||
transport: function (options, success, failure) {
|
||||
var taxonomies;
|
||||
var termsPromise;
|
||||
var promise = CommunicationComponent.getTaxonomies(
|
||||
that.model.get('contentType')
|
||||
).then(function(tax) {
|
||||
).then(function (tax) {
|
||||
taxonomies = tax;
|
||||
// Fetch available terms based on the list of taxonomies already fetched
|
||||
var promise = CommunicationComponent.getTerms({
|
||||
termsPromise = CommunicationComponent.getTerms({
|
||||
search: options.data.term,
|
||||
taxonomies: _.keys(taxonomies)
|
||||
}).then(function(terms) {
|
||||
}).then(function (terms) {
|
||||
return {
|
||||
taxonomies: taxonomies,
|
||||
terms: terms
|
||||
};
|
||||
});
|
||||
return promise;
|
||||
return termsPromise;
|
||||
});
|
||||
|
||||
promise.then(success);
|
||||
promise.fail(failure);
|
||||
return promise;
|
||||
},
|
||||
processResults: function(data) {
|
||||
processResults: function (data) {
|
||||
// Transform taxonomies and terms into select2 compatible format
|
||||
return {
|
||||
results: _.map(
|
||||
data.terms,
|
||||
function(item) {
|
||||
function (item) {
|
||||
return _.defaults({
|
||||
text: data.taxonomies[item.taxonomy].labels.singular_name + ': ' + item.name,
|
||||
id: item.term_id
|
||||
@ -250,23 +252,23 @@ define([
|
||||
}
|
||||
}
|
||||
}).on({
|
||||
'select2:select': function(event) {
|
||||
'select2:select': function (event) {
|
||||
var terms = that.model.get('terms');
|
||||
terms.add(event.params.data);
|
||||
// Reset whole model in order for change events to propagate properly
|
||||
that.model.set('terms', terms.toJSON());
|
||||
},
|
||||
'select2:unselect': function(event) {
|
||||
'select2:unselect': function (event) {
|
||||
var terms = that.model.get('terms');
|
||||
terms.remove(event.params.data);
|
||||
// Reset whole model in order for change events to propagate properly
|
||||
that.model.set('terms', terms.toJSON());
|
||||
}
|
||||
}).trigger( 'change' );
|
||||
}).trigger('change');
|
||||
},
|
||||
toggleDisplayOptions: function(event) {
|
||||
var el = this.$('.mailpoet_automated_latest_content_display_options'),
|
||||
showControl = this.$('.mailpoet_automated_latest_content_show_display_options');
|
||||
toggleDisplayOptions: function () {
|
||||
var el = this.$('.mailpoet_automated_latest_content_display_options');
|
||||
var showControl = this.$('.mailpoet_automated_latest_content_show_display_options');
|
||||
if (el.hasClass('mailpoet_closed')) {
|
||||
el.removeClass('mailpoet_closed');
|
||||
showControl.addClass('mailpoet_hidden');
|
||||
@ -275,7 +277,7 @@ define([
|
||||
showControl.removeClass('mailpoet_hidden');
|
||||
}
|
||||
},
|
||||
showButtonSettings: function(event) {
|
||||
showButtonSettings: function () {
|
||||
var buttonModule = ButtonBlock;
|
||||
(new buttonModule.ButtonBlockSettingsView({
|
||||
model: this.model.get('readMoreButton'),
|
||||
@ -286,7 +288,7 @@ define([
|
||||
}
|
||||
})).render();
|
||||
},
|
||||
showDividerSettings: function(event) {
|
||||
showDividerSettings: function () {
|
||||
var dividerModule = DividerBlock;
|
||||
(new dividerModule.DividerBlockSettingsView({
|
||||
model: this.model.get('divider'),
|
||||
@ -296,7 +298,7 @@ define([
|
||||
}
|
||||
})).render();
|
||||
},
|
||||
changeReadMoreType: function(event) {
|
||||
changeReadMoreType: function (event) {
|
||||
var value = jQuery(event.target).val();
|
||||
if (value == 'link') {
|
||||
this.$('.mailpoet_automated_latest_content_read_more_text').removeClass('mailpoet_hidden');
|
||||
@ -307,7 +309,7 @@ define([
|
||||
}
|
||||
this.changeField('readMoreType', event);
|
||||
},
|
||||
changeDisplayType: function(event) {
|
||||
changeDisplayType: function (event) {
|
||||
var value = jQuery(event.target).val();
|
||||
|
||||
if (value == 'titleOnly') {
|
||||
@ -334,7 +336,7 @@ define([
|
||||
}
|
||||
this.changeField('displayType', event);
|
||||
},
|
||||
changeTitleFormat: function(event) {
|
||||
changeTitleFormat: function (event) {
|
||||
var value = jQuery(event.target).val();
|
||||
if (value == 'ul') {
|
||||
this.$('.mailpoet_automated_latest_content_non_title_list_options').addClass('mailpoet_hidden');
|
||||
@ -348,12 +350,12 @@ define([
|
||||
}
|
||||
this.changeField('titleFormat', event);
|
||||
},
|
||||
_updateContentTypes: function(postTypes) {
|
||||
var select = this.$('.mailpoet_automated_latest_content_content_type'),
|
||||
selectedValue = this.model.get('contentType');
|
||||
_updateContentTypes: function (postTypes) {
|
||||
var select = this.$('.mailpoet_automated_latest_content_content_type');
|
||||
var selectedValue = this.model.get('contentType');
|
||||
|
||||
select.find('option').remove();
|
||||
_.each(postTypes, function(type) {
|
||||
_.each(postTypes, function (type) {
|
||||
select.append(jQuery('<option>', {
|
||||
value: type.name,
|
||||
text: type.label
|
||||
@ -364,21 +366,21 @@ define([
|
||||
});
|
||||
|
||||
Module.AutomatedLatestContentWidgetView = base.WidgetView.extend({
|
||||
getTemplate: function() { return templates.automatedLatestContentInsertion; },
|
||||
getTemplate: function () { return window.templates.automatedLatestContentInsertion; },
|
||||
behaviors: {
|
||||
DraggableBehavior: {
|
||||
cloneOriginal: true,
|
||||
drop: function() {
|
||||
drop: function () {
|
||||
return new Module.AutomatedLatestContentBlockModel({}, { parse: true });
|
||||
},
|
||||
onDrop: function(options) {
|
||||
onDrop: function (options) {
|
||||
options.droppedView.triggerMethod('showSettings');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
App.on('before:start', function(App, options) {
|
||||
App.on('before:start', function (App) {
|
||||
App.registerBlockType('automatedLatestContent', {
|
||||
blockModel: Module.AutomatedLatestContentBlockModel,
|
||||
blockView: Module.AutomatedLatestContentBlockView
|
||||
@ -391,9 +393,10 @@ define([
|
||||
});
|
||||
});
|
||||
|
||||
App.on('start', function(App, options) {
|
||||
App._ALCSupervisor = new Module.ALCSupervisor();
|
||||
App._ALCSupervisor.refresh();
|
||||
App.on('start', function (App) {
|
||||
var Application = App;
|
||||
Application._ALCSupervisor = new Module.ALCSupervisor();
|
||||
Application._ALCSupervisor.refresh();
|
||||
});
|
||||
|
||||
return Module;
|
||||
|
@ -5,29 +5,28 @@
|
||||
* BlockToolsView, BlockSettingsView and BlockWidgetView are optional.
|
||||
*/
|
||||
define([
|
||||
'newsletter_editor/App',
|
||||
'backbone.marionette',
|
||||
'backbone.supermodel',
|
||||
'underscore',
|
||||
'jquery',
|
||||
'mailpoet',
|
||||
'modal'
|
||||
], function(App, Marionette, SuperModel, _, jQuery, MailPoet, Modal) {
|
||||
'newsletter_editor/App',
|
||||
'backbone.marionette',
|
||||
'backbone.supermodel',
|
||||
'underscore',
|
||||
'jquery',
|
||||
'mailpoet',
|
||||
'modal'
|
||||
], function (App, Marionette, SuperModel, _, jQuery, MailPoet) {
|
||||
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var Module = {},
|
||||
AugmentedView = Marionette.View.extend({});
|
||||
var Module = {};
|
||||
var AugmentedView = Marionette.View.extend({});
|
||||
|
||||
Module.BlockModel = SuperModel.extend({
|
||||
stale: [], // Attributes to be removed upon saving
|
||||
initialize: function() {
|
||||
var that = this;
|
||||
this.on('change', function() {
|
||||
initialize: function () {
|
||||
this.on('change', function () {
|
||||
App.getChannel().trigger('autoSave');
|
||||
});
|
||||
},
|
||||
_getDefaults: function(blockDefaults, configDefaults) {
|
||||
_getDefaults: function (blockDefaults, configDefaults) {
|
||||
var defaults = (_.isObject(configDefaults) && _.isFunction(configDefaults.toJSON)) ? configDefaults.toJSON() : configDefaults;
|
||||
|
||||
// Patch the resulting JSON object and fix it's constructors to be Object.
|
||||
@ -36,11 +35,11 @@ define([
|
||||
// TODO: Investigate for a better solution
|
||||
return JSON.parse(JSON.stringify(jQuery.extend(blockDefaults, defaults || {})));
|
||||
},
|
||||
toJSON: function() {
|
||||
toJSON: function () {
|
||||
// Remove stale attributes from resulting JSON object
|
||||
return _.omit(SuperModel.prototype.toJSON.call(this), this.stale);
|
||||
},
|
||||
getChildren: function() {
|
||||
getChildren: function () {
|
||||
return [];
|
||||
}
|
||||
});
|
||||
@ -50,25 +49,26 @@ define([
|
||||
toolsRegion: '> .mailpoet_tools'
|
||||
},
|
||||
modelEvents: {
|
||||
'change': 'render',
|
||||
'delete': 'deleteBlock',
|
||||
'duplicate': 'duplicateBlock'
|
||||
change: 'render',
|
||||
delete: 'deleteBlock',
|
||||
duplicate: 'duplicateBlock'
|
||||
},
|
||||
events: {
|
||||
"mouseenter": "showTools",
|
||||
"mouseleave": "hideTools"
|
||||
mouseenter: 'showTools',
|
||||
mouseleave: 'hideTools'
|
||||
},
|
||||
behaviors: {
|
||||
DraggableBehavior: {
|
||||
cloneOriginal: true,
|
||||
hideOriginal: true,
|
||||
onDrop: function(options) {
|
||||
onDrop: function (options) {
|
||||
// After a clone of model has been dropped, cleanup
|
||||
// and destroy self
|
||||
options.dragBehavior.view.model.destroy();
|
||||
},
|
||||
onDragSubstituteBy: function(behavior) {
|
||||
var WidgetView, node;
|
||||
onDragSubstituteBy: function (behavior) {
|
||||
var WidgetView;
|
||||
var node;
|
||||
// When block is being dragged, display the widget icon instead.
|
||||
// This will create an instance of block's widget view and
|
||||
// use it's rendered DOM element instead of the content block
|
||||
@ -83,76 +83,76 @@ define([
|
||||
},
|
||||
HighlightEditingBehavior: {}
|
||||
},
|
||||
templateContext: function() {
|
||||
templateContext: function () {
|
||||
return {
|
||||
model: this.model.toJSON(),
|
||||
viewCid: this.cid
|
||||
};
|
||||
},
|
||||
constructor: function() {
|
||||
constructor: function () {
|
||||
AugmentedView.apply(this, arguments);
|
||||
this.$el.addClass('mailpoet_editor_view_' + this.cid);
|
||||
},
|
||||
initialize: function() {
|
||||
initialize: function () {
|
||||
this.on('showSettings', this.showSettings, this);
|
||||
this.on('dom:refresh', this.showBlock, this);
|
||||
this._isFirstRender = true;
|
||||
},
|
||||
showTools: function(_event) {
|
||||
showTools: function () {
|
||||
if (!this.showingToolsDisabled) {
|
||||
this.$('> .mailpoet_tools').addClass('mailpoet_display_tools');
|
||||
this.toolsView.triggerMethod('showTools');
|
||||
}
|
||||
},
|
||||
hideTools: function(e) {
|
||||
hideTools: function () {
|
||||
this.$('> .mailpoet_tools').removeClass('mailpoet_display_tools');
|
||||
this.toolsView.triggerMethod('hideTools');
|
||||
},
|
||||
enableShowingTools: function() {
|
||||
enableShowingTools: function () {
|
||||
this.showingToolsDisabled = false;
|
||||
},
|
||||
disableShowingTools: function() {
|
||||
disableShowingTools: function () {
|
||||
this.showingToolsDisabled = true;
|
||||
this.hideTools();
|
||||
},
|
||||
showSettings: function(options) {
|
||||
showSettings: function (options) {
|
||||
this.toolsView.triggerMethod('showSettings', options);
|
||||
},
|
||||
/**
|
||||
* Defines drop behavior of BlockView instance
|
||||
*/
|
||||
getDropFunc: function() {
|
||||
return function() {
|
||||
getDropFunc: function () {
|
||||
return function () {
|
||||
return this.model.clone();
|
||||
}.bind(this);
|
||||
},
|
||||
disableDragging: function() {
|
||||
disableDragging: function () {
|
||||
this.$el.addClass('mailpoet_ignore_drag');
|
||||
},
|
||||
enableDragging: function() {
|
||||
enableDragging: function () {
|
||||
this.$el.removeClass('mailpoet_ignore_drag');
|
||||
},
|
||||
showBlock: function() {
|
||||
showBlock: function () {
|
||||
if (this._isFirstRender) {
|
||||
this.transitionIn();
|
||||
this._isFirstRender = false;
|
||||
}
|
||||
},
|
||||
deleteBlock: function() {
|
||||
this.transitionOut().then(function() {
|
||||
deleteBlock: function () {
|
||||
this.transitionOut().then(function () {
|
||||
this.model.destroy();
|
||||
}.bind(this));
|
||||
},
|
||||
duplicateBlock: function() {
|
||||
this.model.collection.add(this.model.toJSON(), {at: this.model.collection.findIndex(this.model)});
|
||||
duplicateBlock: function () {
|
||||
this.model.collection.add(this.model.toJSON(), { at: this.model.collection.findIndex(this.model) });
|
||||
},
|
||||
transitionIn: function() {
|
||||
transitionIn: function () {
|
||||
return this._transition('slideDown', 'fadeIn', 'easeOut');
|
||||
},
|
||||
transitionOut: function() {
|
||||
transitionOut: function () {
|
||||
return this._transition('slideUp', 'fadeOut', 'easeIn');
|
||||
},
|
||||
_transition: function(slideDirection, fadeDirection, easing) {
|
||||
_transition: function (slideDirection, fadeDirection, easing) {
|
||||
var promise = jQuery.Deferred();
|
||||
|
||||
this.$el.velocity(
|
||||
@ -160,7 +160,7 @@ define([
|
||||
{
|
||||
duration: 250,
|
||||
easing: easing,
|
||||
complete: function() {
|
||||
complete: function () {
|
||||
promise.resolve();
|
||||
}.bind(this)
|
||||
}
|
||||
@ -178,13 +178,13 @@ define([
|
||||
});
|
||||
|
||||
Module.BlockToolsView = AugmentedView.extend({
|
||||
getTemplate: function() { return templates.genericBlockTools; },
|
||||
getTemplate: function () { return window.templates.genericBlockTools; },
|
||||
events: {
|
||||
"click .mailpoet_edit_block": "changeSettings",
|
||||
"click .mailpoet_delete_block_activate": "showDeletionConfirmation",
|
||||
"click .mailpoet_delete_block_cancel": "hideDeletionConfirmation",
|
||||
"click .mailpoet_delete_block_confirm": "deleteBlock",
|
||||
"click .mailpoet_duplicate_block": "duplicateBlock"
|
||||
'click .mailpoet_edit_block': 'changeSettings',
|
||||
'click .mailpoet_delete_block_activate': 'showDeletionConfirmation',
|
||||
'click .mailpoet_delete_block_cancel': 'hideDeletionConfirmation',
|
||||
'click .mailpoet_delete_block_confirm': 'deleteBlock',
|
||||
'click .mailpoet_duplicate_block': 'duplicateBlock'
|
||||
},
|
||||
// Markers of whether these particular tools will be used for this instance
|
||||
tools: {
|
||||
@ -193,9 +193,9 @@ define([
|
||||
duplicate: true,
|
||||
move: true
|
||||
},
|
||||
getSettingsView: function() { return Module.BlockSettingsView; },
|
||||
initialize: function(options) {
|
||||
options = options || {};
|
||||
getSettingsView: function () { return Module.BlockSettingsView; },
|
||||
initialize: function (opts) {
|
||||
var options = opts || {};
|
||||
if (!_.isUndefined(options.tools)) {
|
||||
// Make a new block specific tool config object
|
||||
this.tools = jQuery.extend({}, this.tools, options.tools || {});
|
||||
@ -205,29 +205,29 @@ define([
|
||||
this.on('hideTools', this.hideDeletionConfirmation, this);
|
||||
this.on('showSettings', this.changeSettings);
|
||||
},
|
||||
templateContext: function() {
|
||||
templateContext: function () {
|
||||
return {
|
||||
model: this.model.toJSON(),
|
||||
viewCid: this.cid,
|
||||
tools: this.tools
|
||||
};
|
||||
},
|
||||
changeSettings: function(options) {
|
||||
changeSettings: function (options) {
|
||||
var ViewType = this.getSettingsView();
|
||||
(new ViewType(_.extend({ model: this.model }, options || {}))).render();
|
||||
},
|
||||
showDeletionConfirmation: function() {
|
||||
showDeletionConfirmation: function () {
|
||||
this.$('.mailpoet_delete_block').addClass('mailpoet_delete_block_activated');
|
||||
},
|
||||
hideDeletionConfirmation: function() {
|
||||
hideDeletionConfirmation: function () {
|
||||
this.$('.mailpoet_delete_block').removeClass('mailpoet_delete_block_activated');
|
||||
},
|
||||
deleteBlock: function(event) {
|
||||
deleteBlock: function (event) {
|
||||
event.preventDefault();
|
||||
this.model.trigger('delete');
|
||||
return false;
|
||||
},
|
||||
duplicateBlock: function(event) {
|
||||
duplicateBlock: function (event) {
|
||||
event.preventDefault();
|
||||
this.model.trigger('duplicate');
|
||||
return false;
|
||||
@ -239,14 +239,15 @@ define([
|
||||
behaviors: {
|
||||
ColorPickerBehavior: {}
|
||||
},
|
||||
initialize: function(params) {
|
||||
initialize: function (params) {
|
||||
var panelParams;
|
||||
this.model.trigger('startEditing');
|
||||
var panelParams = {
|
||||
panelParams = {
|
||||
element: this.$el,
|
||||
template: '',
|
||||
position: 'right',
|
||||
width: App.getConfig().get('sidepanelWidth'),
|
||||
onCancel: function() {
|
||||
onCancel: function () {
|
||||
this.destroy();
|
||||
}.bind(this)
|
||||
};
|
||||
@ -257,37 +258,37 @@ define([
|
||||
MailPoet.Modal.panel(panelParams);
|
||||
}
|
||||
},
|
||||
templateContext: function() {
|
||||
templateContext: function () {
|
||||
return {
|
||||
model: this.model.toJSON()
|
||||
};
|
||||
},
|
||||
close: function(event) {
|
||||
close: function () {
|
||||
this.destroy();
|
||||
},
|
||||
changeField: function(field, event) {
|
||||
changeField: function (field, event) {
|
||||
this.model.set(field, jQuery(event.target).val());
|
||||
},
|
||||
changePixelField: function(field, event) {
|
||||
changePixelField: function (field, event) {
|
||||
this.changeFieldWithSuffix(field, event, 'px');
|
||||
},
|
||||
changeFieldWithSuffix: function(field, event, suffix) {
|
||||
changeFieldWithSuffix: function (field, event, suffix) {
|
||||
this.model.set(field, jQuery(event.target).val() + suffix);
|
||||
},
|
||||
changeBoolField: function(field, event) {
|
||||
this.model.set(field, (jQuery(event.target).val() === 'true') ? true : false);
|
||||
changeBoolField: function (field, event) {
|
||||
this.model.set(field, (jQuery(event.target).val() === 'true'));
|
||||
},
|
||||
changeBoolCheckboxField: function(field, event) {
|
||||
changeBoolCheckboxField: function (field, event) {
|
||||
this.model.set(field, (!!jQuery(event.target).prop('checked')));
|
||||
},
|
||||
changeColorField: function(field, event) {
|
||||
changeColorField: function (field, event) {
|
||||
var value = jQuery(event.target).val();
|
||||
if (value === '') {
|
||||
value = 'transparent';
|
||||
}
|
||||
this.model.set(field, value);
|
||||
},
|
||||
onBeforeDestroy: function() {
|
||||
onBeforeDestroy: function () {
|
||||
MailPoet.Modal.close();
|
||||
this.model.trigger('stopEditing');
|
||||
}
|
||||
@ -297,8 +298,8 @@ define([
|
||||
className: 'mailpoet_widget mailpoet_droppable_block mailpoet_droppable_widget',
|
||||
behaviors: {
|
||||
DraggableBehavior: {
|
||||
drop: function() {
|
||||
throw "Unsupported operation";
|
||||
drop: function () {
|
||||
throw 'Unsupported operation';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,20 +2,20 @@
|
||||
* Button content block
|
||||
*/
|
||||
define([
|
||||
'newsletter_editor/App',
|
||||
'newsletter_editor/blocks/base',
|
||||
'mailpoet',
|
||||
'underscore',
|
||||
'jquery'
|
||||
], function(App, BaseBlock, MailPoet, _, jQuery) {
|
||||
'newsletter_editor/App',
|
||||
'newsletter_editor/blocks/base',
|
||||
'mailpoet',
|
||||
'underscore',
|
||||
'jquery'
|
||||
], function (App, BaseBlock, MailPoet, _, jQuery) {
|
||||
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var Module = {},
|
||||
base = BaseBlock;
|
||||
var Module = {};
|
||||
var base = BaseBlock;
|
||||
|
||||
Module.ButtonBlockModel = base.BlockModel.extend({
|
||||
defaults: function() {
|
||||
defaults: function () {
|
||||
return this._getDefaults({
|
||||
type: 'button',
|
||||
text: 'Button',
|
||||
@ -41,77 +41,77 @@ define([
|
||||
});
|
||||
|
||||
Module.ButtonBlockView = base.BlockView.extend({
|
||||
className: "mailpoet_block mailpoet_button_block mailpoet_droppable_block",
|
||||
getTemplate: function() { return templates.buttonBlock; },
|
||||
onDragSubstituteBy: function() { return Module.ButtonWidgetView; },
|
||||
className: 'mailpoet_block mailpoet_button_block mailpoet_droppable_block',
|
||||
getTemplate: function () { return window.templates.buttonBlock; },
|
||||
onDragSubstituteBy: function () { return Module.ButtonWidgetView; },
|
||||
behaviors: _.extend({}, base.BlockView.prototype.behaviors, {
|
||||
ShowSettingsBehavior: {}
|
||||
}),
|
||||
initialize: function() {
|
||||
initialize: function () {
|
||||
base.BlockView.prototype.initialize.apply(this, arguments);
|
||||
|
||||
// Listen for attempts to change all dividers in one go
|
||||
this._replaceButtonStylesHandler = function(data) { this.model.set(data); }.bind(this);
|
||||
this._replaceButtonStylesHandler = function (data) { this.model.set(data); }.bind(this);
|
||||
App.getChannel().on('replaceAllButtonStyles', this._replaceButtonStylesHandler);
|
||||
},
|
||||
onRender: function() {
|
||||
onRender: function () {
|
||||
this.toolsView = new Module.ButtonBlockToolsView({ model: this.model });
|
||||
this.showChildView('toolsRegion', this.toolsView);
|
||||
}
|
||||
});
|
||||
|
||||
Module.ButtonBlockToolsView = base.BlockToolsView.extend({
|
||||
getSettingsView: function() { return Module.ButtonBlockSettingsView; }
|
||||
getSettingsView: function () { return Module.ButtonBlockSettingsView; }
|
||||
});
|
||||
|
||||
Module.ButtonBlockSettingsView = base.BlockSettingsView.extend({
|
||||
getTemplate: function() { return templates.buttonBlockSettings; },
|
||||
events: function() {
|
||||
getTemplate: function () { return window.templates.buttonBlockSettings; },
|
||||
events: function () {
|
||||
return {
|
||||
"input .mailpoet_field_button_text": _.partial(this.changeField, "text"),
|
||||
"input .mailpoet_field_button_url": _.partial(this.changeField, "url"),
|
||||
"change .mailpoet_field_button_alignment": _.partial(this.changeField, "styles.block.textAlign"),
|
||||
"change .mailpoet_field_button_font_color": _.partial(this.changeColorField, "styles.block.fontColor"),
|
||||
"change .mailpoet_field_button_font_family": _.partial(this.changeField, "styles.block.fontFamily"),
|
||||
"change .mailpoet_field_button_font_size": _.partial(this.changeField, "styles.block.fontSize"),
|
||||
"change .mailpoet_field_button_background_color": _.partial(this.changeColorField, "styles.block.backgroundColor"),
|
||||
"change .mailpoet_field_button_border_color": _.partial(this.changeColorField, "styles.block.borderColor"),
|
||||
"change .mailpoet_field_button_font_weight": "changeFontWeight",
|
||||
'input .mailpoet_field_button_text': _.partial(this.changeField, 'text'),
|
||||
'input .mailpoet_field_button_url': _.partial(this.changeField, 'url'),
|
||||
'change .mailpoet_field_button_alignment': _.partial(this.changeField, 'styles.block.textAlign'),
|
||||
'change .mailpoet_field_button_font_color': _.partial(this.changeColorField, 'styles.block.fontColor'),
|
||||
'change .mailpoet_field_button_font_family': _.partial(this.changeField, 'styles.block.fontFamily'),
|
||||
'change .mailpoet_field_button_font_size': _.partial(this.changeField, 'styles.block.fontSize'),
|
||||
'change .mailpoet_field_button_background_color': _.partial(this.changeColorField, 'styles.block.backgroundColor'),
|
||||
'change .mailpoet_field_button_border_color': _.partial(this.changeColorField, 'styles.block.borderColor'),
|
||||
'change .mailpoet_field_button_font_weight': 'changeFontWeight',
|
||||
|
||||
"input .mailpoet_field_button_border_width": _.partial(this.updateValueAndCall, '.mailpoet_field_button_border_width_input', _.partial(this.changePixelField, "styles.block.borderWidth").bind(this)),
|
||||
"change .mailpoet_field_button_border_width": _.partial(this.updateValueAndCall, '.mailpoet_field_button_border_width_input', _.partial(this.changePixelField, "styles.block.borderWidth").bind(this)),
|
||||
"input .mailpoet_field_button_border_width_input": _.partial(this.updateValueAndCall, '.mailpoet_field_button_border_width', _.partial(this.changePixelField, "styles.block.borderWidth").bind(this)),
|
||||
'input .mailpoet_field_button_border_width': _.partial(this.updateValueAndCall, '.mailpoet_field_button_border_width_input', _.partial(this.changePixelField, 'styles.block.borderWidth').bind(this)),
|
||||
'change .mailpoet_field_button_border_width': _.partial(this.updateValueAndCall, '.mailpoet_field_button_border_width_input', _.partial(this.changePixelField, 'styles.block.borderWidth').bind(this)),
|
||||
'input .mailpoet_field_button_border_width_input': _.partial(this.updateValueAndCall, '.mailpoet_field_button_border_width', _.partial(this.changePixelField, 'styles.block.borderWidth').bind(this)),
|
||||
|
||||
"input .mailpoet_field_button_border_radius": _.partial(this.updateValueAndCall, '.mailpoet_field_button_border_radius_input', _.partial(this.changePixelField, "styles.block.borderRadius").bind(this)),
|
||||
"change .mailpoet_field_button_border_radius": _.partial(this.updateValueAndCall, '.mailpoet_field_button_border_radius_input', _.partial(this.changePixelField, "styles.block.borderRadius").bind(this)),
|
||||
"input .mailpoet_field_button_border_radius_input": _.partial(this.updateValueAndCall, '.mailpoet_field_button_border_radius', _.partial(this.changePixelField, "styles.block.borderRadius").bind(this)),
|
||||
'input .mailpoet_field_button_border_radius': _.partial(this.updateValueAndCall, '.mailpoet_field_button_border_radius_input', _.partial(this.changePixelField, 'styles.block.borderRadius').bind(this)),
|
||||
'change .mailpoet_field_button_border_radius': _.partial(this.updateValueAndCall, '.mailpoet_field_button_border_radius_input', _.partial(this.changePixelField, 'styles.block.borderRadius').bind(this)),
|
||||
'input .mailpoet_field_button_border_radius_input': _.partial(this.updateValueAndCall, '.mailpoet_field_button_border_radius', _.partial(this.changePixelField, 'styles.block.borderRadius').bind(this)),
|
||||
|
||||
"input .mailpoet_field_button_width": _.partial(this.updateValueAndCall, '.mailpoet_field_button_width_input', _.partial(this.changePixelField, "styles.block.width").bind(this)),
|
||||
"change .mailpoet_field_button_width": _.partial(this.updateValueAndCall, '.mailpoet_field_button_width_input', _.partial(this.changePixelField, "styles.block.width").bind(this)),
|
||||
"input .mailpoet_field_button_width_input": _.partial(this.updateValueAndCall, '.mailpoet_field_button_width', _.partial(this.changePixelField, "styles.block.width").bind(this)),
|
||||
'input .mailpoet_field_button_width': _.partial(this.updateValueAndCall, '.mailpoet_field_button_width_input', _.partial(this.changePixelField, 'styles.block.width').bind(this)),
|
||||
'change .mailpoet_field_button_width': _.partial(this.updateValueAndCall, '.mailpoet_field_button_width_input', _.partial(this.changePixelField, 'styles.block.width').bind(this)),
|
||||
'input .mailpoet_field_button_width_input': _.partial(this.updateValueAndCall, '.mailpoet_field_button_width', _.partial(this.changePixelField, 'styles.block.width').bind(this)),
|
||||
|
||||
"input .mailpoet_field_button_line_height": _.partial(this.updateValueAndCall, '.mailpoet_field_button_line_height_input', _.partial(this.changePixelField, "styles.block.lineHeight").bind(this)),
|
||||
"change .mailpoet_field_button_line_height": _.partial(this.updateValueAndCall, '.mailpoet_field_button_line_height_input', _.partial(this.changePixelField, "styles.block.lineHeight").bind(this)),
|
||||
"input .mailpoet_field_button_line_height_input": _.partial(this.updateValueAndCall, '.mailpoet_field_button_line_height', _.partial(this.changePixelField, "styles.block.lineHeight").bind(this)),
|
||||
'input .mailpoet_field_button_line_height': _.partial(this.updateValueAndCall, '.mailpoet_field_button_line_height_input', _.partial(this.changePixelField, 'styles.block.lineHeight').bind(this)),
|
||||
'change .mailpoet_field_button_line_height': _.partial(this.updateValueAndCall, '.mailpoet_field_button_line_height_input', _.partial(this.changePixelField, 'styles.block.lineHeight').bind(this)),
|
||||
'input .mailpoet_field_button_line_height_input': _.partial(this.updateValueAndCall, '.mailpoet_field_button_line_height', _.partial(this.changePixelField, 'styles.block.lineHeight').bind(this)),
|
||||
|
||||
"click .mailpoet_field_button_replace_all_styles": "applyToAll",
|
||||
"click .mailpoet_done_editing": "close"
|
||||
'click .mailpoet_field_button_replace_all_styles': 'applyToAll',
|
||||
'click .mailpoet_done_editing': 'close'
|
||||
};
|
||||
},
|
||||
templateContext: function() {
|
||||
templateContext: function () {
|
||||
return _.extend({}, base.BlockView.prototype.templateContext.apply(this, arguments), {
|
||||
availableStyles: App.getAvailableStyles().toJSON(),
|
||||
renderOptions: this.renderOptions
|
||||
});
|
||||
},
|
||||
applyToAll: function() {
|
||||
applyToAll: function () {
|
||||
App.getChannel().trigger('replaceAllButtonStyles', _.pick(this.model.toJSON(), 'styles', 'type'));
|
||||
},
|
||||
updateValueAndCall: function(fieldToUpdate, callable, event) {
|
||||
updateValueAndCall: function (fieldToUpdate, callable, event) {
|
||||
this.$(fieldToUpdate).val(jQuery(event.target).val());
|
||||
callable(event);
|
||||
},
|
||||
changeFontWeight: function(event) {
|
||||
changeFontWeight: function (event) {
|
||||
var checked = !!jQuery(event.target).prop('checked');
|
||||
this.model.set(
|
||||
'styles.block.fontWeight',
|
||||
@ -121,18 +121,18 @@ define([
|
||||
});
|
||||
|
||||
Module.ButtonWidgetView = base.WidgetView.extend({
|
||||
getTemplate: function() { return templates.buttonInsertion; },
|
||||
getTemplate: function () { return window.templates.buttonInsertion; },
|
||||
behaviors: {
|
||||
DraggableBehavior: {
|
||||
cloneOriginal: true,
|
||||
drop: function() {
|
||||
drop: function () {
|
||||
return new Module.ButtonBlockModel();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
App.on('before:start', function(App, options) {
|
||||
App.on('before:start', function (App) {
|
||||
App.registerBlockType('button', {
|
||||
blockModel: Module.ButtonBlockModel,
|
||||
blockView: Module.ButtonBlockView
|
||||
|
@ -4,31 +4,30 @@
|
||||
* as other containers.
|
||||
*/
|
||||
define([
|
||||
'backbone',
|
||||
'backbone.marionette',
|
||||
'underscore',
|
||||
'jquery',
|
||||
'newsletter_editor/App',
|
||||
'newsletter_editor/blocks/base'
|
||||
], function(Backbone, Marionette, _, jQuery, App, BaseBlock) {
|
||||
'backbone',
|
||||
'backbone.marionette',
|
||||
'underscore',
|
||||
'jquery',
|
||||
'newsletter_editor/App',
|
||||
'newsletter_editor/blocks/base'
|
||||
], function (Backbone, Marionette, _, jQuery, App, BaseBlock) {
|
||||
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var Module = {},
|
||||
base = BaseBlock,
|
||||
BlockCollection;
|
||||
var Module = {};
|
||||
var base = BaseBlock;
|
||||
var BlockCollection;
|
||||
|
||||
BlockCollection = Backbone.Collection.extend({
|
||||
model: base.BlockModel,
|
||||
initialize: function() {
|
||||
this.on('add change remove', function() { App.getChannel().trigger('autoSave'); });
|
||||
initialize: function () {
|
||||
this.on('add change remove', function () { App.getChannel().trigger('autoSave'); });
|
||||
},
|
||||
parse: function(response) {
|
||||
var self = this;
|
||||
return _.map(response, function(block) {
|
||||
parse: function (response) {
|
||||
return _.map(response, function (block) {
|
||||
var Type = App.getBlockTypeModel(block.type);
|
||||
// TODO: If type has no registered model, use a backup one
|
||||
return new Type(block, {parse: true});
|
||||
return new Type(block, { parse: true });
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -37,7 +36,7 @@ define([
|
||||
relations: {
|
||||
blocks: BlockCollection
|
||||
},
|
||||
defaults: function() {
|
||||
defaults: function () {
|
||||
return this._getDefaults({
|
||||
type: 'container',
|
||||
orientation: 'vertical',
|
||||
@ -49,14 +48,14 @@ define([
|
||||
blocks: new BlockCollection()
|
||||
}, App.getConfig().get('blockDefaults.container'));
|
||||
},
|
||||
validate: function() {
|
||||
validate: function () {
|
||||
// Recursively propagate validation checks to blocks in the tree
|
||||
var invalidBlock = this.get('blocks').find(function(block) { return !block.isValid(); });
|
||||
var invalidBlock = this.get('blocks').find(function (block) { return !block.isValid(); });
|
||||
if (invalidBlock) {
|
||||
return invalidBlock.validationError;
|
||||
}
|
||||
},
|
||||
parse: function(response) {
|
||||
parse: function (response) {
|
||||
// If container has any blocks - add them to a collection
|
||||
if (response.type === 'container' && _.has(response, 'blocks')) {
|
||||
response.blocks = new BlockCollection(response.blocks, {
|
||||
@ -65,8 +64,8 @@ define([
|
||||
}
|
||||
return response;
|
||||
},
|
||||
getChildren: function() {
|
||||
var models = this.get('blocks').map(function(model, index, list) {
|
||||
getChildren: function () {
|
||||
var models = this.get('blocks').map(function (model) {
|
||||
return [model, model.getChildren()];
|
||||
});
|
||||
|
||||
@ -76,10 +75,10 @@ define([
|
||||
|
||||
Module.ContainerBlocksView = Marionette.CollectionView.extend({
|
||||
className: 'mailpoet_container',
|
||||
childView: function(model) {
|
||||
childView: function (model) {
|
||||
return App.getBlockTypeView(model.get('type'));
|
||||
},
|
||||
childViewOptions: function() {
|
||||
childViewOptions: function () {
|
||||
var newRenderOptions = _.clone(this.renderOptions);
|
||||
if (newRenderOptions.depth !== undefined) {
|
||||
newRenderOptions.depth += 1;
|
||||
@ -88,9 +87,9 @@ define([
|
||||
renderOptions: newRenderOptions
|
||||
};
|
||||
},
|
||||
emptyView: function() { return Module.ContainerBlockEmptyView; },
|
||||
emptyViewOptions: function() { return { renderOptions: this.renderOptions }; },
|
||||
initialize: function(options) {
|
||||
emptyView: function () { return Module.ContainerBlockEmptyView; },
|
||||
emptyViewOptions: function () { return { renderOptions: this.renderOptions }; },
|
||||
initialize: function (options) {
|
||||
this.renderOptions = options.renderOptions;
|
||||
}
|
||||
});
|
||||
@ -103,9 +102,9 @@ define([
|
||||
}
|
||||
}),
|
||||
className: 'mailpoet_block mailpoet_container_block mailpoet_droppable_block mailpoet_droppable_layout_block',
|
||||
getTemplate: function() { return templates.containerBlock; },
|
||||
getTemplate: function () { return window.templates.containerBlock; },
|
||||
events: _.extend({}, base.BlockView.prototype.events, {
|
||||
"click .mailpoet_newsletter_layer_selector": "toggleEditingLayer"
|
||||
'click .mailpoet_newsletter_layer_selector': 'toggleEditingLayer'
|
||||
}),
|
||||
ui: {
|
||||
tools: '> .mailpoet_tools'
|
||||
@ -115,13 +114,14 @@ define([
|
||||
DraggableBehavior: {
|
||||
cloneOriginal: true,
|
||||
hideOriginal: true,
|
||||
onDrop: function(options) {
|
||||
onDrop: function (options) {
|
||||
// After a clone of model has been dropped, cleanup
|
||||
// and destroy self
|
||||
options.dragBehavior.view.model.destroy();
|
||||
},
|
||||
onDragSubstituteBy: function(behavior) {
|
||||
var WidgetView, node;
|
||||
onDragSubstituteBy: function (behavior) {
|
||||
var WidgetView;
|
||||
var node;
|
||||
// When block is being dragged, display the widget icon instead.
|
||||
// This will create an instance of block's widget view and
|
||||
// use it's rendered DOM element instead of the content block
|
||||
@ -133,14 +133,15 @@ define([
|
||||
return node;
|
||||
}
|
||||
},
|
||||
testAttachToInstance: function(model, view) {
|
||||
testAttachToInstance: function (model, view) {
|
||||
// Attach Draggable only to layout containers and disable it
|
||||
// for root and column containers.
|
||||
return view.renderOptions.depth === 1;
|
||||
}
|
||||
}
|
||||
},
|
||||
HighlightContainerBehavior: {}
|
||||
}),
|
||||
onDragSubstituteBy: function() {
|
||||
onDragSubstituteBy: function () {
|
||||
// For two and three column layouts display their respective widgets,
|
||||
// otherwise always default to one column layout widget
|
||||
if (this.renderOptions.depth === 1) {
|
||||
@ -150,12 +151,12 @@ define([
|
||||
return Module.OneColumnContainerWidgetView;
|
||||
|
||||
},
|
||||
initialize: function(options) {
|
||||
initialize: function (options) {
|
||||
base.BlockView.prototype.initialize.apply(this, arguments);
|
||||
|
||||
this.renderOptions = _.defaults(options.renderOptions || {}, {});
|
||||
},
|
||||
onRender: function() {
|
||||
onRender: function () {
|
||||
this.toolsView = new Module.ContainerBlockToolsView({
|
||||
model: this.model,
|
||||
tools: {
|
||||
@ -176,37 +177,37 @@ define([
|
||||
// Sets child container orientation HTML class here, as child CollectionView won't have access to model and will overwrite existing region element instead
|
||||
this.$('> .mailpoet_container').attr('class', 'mailpoet_container mailpoet_container_' + this.model.get('orientation'));
|
||||
},
|
||||
showTools: function() {
|
||||
showTools: function () {
|
||||
if (this.renderOptions.depth === 1 && !this.$el.hasClass('mailpoet_container_layer_active')) {
|
||||
this.$(this.ui.tools).addClass('mailpoet_display_tools');
|
||||
this.toolsView.triggerMethod('showTools');
|
||||
}
|
||||
},
|
||||
hideTools: function() {
|
||||
hideTools: function () {
|
||||
if (this.renderOptions.depth === 1 && !this.$el.hasClass('mailpoet_container_layer_active')) {
|
||||
this.$(this.ui.tools).removeClass('mailpoet_display_tools');
|
||||
this.toolsView.triggerMethod('hideTools');
|
||||
}
|
||||
},
|
||||
toggleEditingLayer: function(event) {
|
||||
var that = this,
|
||||
$toggleButton = this.$('> .mailpoet_tools .mailpoet_newsletter_layer_selector'),
|
||||
$overlay = jQuery('.mailpoet_layer_overlay'),
|
||||
$container = this.$('> .mailpoet_container'),
|
||||
enableContainerLayer = function() {
|
||||
that.$el.addClass('mailpoet_container_layer_active');
|
||||
$toggleButton.addClass('mailpoet_container_layer_active');
|
||||
$container.addClass('mailpoet_layer_highlight');
|
||||
$overlay.click(disableContainerLayer);
|
||||
$overlay.show();
|
||||
},
|
||||
disableContainerLayer = function() {
|
||||
that.$el.removeClass('mailpoet_container_layer_active');
|
||||
$toggleButton.removeClass('mailpoet_container_layer_active');
|
||||
$container.removeClass('mailpoet_layer_highlight');
|
||||
$overlay.hide();
|
||||
$overlay.off('click');
|
||||
};
|
||||
toggleEditingLayer: function (event) {
|
||||
var that = this;
|
||||
var $toggleButton = this.$('> .mailpoet_tools .mailpoet_newsletter_layer_selector');
|
||||
var $overlay = jQuery('.mailpoet_layer_overlay');
|
||||
var $container = this.$('> .mailpoet_container');
|
||||
var enableContainerLayer = function () {
|
||||
that.$el.addClass('mailpoet_container_layer_active');
|
||||
$toggleButton.addClass('mailpoet_container_layer_active');
|
||||
$container.addClass('mailpoet_layer_highlight');
|
||||
$overlay.click(disableContainerLayer);
|
||||
$overlay.show();
|
||||
};
|
||||
var disableContainerLayer = function () {
|
||||
that.$el.removeClass('mailpoet_container_layer_active');
|
||||
$toggleButton.removeClass('mailpoet_container_layer_active');
|
||||
$container.removeClass('mailpoet_layer_highlight');
|
||||
$overlay.hide();
|
||||
$overlay.off('click');
|
||||
};
|
||||
if ($toggleButton.hasClass('mailpoet_container_layer_active')) {
|
||||
disableContainerLayer();
|
||||
} else {
|
||||
@ -217,11 +218,11 @@ define([
|
||||
});
|
||||
|
||||
Module.ContainerBlockEmptyView = Marionette.View.extend({
|
||||
getTemplate: function() { return templates.containerEmpty; },
|
||||
initialize: function(options) {
|
||||
getTemplate: function () { return window.templates.containerEmpty; },
|
||||
initialize: function (options) {
|
||||
this.renderOptions = _.defaults(options.renderOptions || {}, {});
|
||||
},
|
||||
templateContext: function() {
|
||||
templateContext: function () {
|
||||
return {
|
||||
isRoot: this.renderOptions.depth === 0,
|
||||
emptyContainerMessage: this.renderOptions.emptyContainerMessage || ''
|
||||
@ -230,35 +231,35 @@ define([
|
||||
});
|
||||
|
||||
Module.ContainerBlockToolsView = base.BlockToolsView.extend({
|
||||
getSettingsView: function() { return Module.ContainerBlockSettingsView; }
|
||||
getSettingsView: function () { return Module.ContainerBlockSettingsView; }
|
||||
});
|
||||
|
||||
Module.ContainerBlockSettingsView = base.BlockSettingsView.extend({
|
||||
getTemplate: function() { return templates.containerBlockSettings; },
|
||||
events: function() {
|
||||
getTemplate: function () { return window.templates.containerBlockSettings; },
|
||||
events: function () {
|
||||
return {
|
||||
"change .mailpoet_field_container_background_color": _.partial(this.changeColorField, "styles.block.backgroundColor"),
|
||||
"click .mailpoet_done_editing": "close"
|
||||
'change .mailpoet_field_container_background_color': _.partial(this.changeColorField, 'styles.block.backgroundColor'),
|
||||
'click .mailpoet_done_editing': 'close'
|
||||
};
|
||||
},
|
||||
regions: {
|
||||
columnsSettingsRegion: '.mailpoet_container_columns_settings'
|
||||
},
|
||||
initialize: function() {
|
||||
initialize: function () {
|
||||
base.BlockSettingsView.prototype.initialize.apply(this, arguments);
|
||||
|
||||
this._columnsSettingsView = new (Module.ContainerBlockColumnsSettingsView)({
|
||||
collection: this.model.get('blocks')
|
||||
});
|
||||
},
|
||||
onRender: function() {
|
||||
onRender: function () {
|
||||
this.showChildView('columnsSettingsRegion', this._columnsSettingsView);
|
||||
}
|
||||
});
|
||||
|
||||
Module.ContainerBlockColumnsSettingsView = Marionette.CollectionView.extend({
|
||||
childView: function() { return Module.ContainerBlockColumnSettingsView; },
|
||||
childViewOptions: function(model, index) {
|
||||
childView: function () { return Module.ContainerBlockColumnSettingsView; },
|
||||
childViewOptions: function (model, index) {
|
||||
return {
|
||||
columnIndex: index
|
||||
};
|
||||
@ -266,11 +267,11 @@ define([
|
||||
});
|
||||
|
||||
Module.ContainerBlockColumnSettingsView = Marionette.View.extend({
|
||||
getTemplate: function() { return templates.containerBlockColumnSettings; },
|
||||
initialize: function(options) {
|
||||
getTemplate: function () { return window.templates.containerBlockColumnSettings; },
|
||||
initialize: function (options) {
|
||||
this.columnNumber = (options.columnIndex || 0) + 1;
|
||||
},
|
||||
templateContext: function() {
|
||||
templateContext: function () {
|
||||
return {
|
||||
model: this.model.toJSON(),
|
||||
columnNumber: this.columnNumber
|
||||
@ -280,11 +281,11 @@ define([
|
||||
|
||||
Module.OneColumnContainerWidgetView = base.WidgetView.extend({
|
||||
className: base.WidgetView.prototype.className + ' mailpoet_droppable_layout_block',
|
||||
getTemplate: function() { return templates.oneColumnLayoutInsertion; },
|
||||
getTemplate: function () { return window.templates.oneColumnLayoutInsertion; },
|
||||
behaviors: {
|
||||
DraggableBehavior: {
|
||||
cloneOriginal: true,
|
||||
drop: function() {
|
||||
drop: function () {
|
||||
return new Module.ContainerBlockModel({
|
||||
orientation: 'horizontal',
|
||||
blocks: [
|
||||
@ -298,11 +299,11 @@ define([
|
||||
|
||||
Module.TwoColumnContainerWidgetView = base.WidgetView.extend({
|
||||
className: base.WidgetView.prototype.className + ' mailpoet_droppable_layout_block',
|
||||
getTemplate: function() { return templates.twoColumnLayoutInsertion; },
|
||||
getTemplate: function () { return window.templates.twoColumnLayoutInsertion; },
|
||||
behaviors: {
|
||||
DraggableBehavior: {
|
||||
cloneOriginal: true,
|
||||
drop: function() {
|
||||
drop: function () {
|
||||
return new Module.ContainerBlockModel({
|
||||
orientation: 'horizontal',
|
||||
blocks: [
|
||||
@ -317,11 +318,11 @@ define([
|
||||
|
||||
Module.ThreeColumnContainerWidgetView = base.WidgetView.extend({
|
||||
className: base.WidgetView.prototype.className + ' mailpoet_droppable_layout_block',
|
||||
getTemplate: function() { return templates.threeColumnLayoutInsertion; },
|
||||
getTemplate: function () { return window.templates.threeColumnLayoutInsertion; },
|
||||
behaviors: {
|
||||
DraggableBehavior: {
|
||||
cloneOriginal: true,
|
||||
drop: function() {
|
||||
drop: function () {
|
||||
return new Module.ContainerBlockModel({
|
||||
orientation: 'horizontal',
|
||||
blocks: [
|
||||
@ -335,7 +336,7 @@ define([
|
||||
}
|
||||
});
|
||||
|
||||
App.on('before:start', function(App, options) {
|
||||
App.on('before:start', function (App) {
|
||||
App.registerBlockType('container', {
|
||||
blockModel: Module.ContainerBlockModel,
|
||||
blockView: Module.ContainerBlockView
|
||||
|
@ -2,20 +2,19 @@
|
||||
* Divider content block
|
||||
*/
|
||||
define([
|
||||
'newsletter_editor/App',
|
||||
'newsletter_editor/blocks/base',
|
||||
'underscore',
|
||||
'jquery',
|
||||
'mailpoet'
|
||||
], function(App, BaseBlock, _, jQuery, MailPoet) {
|
||||
'newsletter_editor/App',
|
||||
'newsletter_editor/blocks/base',
|
||||
'underscore',
|
||||
'jquery'
|
||||
], function (App, BaseBlock, _, jQuery) {
|
||||
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var Module = {},
|
||||
base = BaseBlock;
|
||||
var Module = {};
|
||||
var base = BaseBlock;
|
||||
|
||||
Module.DividerBlockModel = base.BlockModel.extend({
|
||||
defaults: function() {
|
||||
defaults: function () {
|
||||
return this._getDefaults({
|
||||
type: 'divider',
|
||||
styles: {
|
||||
@ -32,14 +31,14 @@ define([
|
||||
});
|
||||
|
||||
Module.DividerBlockView = base.BlockView.extend({
|
||||
className: "mailpoet_block mailpoet_divider_block mailpoet_droppable_block",
|
||||
getTemplate: function() { return templates.dividerBlock; },
|
||||
className: 'mailpoet_block mailpoet_divider_block mailpoet_droppable_block',
|
||||
getTemplate: function () { return window.templates.dividerBlock; },
|
||||
modelEvents: _.omit(base.BlockView.prototype.modelEvents, 'change'),
|
||||
behaviors: _.defaults({
|
||||
ResizableBehavior: {
|
||||
elementSelector: '.mailpoet_content',
|
||||
resizeHandleSelector: '.mailpoet_resize_handle',
|
||||
transformationFunction: function(y) { return y / 2; },
|
||||
transformationFunction: function (y) { return y / 2; },
|
||||
minLength: 0, // TODO: Move this number to editor configuration
|
||||
modelField: 'styles.block.padding'
|
||||
},
|
||||
@ -47,99 +46,99 @@ define([
|
||||
ignoreFrom: '.mailpoet_resize_handle'
|
||||
}
|
||||
}, base.BlockView.prototype.behaviors),
|
||||
onDragSubstituteBy: function() { return Module.DividerWidgetView; },
|
||||
initialize: function() {
|
||||
base.BlockView.prototype.initialize.apply(this, arguments);
|
||||
onDragSubstituteBy: function () { return Module.DividerWidgetView; },
|
||||
initialize: function () {
|
||||
var that = this;
|
||||
base.BlockView.prototype.initialize.apply(this, arguments);
|
||||
|
||||
// Listen for attempts to change all dividers in one go
|
||||
this._replaceDividerHandler = function(data) { that.model.set(data); that.model.trigger('applyToAll'); };
|
||||
this._replaceDividerHandler = function (data) { that.model.set(data); that.model.trigger('applyToAll'); };
|
||||
App.getChannel().on('replaceAllDividers', this._replaceDividerHandler);
|
||||
|
||||
this.listenTo(this.model, 'change:src change:styles.block.backgroundColor change:styles.block.borderStyle change:styles.block.borderWidth change:styles.block.borderColor applyToAll', this.render);
|
||||
this.listenTo(this.model, 'change:styles.block.padding', this.changePadding);
|
||||
},
|
||||
templateContext: function() {
|
||||
templateContext: function () {
|
||||
return _.extend({
|
||||
totalHeight: parseInt(this.model.get('styles.block.padding'), 10)*2 + parseInt(this.model.get('styles.block.borderWidth')) + 'px'
|
||||
totalHeight: parseInt(this.model.get('styles.block.padding'), 10) * 2 + parseInt(this.model.get('styles.block.borderWidth')) + 'px'
|
||||
}, base.BlockView.prototype.templateContext.apply(this));
|
||||
},
|
||||
onRender: function() {
|
||||
onRender: function () {
|
||||
this.toolsView = new Module.DividerBlockToolsView({ model: this.model });
|
||||
this.showChildView('toolsRegion', this.toolsView);
|
||||
},
|
||||
onBeforeDestroy: function() {
|
||||
onBeforeDestroy: function () {
|
||||
App.getChannel().off('replaceAllDividers', this._replaceDividerHandler);
|
||||
this.stopListening(this.model);
|
||||
},
|
||||
changePadding: function() {
|
||||
changePadding: function () {
|
||||
this.$('.mailpoet_content').css('padding-top', this.model.get('styles.block.padding'));
|
||||
this.$('.mailpoet_content').css('padding-bottom', this.model.get('styles.block.padding'));
|
||||
this.$('.mailpoet_resize_handle_text').text(parseInt(this.model.get('styles.block.padding'), 10)*2 + parseInt(this.model.get('styles.block.borderWidth')) + 'px');
|
||||
this.$('.mailpoet_resize_handle_text').text(parseInt(this.model.get('styles.block.padding'), 10) * 2 + parseInt(this.model.get('styles.block.borderWidth')) + 'px');
|
||||
}
|
||||
});
|
||||
|
||||
Module.DividerBlockToolsView = base.BlockToolsView.extend({
|
||||
getSettingsView: function() { return Module.DividerBlockSettingsView; }
|
||||
getSettingsView: function () { return Module.DividerBlockSettingsView; }
|
||||
});
|
||||
|
||||
Module.DividerBlockSettingsView = base.BlockSettingsView.extend({
|
||||
getTemplate: function() { return templates.dividerBlockSettings; },
|
||||
events: function() {
|
||||
getTemplate: function () { return window.templates.dividerBlockSettings; },
|
||||
events: function () {
|
||||
return {
|
||||
"click .mailpoet_field_divider_style": 'changeStyle',
|
||||
'click .mailpoet_field_divider_style': 'changeStyle',
|
||||
|
||||
"input .mailpoet_field_divider_border_width": _.partial(this.updateValueAndCall, '.mailpoet_field_divider_border_width_input', _.partial(this.changePixelField, "styles.block.borderWidth").bind(this)),
|
||||
"change .mailpoet_field_divider_border_width": _.partial(this.updateValueAndCall, '.mailpoet_field_divider_border_width_input', _.partial(this.changePixelField, "styles.block.borderWidth").bind(this)),
|
||||
"input .mailpoet_field_divider_border_width_input": _.partial(this.updateValueAndCall, '.mailpoet_field_divider_border_width', _.partial(this.changePixelField, "styles.block.borderWidth").bind(this)),
|
||||
'input .mailpoet_field_divider_border_width': _.partial(this.updateValueAndCall, '.mailpoet_field_divider_border_width_input', _.partial(this.changePixelField, 'styles.block.borderWidth').bind(this)),
|
||||
'change .mailpoet_field_divider_border_width': _.partial(this.updateValueAndCall, '.mailpoet_field_divider_border_width_input', _.partial(this.changePixelField, 'styles.block.borderWidth').bind(this)),
|
||||
'input .mailpoet_field_divider_border_width_input': _.partial(this.updateValueAndCall, '.mailpoet_field_divider_border_width', _.partial(this.changePixelField, 'styles.block.borderWidth').bind(this)),
|
||||
|
||||
"change .mailpoet_field_divider_border_color": _.partial(this.changeColorField, "styles.block.borderColor"),
|
||||
"change .mailpoet_field_divider_background_color": _.partial(this.changeColorField, "styles.block.backgroundColor"),
|
||||
"click .mailpoet_button_divider_apply_to_all": "applyToAll",
|
||||
"click .mailpoet_done_editing": "close"
|
||||
'change .mailpoet_field_divider_border_color': _.partial(this.changeColorField, 'styles.block.borderColor'),
|
||||
'change .mailpoet_field_divider_background_color': _.partial(this.changeColorField, 'styles.block.backgroundColor'),
|
||||
'click .mailpoet_button_divider_apply_to_all': 'applyToAll',
|
||||
'click .mailpoet_done_editing': 'close'
|
||||
};
|
||||
},
|
||||
modelEvents: function() {
|
||||
modelEvents: function () {
|
||||
return {
|
||||
'change:styles.block.borderColor': 'repaintDividerStyleOptions'
|
||||
};
|
||||
},
|
||||
templateContext: function() {
|
||||
templateContext: function () {
|
||||
return _.extend({}, base.BlockView.prototype.templateContext.apply(this, arguments), {
|
||||
availableStyles: App.getAvailableStyles().toJSON(),
|
||||
renderOptions: this.renderOptions
|
||||
});
|
||||
},
|
||||
changeStyle: function(event) {
|
||||
changeStyle: function (event) {
|
||||
var style = jQuery(event.currentTarget).data('style');
|
||||
this.model.set('styles.block.borderStyle', style);
|
||||
this.$('.mailpoet_field_divider_style').removeClass('mailpoet_active_divider_style');
|
||||
this.$('.mailpoet_field_divider_style[data-style="' + style + '"]').addClass('mailpoet_active_divider_style');
|
||||
},
|
||||
repaintDividerStyleOptions: function() {
|
||||
repaintDividerStyleOptions: function () {
|
||||
this.$('.mailpoet_field_divider_style > div').css('border-top-color', this.model.get('styles.block.borderColor'));
|
||||
},
|
||||
applyToAll: function(event) {
|
||||
applyToAll: function () {
|
||||
App.getChannel().trigger('replaceAllDividers', this.model.toJSON());
|
||||
},
|
||||
updateValueAndCall: function(fieldToUpdate, callable, event) {
|
||||
updateValueAndCall: function (fieldToUpdate, callable, event) {
|
||||
this.$(fieldToUpdate).val(jQuery(event.target).val());
|
||||
callable(event);
|
||||
}
|
||||
});
|
||||
|
||||
Module.DividerWidgetView = base.WidgetView.extend({
|
||||
getTemplate: function() { return templates.dividerInsertion; },
|
||||
getTemplate: function () { return window.templates.dividerInsertion; },
|
||||
behaviors: {
|
||||
DraggableBehavior: {
|
||||
cloneOriginal: true,
|
||||
drop: function() {
|
||||
drop: function () {
|
||||
return new Module.DividerBlockModel();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
App.on('before:start', function(App, options) {
|
||||
App.on('before:start', function (App) {
|
||||
App.registerBlockType('divider', {
|
||||
blockModel: Module.DividerBlockModel,
|
||||
blockView: Module.DividerBlockView
|
||||
|
@ -2,18 +2,19 @@
|
||||
* Footer content block
|
||||
*/
|
||||
define([
|
||||
'newsletter_editor/App',
|
||||
'newsletter_editor/blocks/base',
|
||||
'underscore'
|
||||
], function(App, BaseBlock, _) {
|
||||
'newsletter_editor/App',
|
||||
'newsletter_editor/blocks/base',
|
||||
'underscore',
|
||||
'mailpoet'
|
||||
], function (App, BaseBlock, _, MailPoet) {
|
||||
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var Module = {},
|
||||
base = BaseBlock;
|
||||
var Module = {};
|
||||
var base = BaseBlock;
|
||||
|
||||
Module.FooterBlockModel = base.BlockModel.extend({
|
||||
defaults: function() {
|
||||
defaults: function () {
|
||||
return this._getDefaults({
|
||||
type: 'footer',
|
||||
text: '<a href="[link:subscription_unsubscribe_url]">Unsubscribe</a> | <a href="[link:subscription_manage_url]">Manage subscription</a><br /><b>Add your postal address here!</b>',
|
||||
@ -37,14 +38,14 @@ define([
|
||||
});
|
||||
|
||||
Module.FooterBlockView = base.BlockView.extend({
|
||||
className: "mailpoet_block mailpoet_footer_block mailpoet_droppable_block",
|
||||
getTemplate: function() { return templates.footerBlock; },
|
||||
className: 'mailpoet_block mailpoet_footer_block mailpoet_droppable_block',
|
||||
getTemplate: function () { return window.templates.footerBlock; },
|
||||
modelEvents: _.extend({
|
||||
'change:styles.block.backgroundColor change:styles.text.fontColor change:styles.text.fontFamily change:styles.text.fontSize change:styles.text.textAlign change:styles.link.fontColor change:styles.link.textDecoration': 'render'
|
||||
}, _.omit(base.BlockView.prototype.modelEvents, 'change')),
|
||||
behaviors: _.extend({}, base.BlockView.prototype.behaviors, {
|
||||
TextEditorBehavior: {
|
||||
configurationFilter: function(originalSettings) {
|
||||
configurationFilter: function (originalSettings) {
|
||||
return _.extend({}, originalSettings, {
|
||||
mailpoet_shortcodes: App.getConfig().get('shortcodes').toJSON(),
|
||||
mailpoet_shortcodes_window_title: MailPoet.I18n.t('shortcodesWindowTitle')
|
||||
@ -52,45 +53,45 @@ define([
|
||||
}
|
||||
}
|
||||
}),
|
||||
onDragSubstituteBy: function() { return Module.FooterWidgetView; },
|
||||
onRender: function() {
|
||||
onDragSubstituteBy: function () { return Module.FooterWidgetView; },
|
||||
onRender: function () {
|
||||
this.toolsView = new Module.FooterBlockToolsView({ model: this.model });
|
||||
this.showChildView('toolsRegion', this.toolsView);
|
||||
},
|
||||
onTextEditorChange: function(newContent) {
|
||||
onTextEditorChange: function (newContent) {
|
||||
this.model.set('text', newContent);
|
||||
},
|
||||
onTextEditorFocus: function() {
|
||||
onTextEditorFocus: function () {
|
||||
this.disableDragging();
|
||||
this.disableShowingTools();
|
||||
},
|
||||
onTextEditorBlur: function() {
|
||||
onTextEditorBlur: function () {
|
||||
this.enableDragging();
|
||||
this.enableShowingTools();
|
||||
}
|
||||
});
|
||||
|
||||
Module.FooterBlockToolsView = base.BlockToolsView.extend({
|
||||
getSettingsView: function() { return Module.FooterBlockSettingsView; }
|
||||
getSettingsView: function () { return Module.FooterBlockSettingsView; }
|
||||
});
|
||||
|
||||
Module.FooterBlockSettingsView = base.BlockSettingsView.extend({
|
||||
getTemplate: function() { return templates.footerBlockSettings; },
|
||||
events: function() {
|
||||
getTemplate: function () { return window.templates.footerBlockSettings; },
|
||||
events: function () {
|
||||
return {
|
||||
"change .mailpoet_field_footer_text_color": _.partial(this.changeColorField, "styles.text.fontColor"),
|
||||
"change .mailpoet_field_footer_text_font_family": _.partial(this.changeField, "styles.text.fontFamily"),
|
||||
"change .mailpoet_field_footer_text_size": _.partial(this.changeField, "styles.text.fontSize"),
|
||||
"change #mailpoet_field_footer_link_color": _.partial(this.changeColorField, "styles.link.fontColor"),
|
||||
"change #mailpoet_field_footer_link_underline": function(event) {
|
||||
this.model.set('styles.link.textDecoration', (event.target.checked) ? event.target.value : 'none');
|
||||
},
|
||||
"change .mailpoet_field_footer_background_color": _.partial(this.changeColorField, "styles.block.backgroundColor"),
|
||||
"change .mailpoet_field_footer_alignment": _.partial(this.changeField, "styles.text.textAlign"),
|
||||
"click .mailpoet_done_editing": "close"
|
||||
'change .mailpoet_field_footer_text_color': _.partial(this.changeColorField, 'styles.text.fontColor'),
|
||||
'change .mailpoet_field_footer_text_font_family': _.partial(this.changeField, 'styles.text.fontFamily'),
|
||||
'change .mailpoet_field_footer_text_size': _.partial(this.changeField, 'styles.text.fontSize'),
|
||||
'change #mailpoet_field_footer_link_color': _.partial(this.changeColorField, 'styles.link.fontColor'),
|
||||
'change #mailpoet_field_footer_link_underline': function (event) {
|
||||
this.model.set('styles.link.textDecoration', (event.target.checked) ? event.target.value : 'none');
|
||||
},
|
||||
'change .mailpoet_field_footer_background_color': _.partial(this.changeColorField, 'styles.block.backgroundColor'),
|
||||
'change .mailpoet_field_footer_alignment': _.partial(this.changeField, 'styles.text.textAlign'),
|
||||
'click .mailpoet_done_editing': 'close'
|
||||
};
|
||||
},
|
||||
templateContext: function() {
|
||||
templateContext: function () {
|
||||
return _.extend({}, base.BlockView.prototype.templateContext.apply(this, arguments), {
|
||||
availableStyles: App.getAvailableStyles().toJSON()
|
||||
});
|
||||
@ -98,18 +99,18 @@ define([
|
||||
});
|
||||
|
||||
Module.FooterWidgetView = base.WidgetView.extend({
|
||||
getTemplate: function() { return templates.footerInsertion; },
|
||||
getTemplate: function () { return window.templates.footerInsertion; },
|
||||
behaviors: {
|
||||
DraggableBehavior: {
|
||||
cloneOriginal: true,
|
||||
drop: function() {
|
||||
drop: function () {
|
||||
return new Module.FooterBlockModel();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
App.on('before:start', function(App, options) {
|
||||
App.on('before:start', function (App) {
|
||||
App.registerBlockType('footer', {
|
||||
blockModel: Module.FooterBlockModel,
|
||||
blockView: Module.FooterBlockView
|
||||
|
@ -2,18 +2,19 @@
|
||||
* Header content block
|
||||
*/
|
||||
define([
|
||||
'newsletter_editor/App',
|
||||
'newsletter_editor/blocks/base',
|
||||
'underscore'
|
||||
], function(App, BaseBlock, _) {
|
||||
'newsletter_editor/App',
|
||||
'newsletter_editor/blocks/base',
|
||||
'underscore',
|
||||
'mailpoet'
|
||||
], function (App, BaseBlock, _, MailPoet) {
|
||||
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var Module = {},
|
||||
base = BaseBlock;
|
||||
var Module = {};
|
||||
var base = BaseBlock;
|
||||
|
||||
Module.HeaderBlockModel = base.BlockModel.extend({
|
||||
defaults: function() {
|
||||
defaults: function () {
|
||||
return this._getDefaults({
|
||||
type: 'header',
|
||||
text: 'Display problems? <a href="[link:newsletter_view_in_browser_url]">View it in your browser</a>',
|
||||
@ -37,14 +38,14 @@ define([
|
||||
});
|
||||
|
||||
Module.HeaderBlockView = base.BlockView.extend({
|
||||
className: "mailpoet_block mailpoet_header_block mailpoet_droppable_block",
|
||||
getTemplate: function() { return templates.headerBlock; },
|
||||
className: 'mailpoet_block mailpoet_header_block mailpoet_droppable_block',
|
||||
getTemplate: function () { return window.templates.headerBlock; },
|
||||
modelEvents: _.extend({
|
||||
'change:styles.block.backgroundColor change:styles.text.fontColor change:styles.text.fontFamily change:styles.text.fontSize change:styles.text.textAlign change:styles.link.fontColor change:styles.link.textDecoration': 'render'
|
||||
}, _.omit(base.BlockView.prototype.modelEvents, 'change')),
|
||||
behaviors: _.extend({}, base.BlockView.prototype.behaviors, {
|
||||
TextEditorBehavior: {
|
||||
configurationFilter: function(originalSettings) {
|
||||
configurationFilter: function (originalSettings) {
|
||||
return _.extend({}, originalSettings, {
|
||||
mailpoet_shortcodes: App.getConfig().get('shortcodes').toJSON(),
|
||||
mailpoet_shortcodes_window_title: MailPoet.I18n.t('shortcodesWindowTitle')
|
||||
@ -52,45 +53,45 @@ define([
|
||||
}
|
||||
}
|
||||
}),
|
||||
onDragSubstituteBy: function() { return Module.HeaderWidgetView; },
|
||||
onRender: function() {
|
||||
onDragSubstituteBy: function () { return Module.HeaderWidgetView; },
|
||||
onRender: function () {
|
||||
this.toolsView = new Module.HeaderBlockToolsView({ model: this.model });
|
||||
this.showChildView('toolsRegion', this.toolsView);
|
||||
},
|
||||
onTextEditorChange: function(newContent) {
|
||||
onTextEditorChange: function (newContent) {
|
||||
this.model.set('text', newContent);
|
||||
},
|
||||
onTextEditorFocus: function() {
|
||||
onTextEditorFocus: function () {
|
||||
this.disableDragging();
|
||||
this.disableShowingTools();
|
||||
},
|
||||
onTextEditorBlur: function() {
|
||||
onTextEditorBlur: function () {
|
||||
this.enableDragging();
|
||||
this.enableShowingTools();
|
||||
}
|
||||
});
|
||||
|
||||
Module.HeaderBlockToolsView = base.BlockToolsView.extend({
|
||||
getSettingsView: function() { return Module.HeaderBlockSettingsView; }
|
||||
getSettingsView: function () { return Module.HeaderBlockSettingsView; }
|
||||
});
|
||||
|
||||
Module.HeaderBlockSettingsView = base.BlockSettingsView.extend({
|
||||
getTemplate: function() { return templates.headerBlockSettings; },
|
||||
events: function() {
|
||||
getTemplate: function () { return window.templates.headerBlockSettings; },
|
||||
events: function () {
|
||||
return {
|
||||
"change .mailpoet_field_header_text_color": _.partial(this.changeColorField, "styles.text.fontColor"),
|
||||
"change .mailpoet_field_header_text_font_family": _.partial(this.changeField, "styles.text.fontFamily"),
|
||||
"change .mailpoet_field_header_text_size": _.partial(this.changeField, "styles.text.fontSize"),
|
||||
"change #mailpoet_field_header_link_color": _.partial(this.changeColorField, "styles.link.fontColor"),
|
||||
"change #mailpoet_field_header_link_underline": function(event) {
|
||||
'change .mailpoet_field_header_text_color': _.partial(this.changeColorField, 'styles.text.fontColor'),
|
||||
'change .mailpoet_field_header_text_font_family': _.partial(this.changeField, 'styles.text.fontFamily'),
|
||||
'change .mailpoet_field_header_text_size': _.partial(this.changeField, 'styles.text.fontSize'),
|
||||
'change #mailpoet_field_header_link_color': _.partial(this.changeColorField, 'styles.link.fontColor'),
|
||||
'change #mailpoet_field_header_link_underline': function (event) {
|
||||
this.model.set('styles.link.textDecoration', (event.target.checked) ? event.target.value : 'none');
|
||||
},
|
||||
"change .mailpoet_field_header_background_color": _.partial(this.changeColorField, "styles.block.backgroundColor"),
|
||||
"change .mailpoet_field_header_alignment": _.partial(this.changeField, "styles.text.textAlign"),
|
||||
"click .mailpoet_done_editing": "close"
|
||||
'change .mailpoet_field_header_background_color': _.partial(this.changeColorField, 'styles.block.backgroundColor'),
|
||||
'change .mailpoet_field_header_alignment': _.partial(this.changeField, 'styles.text.textAlign'),
|
||||
'click .mailpoet_done_editing': 'close'
|
||||
};
|
||||
},
|
||||
templateContext: function() {
|
||||
templateContext: function () {
|
||||
return _.extend({}, base.BlockView.prototype.templateContext.apply(this, arguments), {
|
||||
availableStyles: App.getAvailableStyles().toJSON()
|
||||
});
|
||||
@ -98,18 +99,18 @@ define([
|
||||
});
|
||||
|
||||
Module.HeaderWidgetView = base.WidgetView.extend({
|
||||
getTemplate: function() { return templates.headerInsertion; },
|
||||
getTemplate: function () { return window.templates.headerInsertion; },
|
||||
behaviors: {
|
||||
DraggableBehavior: {
|
||||
cloneOriginal: true,
|
||||
drop: function() {
|
||||
drop: function () {
|
||||
return new Module.HeaderBlockModel();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
App.on('before:start', function(App, options) {
|
||||
App.on('before:start', function (App) {
|
||||
App.registerBlockType('header', {
|
||||
blockModel: Module.HeaderBlockModel,
|
||||
blockView: Module.HeaderBlockView
|
||||
|
@ -2,19 +2,21 @@
|
||||
* Image content block
|
||||
*/
|
||||
define([
|
||||
'newsletter_editor/App',
|
||||
'newsletter_editor/blocks/base',
|
||||
'underscore'
|
||||
], function(App, BaseBlock, _) {
|
||||
'newsletter_editor/App',
|
||||
'newsletter_editor/blocks/base',
|
||||
'underscore',
|
||||
'mailpoet',
|
||||
'jquery'
|
||||
], function (App, BaseBlock, _, MailPoet, jQuery) {
|
||||
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var Module = {},
|
||||
base = BaseBlock,
|
||||
ImageWidgetView;
|
||||
var Module = {};
|
||||
var base = BaseBlock;
|
||||
var ImageWidgetView;
|
||||
|
||||
Module.ImageBlockModel = base.BlockModel.extend({
|
||||
defaults: function() {
|
||||
defaults: function () {
|
||||
return this._getDefaults({
|
||||
type: 'image',
|
||||
link: '',
|
||||
@ -33,64 +35,111 @@ define([
|
||||
});
|
||||
|
||||
Module.ImageBlockView = base.BlockView.extend({
|
||||
className: "mailpoet_block mailpoet_image_block mailpoet_droppable_block",
|
||||
getTemplate: function() { return templates.imageBlock; },
|
||||
onDragSubstituteBy: function() { return Module.ImageWidgetView; },
|
||||
templateContext: function() {
|
||||
className: 'mailpoet_block mailpoet_image_block mailpoet_droppable_block',
|
||||
getTemplate: function () { return window.templates.imageBlock; },
|
||||
onDragSubstituteBy: function () { return Module.ImageWidgetView; },
|
||||
templateContext: function () {
|
||||
return _.extend({
|
||||
imageMissingSrc: App.getConfig().get('urls.imageMissing')
|
||||
}, base.BlockView.prototype.templateContext.apply(this));
|
||||
},
|
||||
behaviors: _.extend({}, base.BlockView.prototype.behaviors, {
|
||||
ShowSettingsBehavior: {}
|
||||
ResizableBehavior: {
|
||||
elementSelector: '.mailpoet_image',
|
||||
resizeHandleSelector: '.mailpoet_image_resize_handle',
|
||||
onResize: function (event) {
|
||||
var corner = this.$('.mailpoet_image').offset();
|
||||
var width = event.pageX - corner.left;
|
||||
this.view.model.set('width', width + 'px');
|
||||
}
|
||||
},
|
||||
ShowSettingsBehavior: {
|
||||
ignoreFrom: '.mailpoet_image_resize_handle'
|
||||
}
|
||||
}),
|
||||
onRender: function() {
|
||||
onRender: function () {
|
||||
this.toolsView = new Module.ImageBlockToolsView({ model: this.model });
|
||||
this.showChildView('toolsRegion', this.toolsView);
|
||||
|
||||
if (this.model.get('fullWidth')) {
|
||||
this.$el.addClass('mailpoet_full_image');
|
||||
} else {
|
||||
this.$el.removeClass('mailpoet_full_image');
|
||||
}
|
||||
this.$('.mailpoet_content').css('width', this.model.get('width'));
|
||||
}
|
||||
});
|
||||
|
||||
Module.ImageBlockToolsView = base.BlockToolsView.extend({
|
||||
getSettingsView: function() { return Module.ImageBlockSettingsView; }
|
||||
getSettingsView: function () { return Module.ImageBlockSettingsView; }
|
||||
});
|
||||
|
||||
Module.ImageBlockSettingsView = base.BlockSettingsView.extend({
|
||||
getTemplate: function() { return templates.imageBlockSettings; },
|
||||
events: function() {
|
||||
onRender: function () {
|
||||
MailPoet.helpTooltip.show(document.getElementById('tooltip-designer-full-width'), {
|
||||
tooltipId: 'tooltip-editor-full-width',
|
||||
tooltip: MailPoet.I18n.t('helpTooltipDesignerFullWidth')
|
||||
});
|
||||
MailPoet.helpTooltip.show(document.getElementById('tooltip-designer-ideal-width'), {
|
||||
tooltipId: 'tooltip-editor-ideal-width',
|
||||
tooltip: MailPoet.I18n.t('helpTooltipDesignerIdealWidth')
|
||||
});
|
||||
},
|
||||
getTemplate: function () { return window.templates.imageBlockSettings; },
|
||||
events: function () {
|
||||
return {
|
||||
"input .mailpoet_field_image_link": _.partial(this.changeField, "link"),
|
||||
"input .mailpoet_field_image_address": 'changeAddress',
|
||||
"input .mailpoet_field_image_alt_text": _.partial(this.changeField, "alt"),
|
||||
"change .mailpoet_field_image_full_width": _.partial(this.changeBoolCheckboxField, "fullWidth"),
|
||||
"change .mailpoet_field_image_alignment": _.partial(this.changeField, "styles.block.textAlign"),
|
||||
"click .mailpoet_field_image_select_another_image": "showMediaManager",
|
||||
"click .mailpoet_done_editing": "close"
|
||||
'input .mailpoet_field_image_link': _.partial(this.changeField, 'link'),
|
||||
'input .mailpoet_field_image_address': 'changeAddress',
|
||||
'input .mailpoet_field_image_alt_text': _.partial(this.changeField, 'alt'),
|
||||
'change .mailpoet_field_image_full_width': _.partial(this.changeBoolCheckboxField, 'fullWidth'),
|
||||
'change .mailpoet_field_image_alignment': _.partial(this.changeField, 'styles.block.textAlign'),
|
||||
'click .mailpoet_field_image_select_another_image': 'showMediaManager',
|
||||
'click .mailpoet_done_editing': 'close',
|
||||
'input .mailpoet_field_image_width': _.partial(this.updateValueAndCall, '.mailpoet_field_image_width_input', _.partial(this.changePixelField, 'width').bind(this)),
|
||||
'change .mailpoet_field_image_width': _.partial(this.updateValueAndCall, '.mailpoet_field_image_width_input', _.partial(this.changePixelField, 'width').bind(this)),
|
||||
'input .mailpoet_field_image_width_input': _.partial(this.updateValueAndCall, '.mailpoet_field_image_width', _.partial(this.changePixelField, 'width').bind(this))
|
||||
};
|
||||
},
|
||||
initialize: function(options) {
|
||||
modelEvents: function () {
|
||||
return {
|
||||
'change:maxWidth': 'updateMaxWidth',
|
||||
'change:width': 'updateWidth'
|
||||
};
|
||||
},
|
||||
updateValueAndCall: function (fieldToUpdate, callable, event) {
|
||||
this.$(fieldToUpdate).val(jQuery(event.target).val());
|
||||
callable(event);
|
||||
},
|
||||
updateMaxWidth: function () {
|
||||
var maxWidth = parseInt(this.model.get('maxWidth'));
|
||||
this.$('.mailpoet_field_image_width').attr('max', maxWidth);
|
||||
this.$('.mailpoet_field_image_width_input').attr('max', maxWidth);
|
||||
},
|
||||
updateWidth: function () {
|
||||
var width = parseInt(this.model.get('width'));
|
||||
this.$('.mailpoet_field_image_width').val(width);
|
||||
this.$('.mailpoet_field_image_width_input').val(width);
|
||||
},
|
||||
initialize: function (options) {
|
||||
base.BlockSettingsView.prototype.initialize.apply(this, arguments);
|
||||
|
||||
if (options.showImageManager) {
|
||||
this.showMediaManager();
|
||||
}
|
||||
},
|
||||
showMediaManager: function() {
|
||||
showMediaManager: function () {
|
||||
var that = this;
|
||||
var MediaManager;
|
||||
var theFrame;
|
||||
if (this._mediaManager) {
|
||||
this._mediaManager.resetSelections();
|
||||
this._mediaManager.open();
|
||||
return;
|
||||
}
|
||||
|
||||
var MediaManager = wp.media.view.MediaFrame.Select.extend({
|
||||
MediaManager = window.wp.media.view.MediaFrame.Select.extend({
|
||||
|
||||
initialize: function() {
|
||||
wp.media.view.MediaFrame.prototype.initialize.apply(this, arguments);
|
||||
initialize: function () {
|
||||
window.wp.media.view.MediaFrame.prototype.initialize.apply(this, arguments);
|
||||
|
||||
_.defaults(this.options, {
|
||||
multiple: true,
|
||||
@ -107,22 +156,22 @@ define([
|
||||
this.$el.addClass('hide-title');
|
||||
},
|
||||
|
||||
resetSelections: function() {
|
||||
resetSelections: function () {
|
||||
this.state().get('selection').reset();
|
||||
},
|
||||
|
||||
createQuery: function(options) {
|
||||
var query = wp.media.query(options);
|
||||
createQuery: function (options) {
|
||||
var query = window.wp.media.query(options);
|
||||
return query;
|
||||
},
|
||||
|
||||
createStates: function() {
|
||||
createStates: function () {
|
||||
var options = this.options;
|
||||
|
||||
// Add the default states.
|
||||
this.states.add([
|
||||
// Main states.
|
||||
new wp.media.controller.Library({
|
||||
new window.wp.media.controller.Library({
|
||||
id: 'insert',
|
||||
title: 'Add images',
|
||||
priority: 20,
|
||||
@ -144,12 +193,13 @@ define([
|
||||
})
|
||||
]);
|
||||
|
||||
if(wp.media.view.settings.post.featuredImageId) {
|
||||
this.states.add(new wp.media.controller.FeaturedImage());
|
||||
if (window.wp.media.view.settings.post.featuredImageId) {
|
||||
this.states.add(new window.wp.media.controller.FeaturedImage());
|
||||
}
|
||||
},
|
||||
|
||||
bindHandlers: function() {
|
||||
bindHandlers: function () {
|
||||
var handlers;
|
||||
// from Select
|
||||
this.on('router:create:browse', this.createRouter, this);
|
||||
this.on('router:render:browse', this.browseRouter, this);
|
||||
@ -164,31 +214,31 @@ define([
|
||||
|
||||
this.on('updateExcluded', this.browseContent, this);
|
||||
|
||||
var handlers = {
|
||||
content: {
|
||||
'embed': 'embedContent',
|
||||
'edit-selection': 'editSelectionContent'
|
||||
},
|
||||
toolbar: {
|
||||
'main-insert': 'mainInsertToolbar'
|
||||
}
|
||||
};
|
||||
handlers = {
|
||||
content: {
|
||||
embed: 'embedContent',
|
||||
'edit-selection': 'editSelectionContent'
|
||||
},
|
||||
toolbar: {
|
||||
'main-insert': 'mainInsertToolbar'
|
||||
}
|
||||
};
|
||||
|
||||
_.each(handlers, function(regionHandlers, region) {
|
||||
_.each(regionHandlers, function(callback, handler) {
|
||||
_.each(handlers, function (regionHandlers, region) {
|
||||
_.each(regionHandlers, function (callback, handler) {
|
||||
this.on(region + ':render:' + handler, this[callback], this);
|
||||
}, this);
|
||||
}, this);
|
||||
},
|
||||
|
||||
uploadContent: function() {
|
||||
wp.media.view.MediaFrame.Select.prototype.uploadContent.apply(this, arguments);
|
||||
uploadContent: function () {
|
||||
window.wp.media.view.MediaFrame.Select.prototype.uploadContent.apply(this, arguments);
|
||||
this.$el.addClass('hide-toolbar');
|
||||
},
|
||||
|
||||
// Content
|
||||
embedContent: function() {
|
||||
var view = new wp.media.view.Embed({
|
||||
embedContent: function () {
|
||||
var view = new window.wp.media.view.Embed({
|
||||
controller: this,
|
||||
model: this.state()
|
||||
}).render();
|
||||
@ -197,12 +247,12 @@ define([
|
||||
view.url.focus();
|
||||
},
|
||||
|
||||
editSelectionContent: function() {
|
||||
var state = this.state(),
|
||||
selection = state.get('selection'),
|
||||
view;
|
||||
editSelectionContent: function () {
|
||||
var state = this.state();
|
||||
var selection = state.get('selection');
|
||||
var view;
|
||||
|
||||
view = new wp.media.view.AttachmentsBrowser({
|
||||
view = new window.wp.media.view.AttachmentsBrowser({
|
||||
controller: this,
|
||||
collection: selection,
|
||||
selection: selection,
|
||||
@ -211,14 +261,14 @@ define([
|
||||
search: false,
|
||||
dragInfo: true,
|
||||
|
||||
AttachmentView: wp.media.view.Attachment.EditSelection
|
||||
AttachmentView: window.wp.media.view.Attachment.EditSelection
|
||||
}).render();
|
||||
|
||||
view.toolbar.set('backToLibrary', {
|
||||
text: 'Return to library',
|
||||
priority: -100,
|
||||
|
||||
click: function() {
|
||||
click: function () {
|
||||
this.controller.content.mode('browse');
|
||||
}
|
||||
});
|
||||
@ -228,23 +278,23 @@ define([
|
||||
},
|
||||
|
||||
// Toolbars
|
||||
selectionStatusToolbar: function(view) {
|
||||
selectionStatusToolbar: function (view) {
|
||||
var editable = this.state().get('editable');
|
||||
|
||||
view.set('selection', new wp.media.view.Selection({
|
||||
view.set('selection', new window.wp.media.view.Selection({
|
||||
controller: this,
|
||||
collection: this.state().get('selection'),
|
||||
priority: -40,
|
||||
|
||||
// If the selection is editable, pass the callback to
|
||||
// switch the content mode.
|
||||
editable: editable && function() {
|
||||
editable: editable && function () {
|
||||
this.controller.content.mode('edit-selection');
|
||||
}
|
||||
}).render() );
|
||||
}).render());
|
||||
},
|
||||
|
||||
mainInsertToolbar: function(view) {
|
||||
mainInsertToolbar: function (view) {
|
||||
var controller = this;
|
||||
|
||||
this.selectionStatusToolbar(view);
|
||||
@ -255,9 +305,9 @@ define([
|
||||
text: 'Select Image',
|
||||
requires: { selection: true },
|
||||
|
||||
click: function() {
|
||||
var state = controller.state(),
|
||||
selection = state.get('selection');
|
||||
click: function () {
|
||||
var state = controller.state();
|
||||
var selection = state.get('selection');
|
||||
|
||||
controller.close();
|
||||
state.trigger('insert', selection).reset();
|
||||
@ -265,8 +315,9 @@ define([
|
||||
});
|
||||
},
|
||||
|
||||
mainEmbedToolbar: function(toolbar) {
|
||||
toolbar.view = new wp.media.view.Toolbar.Embed({
|
||||
mainEmbedToolbar: function (toolbar) {
|
||||
var tbar = toolbar;
|
||||
tbar.view = new window.wp.media.view.Toolbar.Embed({
|
||||
controller: this,
|
||||
text: 'Add images'
|
||||
});
|
||||
@ -274,51 +325,48 @@ define([
|
||||
|
||||
});
|
||||
|
||||
var theFrame = this._mediaManager = new MediaManager({
|
||||
id: 'mailpoet-media-manager',
|
||||
frame: 'select',
|
||||
title: 'Select image',
|
||||
editing: false,
|
||||
multiple: false,
|
||||
library: {
|
||||
type: 'image'
|
||||
},
|
||||
displaySettings: false,
|
||||
button: {
|
||||
text: 'Select'
|
||||
}
|
||||
}),
|
||||
that = this;
|
||||
theFrame = new MediaManager({
|
||||
id: 'mailpoet-media-manager',
|
||||
frame: 'select',
|
||||
title: 'Select image',
|
||||
editing: false,
|
||||
multiple: false,
|
||||
library: {
|
||||
type: 'image'
|
||||
},
|
||||
displaySettings: false,
|
||||
button: {
|
||||
text: 'Select'
|
||||
}
|
||||
});
|
||||
this._mediaManager = theFrame;
|
||||
|
||||
this._mediaManager.on('insert', function() {
|
||||
this._mediaManager.on('insert', function () {
|
||||
// Append media manager image selections to Images tab
|
||||
var selection = theFrame.state().get('selection');
|
||||
selection.each(function(attachment) {
|
||||
var sizes = attachment.get('sizes'),
|
||||
// Following advice from Becs, the target width should
|
||||
// be a double of one column width to render well on
|
||||
// retina screen devices
|
||||
targetImageWidth = 1320,
|
||||
selection.each(function (attachment) {
|
||||
var sizes = attachment.get('sizes');
|
||||
// Following advice from Becs, the target width should
|
||||
// be a double of one column width to render well on
|
||||
// retina screen devices
|
||||
var targetImageWidth = 1320;
|
||||
|
||||
// For main image use the size, that's closest to being 660px in width
|
||||
sizeKeys = _.keys(sizes),
|
||||
// Pick the width that is closest to target width
|
||||
var increasingByWidthDifference = _.sortBy(
|
||||
_.keys(sizes),
|
||||
function (size) { return Math.abs(targetImageWidth - sizes[size].width); }
|
||||
);
|
||||
var bestWidth = sizes[_.first(increasingByWidthDifference)].width;
|
||||
var imagesOfBestWidth = _.filter(_.values(sizes), function (size) { return size.width === bestWidth; });
|
||||
|
||||
// Pick the width that is closest to target width
|
||||
increasingByWidthDifference = _.sortBy(
|
||||
_.keys(sizes),
|
||||
function(size) { return Math.abs(targetImageWidth - sizes[size].width); }
|
||||
),
|
||||
bestWidth = sizes[_.first(increasingByWidthDifference)].width,
|
||||
imagesOfBestWidth = _.filter(_.values(sizes), function(size) { return size.width === bestWidth; }),
|
||||
|
||||
// Maximize the height if there are multiple images with same width
|
||||
mainSize = _.max(imagesOfBestWidth, function(size) { return size.height; });
|
||||
// Maximize the height if there are multiple images with same width
|
||||
var mainSize = _.max(imagesOfBestWidth, function (size) { return size.height; });
|
||||
|
||||
that.model.set({
|
||||
height: mainSize.height + 'px',
|
||||
width: mainSize.width + 'px',
|
||||
src: mainSize.url,
|
||||
alt: (attachment.get('alt') !== "" && attachment.get('alt') !== undefined) ? attachment.get('alt') : attachment.get('title')
|
||||
alt: (attachment.get('alt') !== '' && attachment.get('alt') !== undefined) ? attachment.get('alt') : attachment.get('title')
|
||||
});
|
||||
// Rerender settings view due to changes from outside of settings view
|
||||
that.render();
|
||||
@ -327,11 +375,11 @@ define([
|
||||
|
||||
this._mediaManager.open();
|
||||
},
|
||||
changeAddress: function(event) {
|
||||
changeAddress: function (event) {
|
||||
var src = jQuery(event.target).val();
|
||||
var image = new Image();
|
||||
|
||||
image.onload = function() {
|
||||
image.onload = function () {
|
||||
this.model.set({
|
||||
src: src,
|
||||
width: image.naturalWidth + 'px',
|
||||
@ -341,7 +389,7 @@ define([
|
||||
|
||||
image.src = src;
|
||||
},
|
||||
onBeforeDestroy: function() {
|
||||
onBeforeDestroy: function () {
|
||||
base.BlockSettingsView.prototype.onBeforeDestroy.apply(this, arguments);
|
||||
if (typeof this._mediaManager === 'object') {
|
||||
this._mediaManager.remove();
|
||||
@ -350,14 +398,14 @@ define([
|
||||
});
|
||||
|
||||
ImageWidgetView = base.WidgetView.extend({
|
||||
getTemplate: function() { return templates.imageInsertion; },
|
||||
getTemplate: function () { return window.templates.imageInsertion; },
|
||||
behaviors: {
|
||||
DraggableBehavior: {
|
||||
cloneOriginal: true,
|
||||
drop: function() {
|
||||
drop: function () {
|
||||
return new Module.ImageBlockModel();
|
||||
},
|
||||
onDrop: function(options) {
|
||||
onDrop: function (options) {
|
||||
options.droppedView.triggerMethod('showSettings', { showImageManager: true });
|
||||
}
|
||||
}
|
||||
@ -365,7 +413,7 @@ define([
|
||||
});
|
||||
Module.ImageWidgetView = ImageWidgetView;
|
||||
|
||||
App.on('before:start', function(App, options) {
|
||||
App.on('before:start', function (App) {
|
||||
App.registerBlockType('image', {
|
||||
blockModel: Module.ImageBlockModel,
|
||||
blockView: Module.ImageBlockView
|
||||
|
@ -11,40 +11,45 @@
|
||||
* block settings view.
|
||||
*/
|
||||
define([
|
||||
'backbone',
|
||||
'backbone.marionette',
|
||||
'backbone.radio',
|
||||
'underscore',
|
||||
'jquery',
|
||||
'mailpoet',
|
||||
'newsletter_editor/App',
|
||||
'newsletter_editor/components/communication',
|
||||
'newsletter_editor/blocks/base',
|
||||
'newsletter_editor/blocks/button',
|
||||
'newsletter_editor/blocks/divider',
|
||||
'select2'
|
||||
], function(
|
||||
Backbone,
|
||||
Marionette,
|
||||
Radio,
|
||||
_,
|
||||
jQuery,
|
||||
MailPoet,
|
||||
App,
|
||||
CommunicationComponent,
|
||||
BaseBlock,
|
||||
ButtonBlock,
|
||||
DividerBlock
|
||||
'backbone',
|
||||
'backbone.marionette',
|
||||
'backbone.radio',
|
||||
'underscore',
|
||||
'jquery',
|
||||
'mailpoet',
|
||||
'newsletter_editor/App',
|
||||
'newsletter_editor/components/communication',
|
||||
'newsletter_editor/blocks/base',
|
||||
'newsletter_editor/blocks/button',
|
||||
'newsletter_editor/blocks/divider',
|
||||
'select2'
|
||||
], function (
|
||||
Backbone,
|
||||
Marionette,
|
||||
Radio,
|
||||
_,
|
||||
jQuery,
|
||||
MailPoet,
|
||||
App,
|
||||
CommunicationComponent,
|
||||
BaseBlock,
|
||||
ButtonBlock,
|
||||
DividerBlock
|
||||
) {
|
||||
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var Module = {},
|
||||
base = BaseBlock;
|
||||
var Module = {};
|
||||
var base = BaseBlock;
|
||||
var PostsDisplayOptionsSettingsView;
|
||||
var SinglePostSelectionSettingsView;
|
||||
var EmptyPostSelectionSettingsView;
|
||||
var PostSelectionSettingsView;
|
||||
var PostsSelectionCollectionView;
|
||||
|
||||
Module.PostsBlockModel = base.BlockModel.extend({
|
||||
stale: ['_selectedPosts', '_availablePosts', '_transformedPosts'],
|
||||
defaults: function() {
|
||||
defaults: function () {
|
||||
return this._getDefaults({
|
||||
type: 'posts',
|
||||
amount: '10',
|
||||
@ -60,7 +65,7 @@ define([
|
||||
titleIsLink: false, // false|true
|
||||
imageFullWidth: false, // true|false
|
||||
featuredImagePosition: 'belowTitle', // 'aboveTitle'|'belowTitle'|'none'
|
||||
//imageAlignment: 'centerPadded', // 'centerFull'|'centerPadded'|'left'|'right'|'alternate'|'none'
|
||||
// imageAlignment: 'centerPadded', // 'centerFull'|'centerPadded'|'left'|'right'|'alternate'|'none'
|
||||
showAuthor: 'no', // 'no'|'aboveText'|'belowText'
|
||||
authorPrecededBy: 'Author:',
|
||||
showCategories: 'no', // 'no'|'aboveText'|'belowText'
|
||||
@ -79,7 +84,7 @@ define([
|
||||
_transformedPosts: new (App.getBlockTypeModel('container'))()
|
||||
}, App.getConfig().get('blockDefaults.posts'));
|
||||
},
|
||||
relations: function() {
|
||||
relations: function () {
|
||||
return {
|
||||
readMoreButton: App.getBlockTypeModel('button'),
|
||||
divider: App.getBlockTypeModel('divider'),
|
||||
@ -88,11 +93,10 @@ define([
|
||||
_transformedPosts: App.getBlockTypeModel('container')
|
||||
};
|
||||
},
|
||||
initialize: function() {
|
||||
var that = this,
|
||||
POST_REFRESH_DELAY_MS = 500,
|
||||
refreshAvailablePosts = _.debounce(this.fetchAvailablePosts.bind(this), POST_REFRESH_DELAY_MS),
|
||||
refreshTransformedPosts = _.debounce(this._refreshTransformedPosts.bind(this), POST_REFRESH_DELAY_MS);
|
||||
initialize: function () {
|
||||
var POST_REFRESH_DELAY_MS = 500;
|
||||
var refreshAvailablePosts = _.debounce(this.fetchAvailablePosts.bind(this), POST_REFRESH_DELAY_MS);
|
||||
var refreshTransformedPosts = _.debounce(this._refreshTransformedPosts.bind(this), POST_REFRESH_DELAY_MS);
|
||||
|
||||
// Attach Radio.Requests API primarily for highlighting
|
||||
_.extend(this, Radio.Requests);
|
||||
@ -108,41 +112,41 @@ define([
|
||||
|
||||
this.on('insertSelectedPosts', this._insertSelectedPosts, this);
|
||||
},
|
||||
fetchAvailablePosts: function() {
|
||||
fetchAvailablePosts: function () {
|
||||
var that = this;
|
||||
this.set('offset', 0);
|
||||
CommunicationComponent.getPosts(this.toJSON()).done(function(posts) {
|
||||
CommunicationComponent.getPosts(this.toJSON()).done(function (posts) {
|
||||
that.get('_availablePosts').reset(posts);
|
||||
that.get('_selectedPosts').reset(); // Empty out the collection
|
||||
that.trigger('change:_availablePosts');
|
||||
}).fail(function() {
|
||||
}).fail(function () {
|
||||
MailPoet.Notice.error(MailPoet.I18n.t('failedToFetchAvailablePosts'));
|
||||
});
|
||||
},
|
||||
_loadMorePosts: function() {
|
||||
var that = this,
|
||||
postCount = this.get('_availablePosts').length,
|
||||
nextOffset = this.get('offset') + Number(this.get('amount'));
|
||||
_loadMorePosts: function () {
|
||||
var that = this;
|
||||
var postCount = this.get('_availablePosts').length;
|
||||
var nextOffset = this.get('offset') + Number(this.get('amount'));
|
||||
|
||||
if(postCount === 0 || postCount < nextOffset) {
|
||||
if (postCount === 0 || postCount < nextOffset) {
|
||||
// No more posts to load
|
||||
return false;
|
||||
}
|
||||
this.set('offset', nextOffset);
|
||||
this.trigger('loadingMorePosts');
|
||||
|
||||
CommunicationComponent.getPosts(this.toJSON()).done(function(posts) {
|
||||
CommunicationComponent.getPosts(this.toJSON()).done(function (posts) {
|
||||
that.get('_availablePosts').add(posts);
|
||||
that.trigger('change:_availablePosts');
|
||||
}).fail(function() {
|
||||
}).fail(function () {
|
||||
MailPoet.Notice.error(MailPoet.I18n.t('failedToFetchAvailablePosts'));
|
||||
}).always(function() {
|
||||
}).always(function () {
|
||||
that.trigger('morePostsLoaded');
|
||||
});
|
||||
},
|
||||
_refreshTransformedPosts: function() {
|
||||
var that = this,
|
||||
data = this.toJSON();
|
||||
_refreshTransformedPosts: function () {
|
||||
var that = this;
|
||||
var data = this.toJSON();
|
||||
|
||||
data.posts = this.get('_selectedPosts').pluck('ID');
|
||||
|
||||
@ -151,72 +155,73 @@ define([
|
||||
return;
|
||||
}
|
||||
|
||||
CommunicationComponent.getTransformedPosts(data).done(function(posts) {
|
||||
that.get('_transformedPosts').get('blocks').reset(posts, {parse: true});
|
||||
}).fail(function() {
|
||||
CommunicationComponent.getTransformedPosts(data).done(function (posts) {
|
||||
that.get('_transformedPosts').get('blocks').reset(posts, { parse: true });
|
||||
}).fail(function () {
|
||||
MailPoet.Notice.error(MailPoet.I18n.t('failedToFetchRenderedPosts'));
|
||||
});
|
||||
},
|
||||
_insertSelectedPosts: function() {
|
||||
var that = this,
|
||||
data = this.toJSON(),
|
||||
index = this.collection.indexOf(this),
|
||||
collection = this.collection;
|
||||
_insertSelectedPosts: function () {
|
||||
var data = this.toJSON();
|
||||
var index = this.collection.indexOf(this);
|
||||
var collection = this.collection;
|
||||
|
||||
data.posts = this.get('_selectedPosts').pluck('ID');
|
||||
|
||||
if (data.posts.length === 0) return;
|
||||
|
||||
CommunicationComponent.getTransformedPosts(data).done(function(posts) {
|
||||
CommunicationComponent.getTransformedPosts(data).done(function (posts) {
|
||||
collection.add(posts, { at: index });
|
||||
}).fail(function() {
|
||||
}).fail(function () {
|
||||
MailPoet.Notice.error(MailPoet.I18n.t('failedToFetchRenderedPosts'));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Module.PostsBlockView = base.BlockView.extend({
|
||||
className: "mailpoet_block mailpoet_posts_block mailpoet_droppable_block",
|
||||
getTemplate: function() { return templates.postsBlock; },
|
||||
className: 'mailpoet_block mailpoet_posts_block mailpoet_droppable_block',
|
||||
getTemplate: function () { return window.templates.postsBlock; },
|
||||
modelEvents: {}, // Forcefully disable all events
|
||||
regions: _.extend({
|
||||
postsRegion: '.mailpoet_posts_block_posts'
|
||||
}, base.BlockView.prototype.regions),
|
||||
onDragSubstituteBy: function() { return Module.PostsWidgetView; },
|
||||
initialize: function() {
|
||||
onDragSubstituteBy: function () { return Module.PostsWidgetView; },
|
||||
initialize: function () {
|
||||
base.BlockView.prototype.initialize.apply(this, arguments);
|
||||
|
||||
this.toolsView = new Module.PostsBlockToolsView({ model: this.model });
|
||||
this.model.reply('blockView', this.notifyAboutSelf, this);
|
||||
},
|
||||
onRender: function() {
|
||||
onRender: function () {
|
||||
var ContainerView;
|
||||
var renderOptions;
|
||||
if (!this.getRegion('toolsRegion').hasView()) {
|
||||
this.showChildView('toolsRegion', this.toolsView);
|
||||
}
|
||||
this.trigger('showSettings');
|
||||
|
||||
var ContainerView = App.getBlockTypeView('container'),
|
||||
renderOptions = {
|
||||
disableTextEditor: true,
|
||||
disableDragAndDrop: true,
|
||||
emptyContainerMessage: MailPoet.I18n.t('noPostsToDisplay')
|
||||
};
|
||||
ContainerView = App.getBlockTypeView('container');
|
||||
renderOptions = {
|
||||
disableTextEditor: true,
|
||||
disableDragAndDrop: true,
|
||||
emptyContainerMessage: MailPoet.I18n.t('noPostsToDisplay')
|
||||
};
|
||||
this.showChildView('postsRegion', new ContainerView({ model: this.model.get('_transformedPosts'), renderOptions: renderOptions }));
|
||||
},
|
||||
notifyAboutSelf: function() {
|
||||
notifyAboutSelf: function () {
|
||||
return this;
|
||||
},
|
||||
onBeforeDestroy: function() {
|
||||
onBeforeDestroy: function () {
|
||||
this.model.stopReplying('blockView', this.notifyAboutSelf, this);
|
||||
}
|
||||
});
|
||||
|
||||
Module.PostsBlockToolsView = base.BlockToolsView.extend({
|
||||
getSettingsView: function() { return Module.PostsBlockSettingsView; }
|
||||
getSettingsView: function () { return Module.PostsBlockSettingsView; }
|
||||
});
|
||||
|
||||
Module.PostsBlockSettingsView = base.BlockSettingsView.extend({
|
||||
getTemplate: function() { return templates.postsBlockSettings; },
|
||||
getTemplate: function () { return window.templates.postsBlockSettings; },
|
||||
regions: {
|
||||
selectionRegion: '.mailpoet_settings_posts_selection',
|
||||
displayOptionsRegion: '.mailpoet_settings_posts_display_options'
|
||||
@ -226,19 +231,19 @@ define([
|
||||
'click .mailpoet_settings_posts_show_post_selection': 'switchToPostSelection',
|
||||
'click .mailpoet_settings_posts_insert_selected': 'insertPosts'
|
||||
},
|
||||
templateContext: function() {
|
||||
templateContext: function () {
|
||||
return {
|
||||
model: this.model.toJSON()
|
||||
};
|
||||
},
|
||||
initialize: function() {
|
||||
initialize: function () {
|
||||
this.model.trigger('startEditing');
|
||||
this.selectionView = new PostSelectionSettingsView({ model: this.model });
|
||||
this.displayOptionsView = new PostsDisplayOptionsSettingsView({ model: this.model });
|
||||
},
|
||||
onRender: function() {
|
||||
var that = this,
|
||||
blockView = this.model.request('blockView');
|
||||
onRender: function () {
|
||||
var that = this;
|
||||
this.model.request('blockView');
|
||||
|
||||
this.showChildView('selectionRegion', this.selectionView);
|
||||
this.showChildView('displayOptionsRegion', this.displayOptionsView);
|
||||
@ -248,7 +253,7 @@ define([
|
||||
template: '',
|
||||
position: 'right',
|
||||
width: App.getConfig().get('sidepanelWidth'),
|
||||
onCancel: function() {
|
||||
onCancel: function () {
|
||||
// Self destroy the block if the user closes settings modal
|
||||
that.model.destroy();
|
||||
}
|
||||
@ -258,7 +263,7 @@ define([
|
||||
this.selectionView.triggerMethod('attach');
|
||||
this.displayOptionsView.triggerMethod('attach');
|
||||
},
|
||||
switchToDisplayOptions: function() {
|
||||
switchToDisplayOptions: function () {
|
||||
// Switch content view
|
||||
this.$('.mailpoet_settings_posts_selection').addClass('mailpoet_closed');
|
||||
this.$('.mailpoet_settings_posts_display_options').removeClass('mailpoet_closed');
|
||||
@ -267,7 +272,7 @@ define([
|
||||
this.$('.mailpoet_settings_posts_show_display_options').addClass('mailpoet_hidden');
|
||||
this.$('.mailpoet_settings_posts_show_post_selection').removeClass('mailpoet_hidden');
|
||||
},
|
||||
switchToPostSelection: function() {
|
||||
switchToPostSelection: function () {
|
||||
// Switch content view
|
||||
this.$('.mailpoet_settings_posts_display_options').addClass('mailpoet_closed');
|
||||
this.$('.mailpoet_settings_posts_selection').removeClass('mailpoet_closed');
|
||||
@ -276,43 +281,43 @@ define([
|
||||
this.$('.mailpoet_settings_posts_show_post_selection').addClass('mailpoet_hidden');
|
||||
this.$('.mailpoet_settings_posts_show_display_options').removeClass('mailpoet_hidden');
|
||||
},
|
||||
insertPosts: function() {
|
||||
insertPosts: function () {
|
||||
this.model.trigger('insertSelectedPosts');
|
||||
this.model.destroy();
|
||||
this.close();
|
||||
}
|
||||
});
|
||||
|
||||
var PostsSelectionCollectionView = Marionette.CollectionView.extend({
|
||||
PostsSelectionCollectionView = Marionette.CollectionView.extend({
|
||||
className: 'mailpoet_post_scroll_container',
|
||||
childView: function() { return SinglePostSelectionSettingsView; },
|
||||
emptyView: function() { return EmptyPostSelectionSettingsView; },
|
||||
childViewOptions: function() {
|
||||
childView: function () { return SinglePostSelectionSettingsView; },
|
||||
emptyView: function () { return EmptyPostSelectionSettingsView; },
|
||||
childViewOptions: function () {
|
||||
return {
|
||||
blockModel: this.blockModel
|
||||
};
|
||||
},
|
||||
initialize: function(options) {
|
||||
initialize: function (options) {
|
||||
this.blockModel = options.blockModel;
|
||||
},
|
||||
events: {
|
||||
'scroll': 'onPostsScroll'
|
||||
scroll: 'onPostsScroll'
|
||||
},
|
||||
onPostsScroll: function(event) {
|
||||
onPostsScroll: function (event) {
|
||||
var $postsBox = jQuery(event.target);
|
||||
if($postsBox.scrollTop() + $postsBox.innerHeight() >= $postsBox[0].scrollHeight){
|
||||
if ($postsBox.scrollTop() + $postsBox.innerHeight() >= $postsBox[0].scrollHeight) {
|
||||
// Load more posts if scrolled to bottom
|
||||
this.blockModel.trigger('loadMorePosts');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var PostSelectionSettingsView = Marionette.View.extend({
|
||||
getTemplate: function() { return templates.postSelectionPostsBlockSettings; },
|
||||
PostSelectionSettingsView = Marionette.View.extend({
|
||||
getTemplate: function () { return window.templates.postSelectionPostsBlockSettings; },
|
||||
regions: {
|
||||
posts: '.mailpoet_post_selection_container'
|
||||
},
|
||||
events: function() {
|
||||
events: function () {
|
||||
return {
|
||||
'change .mailpoet_settings_posts_content_type': _.partial(this.changeField, 'contentType'),
|
||||
'change .mailpoet_posts_post_status': _.partial(this.changeField, 'postStatus'),
|
||||
@ -320,30 +325,31 @@ define([
|
||||
};
|
||||
},
|
||||
modelEvents: {
|
||||
'change:offset': function(model, value) {
|
||||
'change:offset': function (model, value) {
|
||||
// Scroll posts view to top if settings are changed
|
||||
if (value === 0) {
|
||||
this.$('.mailpoet_post_scroll_container').scrollTop(0);
|
||||
}
|
||||
},
|
||||
'loadingMorePosts': function() {
|
||||
loadingMorePosts: function () {
|
||||
this.$('.mailpoet_post_selection_loading').css('visibility', 'visible');
|
||||
},
|
||||
'morePostsLoaded': function() {
|
||||
morePostsLoaded: function () {
|
||||
this.$('.mailpoet_post_selection_loading').css('visibility', 'hidden');
|
||||
}
|
||||
},
|
||||
onRender: function() {
|
||||
onRender: function () {
|
||||
var postsView;
|
||||
// Dynamically update available post types
|
||||
CommunicationComponent.getPostTypes().done(_.bind(this._updateContentTypes, this));
|
||||
var postsView = new PostsSelectionCollectionView({
|
||||
postsView = new PostsSelectionCollectionView({
|
||||
collection: this.model.get('_availablePosts'),
|
||||
blockModel: this.model
|
||||
});
|
||||
|
||||
this.showChildView('posts', postsView);
|
||||
},
|
||||
onAttach: function() {
|
||||
onAttach: function () {
|
||||
var that = this;
|
||||
|
||||
this.$('.mailpoet_posts_categories_and_tags').select2({
|
||||
@ -356,35 +362,36 @@ define([
|
||||
term: params.term
|
||||
};
|
||||
},
|
||||
transport: function(options, success, failure) {
|
||||
transport: function (options, success, failure) {
|
||||
var taxonomies;
|
||||
var termsPromise;
|
||||
var promise = CommunicationComponent.getTaxonomies(
|
||||
that.model.get('contentType')
|
||||
).then(function(tax) {
|
||||
).then(function (tax) {
|
||||
taxonomies = tax;
|
||||
// Fetch available terms based on the list of taxonomies already fetched
|
||||
var promise = CommunicationComponent.getTerms({
|
||||
termsPromise = CommunicationComponent.getTerms({
|
||||
search: options.data.term,
|
||||
taxonomies: _.keys(taxonomies)
|
||||
}).then(function(terms) {
|
||||
}).then(function (terms) {
|
||||
return {
|
||||
taxonomies: taxonomies,
|
||||
terms: terms
|
||||
};
|
||||
});
|
||||
return promise;
|
||||
return termsPromise;
|
||||
});
|
||||
|
||||
promise.then(success);
|
||||
promise.fail(failure);
|
||||
return promise;
|
||||
},
|
||||
processResults: function(data) {
|
||||
processResults: function (data) {
|
||||
// Transform taxonomies and terms into select2 compatible format
|
||||
return {
|
||||
results: _.map(
|
||||
data.terms,
|
||||
function(item) {
|
||||
function (item) {
|
||||
return _.defaults({
|
||||
text: data.taxonomies[item.taxonomy].labels.singular_name + ': ' + item.name,
|
||||
id: item.term_id
|
||||
@ -395,29 +402,29 @@ define([
|
||||
}
|
||||
}
|
||||
}).on({
|
||||
'select2:select': function(event) {
|
||||
'select2:select': function (event) {
|
||||
var terms = that.model.get('terms');
|
||||
terms.add(event.params.data);
|
||||
// Reset whole model in order for change events to propagate properly
|
||||
that.model.set('terms', terms.toJSON());
|
||||
},
|
||||
'select2:unselect': function(event) {
|
||||
'select2:unselect': function (event) {
|
||||
var terms = that.model.get('terms');
|
||||
terms.remove(event.params.data);
|
||||
// Reset whole model in order for change events to propagate properly
|
||||
that.model.set('terms', terms.toJSON());
|
||||
}
|
||||
}).trigger( 'change' );
|
||||
}).trigger('change');
|
||||
},
|
||||
changeField: function(field, event) {
|
||||
changeField: function (field, event) {
|
||||
this.model.set(field, jQuery(event.target).val());
|
||||
},
|
||||
_updateContentTypes: function(postTypes) {
|
||||
var select = this.$('.mailpoet_settings_posts_content_type'),
|
||||
selectedValue = this.model.get('contentType');
|
||||
_updateContentTypes: function (postTypes) {
|
||||
var select = this.$('.mailpoet_settings_posts_content_type');
|
||||
var selectedValue = this.model.get('contentType');
|
||||
|
||||
select.find('option').remove();
|
||||
_.each(postTypes, function(type) {
|
||||
_.each(postTypes, function (type) {
|
||||
select.append(jQuery('<option>', {
|
||||
value: type.name,
|
||||
text: type.label
|
||||
@ -427,29 +434,29 @@ define([
|
||||
}
|
||||
});
|
||||
|
||||
var EmptyPostSelectionSettingsView = Marionette.View.extend({
|
||||
getTemplate: function() { return templates.emptyPostPostsBlockSettings; }
|
||||
EmptyPostSelectionSettingsView = Marionette.View.extend({
|
||||
getTemplate: function () { return window.templates.emptyPostPostsBlockSettings; }
|
||||
});
|
||||
|
||||
var SinglePostSelectionSettingsView = Marionette.View.extend({
|
||||
getTemplate: function() { return templates.singlePostPostsBlockSettings; },
|
||||
events: function() {
|
||||
SinglePostSelectionSettingsView = Marionette.View.extend({
|
||||
getTemplate: function () { return window.templates.singlePostPostsBlockSettings; },
|
||||
events: function () {
|
||||
return {
|
||||
'change .mailpoet_select_post_checkbox': 'postSelectionChange'
|
||||
};
|
||||
},
|
||||
templateContext: function() {
|
||||
templateContext: function () {
|
||||
return {
|
||||
model: this.model.toJSON(),
|
||||
index: this._index
|
||||
};
|
||||
},
|
||||
initialize: function(options) {
|
||||
initialize: function (options) {
|
||||
this.blockModel = options.blockModel;
|
||||
},
|
||||
postSelectionChange: function(event) {
|
||||
var checkBox = jQuery(event.target),
|
||||
selectedPostsCollection = this.blockModel.get('_selectedPosts');
|
||||
postSelectionChange: function (event) {
|
||||
var checkBox = jQuery(event.target);
|
||||
var selectedPostsCollection = this.blockModel.get('_selectedPosts');
|
||||
if (checkBox.prop('checked')) {
|
||||
selectedPostsCollection.add(this.model);
|
||||
} else {
|
||||
@ -458,37 +465,37 @@ define([
|
||||
}
|
||||
});
|
||||
|
||||
var PostsDisplayOptionsSettingsView = base.BlockSettingsView.extend({
|
||||
getTemplate: function() { return templates.displayOptionsPostsBlockSettings; },
|
||||
events: function() {
|
||||
PostsDisplayOptionsSettingsView = base.BlockSettingsView.extend({
|
||||
getTemplate: function () { return window.templates.displayOptionsPostsBlockSettings; },
|
||||
events: function () {
|
||||
return {
|
||||
"click .mailpoet_posts_select_button": 'showButtonSettings',
|
||||
"click .mailpoet_posts_select_divider": 'showDividerSettings',
|
||||
"change .mailpoet_posts_read_more_type": 'changeReadMoreType',
|
||||
"change .mailpoet_posts_display_type": 'changeDisplayType',
|
||||
"change .mailpoet_posts_title_format": 'changeTitleFormat',
|
||||
"change .mailpoet_posts_title_as_links": _.partial(this.changeBoolField, 'titleIsLink'),
|
||||
"change .mailpoet_posts_show_divider": _.partial(this.changeBoolField, 'showDivider'),
|
||||
"input .mailpoet_posts_show_amount": _.partial(this.changeField, "amount"),
|
||||
"change .mailpoet_posts_content_type": _.partial(this.changeField, "contentType"),
|
||||
"change .mailpoet_posts_include_or_exclude": _.partial(this.changeField, "inclusionType"),
|
||||
"change .mailpoet_posts_title_alignment": _.partial(this.changeField, "titleAlignment"),
|
||||
"change .mailpoet_posts_image_full_width": _.partial(this.changeBoolField, "imageFullWidth"),
|
||||
"change .mailpoet_posts_featured_image_position": _.partial(this.changeField, "featuredImagePosition"),
|
||||
"change .mailpoet_posts_show_author": _.partial(this.changeField, "showAuthor"),
|
||||
"input .mailpoet_posts_author_preceded_by": _.partial(this.changeField, "authorPrecededBy"),
|
||||
"change .mailpoet_posts_show_categories": _.partial(this.changeField, "showCategories"),
|
||||
"input .mailpoet_posts_categories": _.partial(this.changeField, "categoriesPrecededBy"),
|
||||
"input .mailpoet_posts_read_more_text": _.partial(this.changeField, "readMoreText"),
|
||||
"change .mailpoet_posts_sort_by": _.partial(this.changeField, "sortBy")
|
||||
'click .mailpoet_posts_select_button': 'showButtonSettings',
|
||||
'click .mailpoet_posts_select_divider': 'showDividerSettings',
|
||||
'change .mailpoet_posts_read_more_type': 'changeReadMoreType',
|
||||
'change .mailpoet_posts_display_type': 'changeDisplayType',
|
||||
'change .mailpoet_posts_title_format': 'changeTitleFormat',
|
||||
'change .mailpoet_posts_title_as_links': _.partial(this.changeBoolField, 'titleIsLink'),
|
||||
'change .mailpoet_posts_show_divider': _.partial(this.changeBoolField, 'showDivider'),
|
||||
'input .mailpoet_posts_show_amount': _.partial(this.changeField, 'amount'),
|
||||
'change .mailpoet_posts_content_type': _.partial(this.changeField, 'contentType'),
|
||||
'change .mailpoet_posts_include_or_exclude': _.partial(this.changeField, 'inclusionType'),
|
||||
'change .mailpoet_posts_title_alignment': _.partial(this.changeField, 'titleAlignment'),
|
||||
'change .mailpoet_posts_image_full_width': _.partial(this.changeBoolField, 'imageFullWidth'),
|
||||
'change .mailpoet_posts_featured_image_position': _.partial(this.changeField, 'featuredImagePosition'),
|
||||
'change .mailpoet_posts_show_author': _.partial(this.changeField, 'showAuthor'),
|
||||
'input .mailpoet_posts_author_preceded_by': _.partial(this.changeField, 'authorPrecededBy'),
|
||||
'change .mailpoet_posts_show_categories': _.partial(this.changeField, 'showCategories'),
|
||||
'input .mailpoet_posts_categories': _.partial(this.changeField, 'categoriesPrecededBy'),
|
||||
'input .mailpoet_posts_read_more_text': _.partial(this.changeField, 'readMoreText'),
|
||||
'change .mailpoet_posts_sort_by': _.partial(this.changeField, 'sortBy')
|
||||
};
|
||||
},
|
||||
templateContext: function() {
|
||||
templateContext: function () {
|
||||
return {
|
||||
model: this.model.toJSON()
|
||||
};
|
||||
},
|
||||
showButtonSettings: function(event) {
|
||||
showButtonSettings: function () {
|
||||
var buttonModule = ButtonBlock;
|
||||
(new buttonModule.ButtonBlockSettingsView({
|
||||
model: this.model.get('readMoreButton'),
|
||||
@ -499,7 +506,7 @@ define([
|
||||
}
|
||||
})).render();
|
||||
},
|
||||
showDividerSettings: function(event) {
|
||||
showDividerSettings: function () {
|
||||
var dividerModule = DividerBlock;
|
||||
(new dividerModule.DividerBlockSettingsView({
|
||||
model: this.model.get('divider'),
|
||||
@ -509,7 +516,7 @@ define([
|
||||
}
|
||||
})).render();
|
||||
},
|
||||
changeReadMoreType: function(event) {
|
||||
changeReadMoreType: function (event) {
|
||||
var value = jQuery(event.target).val();
|
||||
if (value == 'link') {
|
||||
this.$('.mailpoet_posts_read_more_text').removeClass('mailpoet_hidden');
|
||||
@ -520,7 +527,7 @@ define([
|
||||
}
|
||||
this.changeField('readMoreType', event);
|
||||
},
|
||||
changeDisplayType: function(event) {
|
||||
changeDisplayType: function (event) {
|
||||
var value = jQuery(event.target).val();
|
||||
if (value == 'titleOnly') {
|
||||
this.$('.mailpoet_posts_title_as_list').removeClass('mailpoet_hidden');
|
||||
@ -547,7 +554,7 @@ define([
|
||||
|
||||
this.changeField('displayType', event);
|
||||
},
|
||||
changeTitleFormat: function(event) {
|
||||
changeTitleFormat: function (event) {
|
||||
var value = jQuery(event.target).val();
|
||||
if (value == 'ul') {
|
||||
this.$('.mailpoet_posts_non_title_list_options').addClass('mailpoet_hidden');
|
||||
@ -564,18 +571,18 @@ define([
|
||||
});
|
||||
|
||||
Module.PostsWidgetView = base.WidgetView.extend({
|
||||
getTemplate: function() { return templates.postsInsertion; },
|
||||
getTemplate: function () { return window.templates.postsInsertion; },
|
||||
behaviors: {
|
||||
DraggableBehavior: {
|
||||
cloneOriginal: true,
|
||||
drop: function() {
|
||||
drop: function () {
|
||||
return new Module.PostsBlockModel({}, { parse: true });
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
App.on('before:start', function(App, options) {
|
||||
App.on('before:start', function (App) {
|
||||
App.registerBlockType('posts', {
|
||||
blockModel: Module.PostsBlockModel,
|
||||
blockView: Module.PostsBlockView
|
||||
|
@ -2,26 +2,27 @@
|
||||
* Social icons content block
|
||||
*/
|
||||
define([
|
||||
'newsletter_editor/App',
|
||||
'newsletter_editor/blocks/base',
|
||||
'backbone',
|
||||
'backbone.marionette',
|
||||
'backbone.supermodel',
|
||||
'underscore',
|
||||
'jquery'
|
||||
], function(App, BaseBlock, Backbone, Marionette, SuperModel, _, jQuery) {
|
||||
'newsletter_editor/App',
|
||||
'newsletter_editor/blocks/base',
|
||||
'backbone',
|
||||
'backbone.marionette',
|
||||
'backbone.supermodel',
|
||||
'underscore',
|
||||
'jquery'
|
||||
], function (App, BaseBlock, Backbone, Marionette, SuperModel, _, jQuery) {
|
||||
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var Module = {},
|
||||
base = BaseBlock,
|
||||
SocialBlockSettingsIconSelectorView,
|
||||
SocialBlockSettingsIconView,
|
||||
SocialBlockSettingsIconCollectionView,
|
||||
SocialBlockSettingsStylesView;
|
||||
var Module = {};
|
||||
var base = BaseBlock;
|
||||
var SocialBlockSettingsIconSelectorView;
|
||||
var SocialBlockSettingsIconView;
|
||||
var SocialBlockSettingsIconCollectionView;
|
||||
var SocialBlockSettingsStylesView;
|
||||
var SocialIconView;
|
||||
|
||||
Module.SocialIconModel = SuperModel.extend({
|
||||
defaults: function() {
|
||||
defaults: function () {
|
||||
var defaultValues = App.getConfig().get('socialIcons.custom');
|
||||
return {
|
||||
type: 'socialIcon',
|
||||
@ -33,19 +34,19 @@ define([
|
||||
text: defaultValues.get('title')
|
||||
};
|
||||
},
|
||||
initialize: function(options) {
|
||||
initialize: function () {
|
||||
var that = this;
|
||||
// Make model swap to default values for that type when iconType changes
|
||||
this.on('change:iconType', function() {
|
||||
var defaultValues = App.getConfig().get('socialIcons').get(that.get('iconType')),
|
||||
iconSet = that.collection.iconBlockModel.getIconSet();
|
||||
this.on('change:iconType', function () {
|
||||
var defaultValues = App.getConfig().get('socialIcons').get(that.get('iconType'));
|
||||
var iconSet = that.collection.iconBlockModel.getIconSet();
|
||||
this.set({
|
||||
link: defaultValues.get('defaultLink'),
|
||||
image: iconSet.get(that.get('iconType')),
|
||||
text: defaultValues.get('title')
|
||||
});
|
||||
}, this);
|
||||
this.on('change', function() { App.getChannel().trigger('autoSave'); });
|
||||
this.on('change', function () { App.getChannel().trigger('autoSave'); });
|
||||
}
|
||||
});
|
||||
|
||||
@ -55,7 +56,7 @@ define([
|
||||
|
||||
Module.SocialBlockModel = base.BlockModel.extend({
|
||||
name: 'iconBlockModel',
|
||||
defaults: function() {
|
||||
defaults: function () {
|
||||
return this._getDefaults({
|
||||
type: 'social',
|
||||
iconSet: 'default',
|
||||
@ -65,31 +66,31 @@ define([
|
||||
relations: {
|
||||
icons: Module.SocialIconCollectionModel
|
||||
},
|
||||
initialize: function() {
|
||||
initialize: function () {
|
||||
this.get('icons').on('add remove change', this._iconsChanged, this);
|
||||
this.on('change:iconSet', this.changeIconSet, this);
|
||||
},
|
||||
getIconSet: function() {
|
||||
getIconSet: function () {
|
||||
return App.getAvailableStyles().get('socialIconSets').get(this.get('iconSet'));
|
||||
},
|
||||
changeIconSet: function() {
|
||||
changeIconSet: function () {
|
||||
var iconSet = this.getIconSet();
|
||||
_.each(this.get('icons').models, function(model) {
|
||||
_.each(this.get('icons').models, function (model) {
|
||||
model.set('image', iconSet.get(model.get('iconType')));
|
||||
});
|
||||
},
|
||||
_iconsChanged: function() {
|
||||
App.getChannel().trigger('autoSave');
|
||||
_iconsChanged: function () {
|
||||
App.getChannel().trigger('autoSave');
|
||||
}
|
||||
});
|
||||
|
||||
var SocialIconView = Marionette.View.extend({
|
||||
SocialIconView = Marionette.View.extend({
|
||||
tagName: 'span',
|
||||
getTemplate: function() { return templates.socialIconBlock; },
|
||||
getTemplate: function () { return window.templates.socialIconBlock; },
|
||||
modelEvents: {
|
||||
'change': 'render'
|
||||
change: 'render'
|
||||
},
|
||||
templateContext: function() {
|
||||
templateContext: function () {
|
||||
var allIconSets = App.getAvailableStyles().get('socialIconSets');
|
||||
return {
|
||||
model: this.model.toJSON(),
|
||||
@ -105,7 +106,7 @@ define([
|
||||
|
||||
Module.SocialBlockView = base.BlockView.extend({
|
||||
className: 'mailpoet_block mailpoet_social_block mailpoet_droppable_block',
|
||||
getTemplate: function() { return templates.socialBlock; },
|
||||
getTemplate: function () { return window.templates.socialBlock; },
|
||||
regions: _.extend({}, base.BlockView.prototype.regions, {
|
||||
icons: '.mailpoet_social'
|
||||
}),
|
||||
@ -115,39 +116,39 @@ define([
|
||||
behaviors: _.extend({}, base.BlockView.prototype.behaviors, {
|
||||
ShowSettingsBehavior: {}
|
||||
}),
|
||||
onDragSubstituteBy: function() { return Module.SocialWidgetView; },
|
||||
onRender: function() {
|
||||
onDragSubstituteBy: function () { return Module.SocialWidgetView; },
|
||||
onRender: function () {
|
||||
this.toolsView = new Module.SocialBlockToolsView({ model: this.model });
|
||||
this.showChildView('toolsRegion', this.toolsView);
|
||||
this.showChildView('icons', new Module.SocialIconCollectionView({
|
||||
collection: this.model.get('icons')
|
||||
}))
|
||||
}));
|
||||
}
|
||||
});
|
||||
|
||||
Module.SocialBlockToolsView = base.BlockToolsView.extend({
|
||||
getSettingsView: function() { return Module.SocialBlockSettingsView; }
|
||||
getSettingsView: function () { return Module.SocialBlockSettingsView; }
|
||||
});
|
||||
|
||||
// Sidebar view container
|
||||
Module.SocialBlockSettingsView = base.BlockSettingsView.extend({
|
||||
getTemplate: function() { return templates.socialBlockSettings; },
|
||||
getTemplate: function () { return window.templates.socialBlockSettings; },
|
||||
regions: {
|
||||
iconRegion: '#mailpoet_social_icons_selection',
|
||||
stylesRegion: '#mailpoet_social_icons_styles'
|
||||
},
|
||||
events: function() {
|
||||
events: function () {
|
||||
return {
|
||||
"click .mailpoet_done_editing": "close"
|
||||
'click .mailpoet_done_editing': 'close'
|
||||
};
|
||||
},
|
||||
initialize: function() {
|
||||
initialize: function () {
|
||||
base.BlockSettingsView.prototype.initialize.apply(this, arguments);
|
||||
|
||||
this._iconSelectorView = new SocialBlockSettingsIconSelectorView({ model: this.model });
|
||||
this._stylesView = new SocialBlockSettingsStylesView({ model: this.model });
|
||||
},
|
||||
onRender: function() {
|
||||
onRender: function () {
|
||||
this.showChildView('iconRegion', this._iconSelectorView);
|
||||
this.showChildView('stylesRegion', this._stylesView);
|
||||
}
|
||||
@ -155,47 +156,47 @@ define([
|
||||
|
||||
// Single icon settings view, used by the selector view
|
||||
SocialBlockSettingsIconView = Marionette.View.extend({
|
||||
getTemplate: function() { return templates.socialSettingsIcon; },
|
||||
events: function() {
|
||||
getTemplate: function () { return window.templates.socialSettingsIcon; },
|
||||
events: function () {
|
||||
return {
|
||||
"click .mailpoet_delete_block": "deleteIcon",
|
||||
"change .mailpoet_social_icon_field_type": _.partial(this.changeField, "iconType"),
|
||||
"input .mailpoet_social_icon_field_image": _.partial(this.changeField, "image"),
|
||||
"input .mailpoet_social_icon_field_link": this.changeLink,
|
||||
"input .mailpoet_social_icon_field_text": _.partial(this.changeField, "text")
|
||||
'click .mailpoet_delete_block': 'deleteIcon',
|
||||
'change .mailpoet_social_icon_field_type': _.partial(this.changeField, 'iconType'),
|
||||
'input .mailpoet_social_icon_field_image': _.partial(this.changeField, 'image'),
|
||||
'input .mailpoet_social_icon_field_link': this.changeLink,
|
||||
'input .mailpoet_social_icon_field_text': _.partial(this.changeField, 'text')
|
||||
};
|
||||
},
|
||||
modelEvents: {
|
||||
'change:iconType': 'render',
|
||||
'change:image': function() {
|
||||
'change:image': function () {
|
||||
this.$('.mailpoet_social_icon_image').attr('src', this.model.get('image'));
|
||||
},
|
||||
'change:text': function() {
|
||||
'change:text': function () {
|
||||
this.$('.mailpoet_social_icon_image').attr('alt', this.model.get('text'));
|
||||
}
|
||||
},
|
||||
templateContext: function() {
|
||||
var icons = App.getConfig().get('socialIcons'),
|
||||
// Construct icon type list of format [{iconType: 'type', title: 'Title'}, ...]
|
||||
availableIconTypes = _.map(_.keys(icons.attributes), function(key) { return { iconType: key, title: icons.get(key).get('title') }; }),
|
||||
allIconSets = App.getAvailableStyles().get('socialIconSets');
|
||||
templateContext: function () {
|
||||
var icons = App.getConfig().get('socialIcons');
|
||||
// Construct icon type list of format [{iconType: 'type', title: 'Title'}, ...]
|
||||
var availableIconTypes = _.map(_.keys(icons.attributes), function (key) { return { iconType: key, title: icons.get(key).get('title') }; });
|
||||
var allIconSets = App.getAvailableStyles().get('socialIconSets');
|
||||
return _.extend({}, base.BlockView.prototype.templateContext.apply(this, arguments), {
|
||||
iconTypes: availableIconTypes,
|
||||
currentType: icons.get(this.model.get('iconType')).toJSON(),
|
||||
allIconSets: allIconSets.toJSON()
|
||||
});
|
||||
},
|
||||
deleteIcon: function() {
|
||||
deleteIcon: function () {
|
||||
this.model.destroy();
|
||||
},
|
||||
changeLink: function(event) {
|
||||
changeLink: function (event) {
|
||||
if (this.model.get('iconType') === 'email') {
|
||||
this.model.set('link', 'mailto:' + jQuery(event.target).val());
|
||||
} else {
|
||||
return this.changeField('link', event);
|
||||
}
|
||||
},
|
||||
changeField: function(field, event) {
|
||||
changeField: function (field, event) {
|
||||
this.model.set(field, jQuery(event.target).val());
|
||||
}
|
||||
});
|
||||
@ -212,9 +213,9 @@ define([
|
||||
|
||||
// Select icons section container view
|
||||
SocialBlockSettingsIconSelectorView = Marionette.View.extend({
|
||||
getTemplate: function() { return templates.socialSettingsIconSelector; },
|
||||
getTemplate: function () { return window.templates.socialSettingsIconSelector; },
|
||||
regions: {
|
||||
'icons': '#mailpoet_social_icon_selector_contents'
|
||||
icons: '#mailpoet_social_icon_selector_contents'
|
||||
},
|
||||
events: {
|
||||
'click .mailpoet_add_social_icon': 'addSocialIcon'
|
||||
@ -222,11 +223,11 @@ define([
|
||||
modelEvents: {
|
||||
'change:iconSet': 'render'
|
||||
},
|
||||
addSocialIcon: function() {
|
||||
addSocialIcon: function () {
|
||||
// Add a social icon with default values
|
||||
this.model.get('icons').add({});
|
||||
},
|
||||
onRender: function() {
|
||||
onRender: function () {
|
||||
this.showChildView('icons', new SocialBlockSettingsIconCollectionView({
|
||||
collection: this.model.get('icons')
|
||||
}));
|
||||
@ -235,17 +236,17 @@ define([
|
||||
});
|
||||
|
||||
SocialBlockSettingsStylesView = Marionette.View.extend({
|
||||
getTemplate: function() { return templates.socialSettingsStyles; },
|
||||
getTemplate: function () { return window.templates.socialSettingsStyles; },
|
||||
modelEvents: {
|
||||
'change': 'render'
|
||||
change: 'render'
|
||||
},
|
||||
events: {
|
||||
'click .mailpoet_social_icon_set': 'changeSocialIconSet'
|
||||
},
|
||||
initialize: function() {
|
||||
initialize: function () {
|
||||
this.listenTo(this.model.get('icons'), 'add remove change', this.render);
|
||||
},
|
||||
templateContext: function() {
|
||||
templateContext: function () {
|
||||
var allIconSets = App.getAvailableStyles().get('socialIconSets');
|
||||
return {
|
||||
activeSet: this.model.get('iconSet'),
|
||||
@ -254,20 +255,20 @@ define([
|
||||
availableSocialIcons: this.model.get('icons').pluck('iconType')
|
||||
};
|
||||
},
|
||||
changeSocialIconSet: function(event) {
|
||||
changeSocialIconSet: function (event) {
|
||||
this.model.set('iconSet', jQuery(event.currentTarget).data('setname'));
|
||||
},
|
||||
onBeforeDestroy: function() {
|
||||
onBeforeDestroy: function () {
|
||||
this.model.get('icons').off('add remove', this.render, this);
|
||||
}
|
||||
});
|
||||
|
||||
Module.SocialWidgetView = base.WidgetView.extend({
|
||||
getTemplate: function() { return templates.socialInsertion; },
|
||||
getTemplate: function () { return window.templates.socialInsertion; },
|
||||
behaviors: {
|
||||
DraggableBehavior: {
|
||||
cloneOriginal: true,
|
||||
drop: function() {
|
||||
drop: function () {
|
||||
return new Module.SocialBlockModel({
|
||||
type: 'social',
|
||||
iconSet: 'default',
|
||||
@ -297,7 +298,7 @@ define([
|
||||
}
|
||||
});
|
||||
|
||||
App.on('before:start', function(App, options) {
|
||||
App.on('before:start', function (App) {
|
||||
App.registerBlockType('social', {
|
||||
blockModel: Module.SocialBlockModel,
|
||||
blockView: Module.SocialBlockView
|
||||
|
@ -2,18 +2,18 @@
|
||||
* Spacer content block
|
||||
*/
|
||||
define([
|
||||
'newsletter_editor/App',
|
||||
'newsletter_editor/blocks/base',
|
||||
'underscore'
|
||||
], function(App, BaseBlock, _) {
|
||||
'newsletter_editor/App',
|
||||
'newsletter_editor/blocks/base',
|
||||
'underscore'
|
||||
], function (App, BaseBlock, _) {
|
||||
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var Module = {},
|
||||
base = BaseBlock;
|
||||
var Module = {};
|
||||
var base = BaseBlock;
|
||||
|
||||
Module.SpacerBlockModel = base.BlockModel.extend({
|
||||
defaults: function() {
|
||||
defaults: function () {
|
||||
return this._getDefaults({
|
||||
type: 'spacer',
|
||||
styles: {
|
||||
@ -27,8 +27,8 @@ define([
|
||||
});
|
||||
|
||||
Module.SpacerBlockView = base.BlockView.extend({
|
||||
className: "mailpoet_block mailpoet_spacer_block mailpoet_droppable_block",
|
||||
getTemplate: function() { return templates.spacerBlock; },
|
||||
className: 'mailpoet_block mailpoet_spacer_block mailpoet_droppable_block',
|
||||
getTemplate: function () { return window.templates.spacerBlock; },
|
||||
behaviors: _.defaults({
|
||||
ResizableBehavior: {
|
||||
elementSelector: '.mailpoet_spacer',
|
||||
@ -41,53 +41,53 @@ define([
|
||||
}
|
||||
}, base.BlockView.prototype.behaviors),
|
||||
modelEvents: _.omit(base.BlockView.prototype.modelEvents, 'change'),
|
||||
onDragSubstituteBy: function() { return Module.SpacerWidgetView; },
|
||||
initialize: function() {
|
||||
onDragSubstituteBy: function () { return Module.SpacerWidgetView; },
|
||||
initialize: function () {
|
||||
base.BlockView.prototype.initialize.apply(this, arguments);
|
||||
|
||||
this.listenTo(this.model, 'change:styles.block.backgroundColor', this.render);
|
||||
this.listenTo(this.model, 'change:styles.block.height', this.changeHeight);
|
||||
},
|
||||
onRender: function() {
|
||||
onRender: function () {
|
||||
this.toolsView = new Module.SpacerBlockToolsView({ model: this.model });
|
||||
this.showChildView('toolsRegion', this.toolsView);
|
||||
},
|
||||
changeHeight: function() {
|
||||
changeHeight: function () {
|
||||
this.$('.mailpoet_spacer').css('height', this.model.get('styles.block.height'));
|
||||
this.$('.mailpoet_resize_handle_text').text(this.model.get('styles.block.height'));
|
||||
},
|
||||
onBeforeDestroy: function() {
|
||||
onBeforeDestroy: function () {
|
||||
this.stopListening(this.model);
|
||||
}
|
||||
});
|
||||
|
||||
Module.SpacerBlockToolsView = base.BlockToolsView.extend({
|
||||
getSettingsView: function() { return Module.SpacerBlockSettingsView; }
|
||||
getSettingsView: function () { return Module.SpacerBlockSettingsView; }
|
||||
});
|
||||
|
||||
Module.SpacerBlockSettingsView = base.BlockSettingsView.extend({
|
||||
getTemplate: function() { return templates.spacerBlockSettings; },
|
||||
events: function() {
|
||||
getTemplate: function () { return window.templates.spacerBlockSettings; },
|
||||
events: function () {
|
||||
return {
|
||||
"change .mailpoet_field_spacer_background_color": _.partial(this.changeColorField, "styles.block.backgroundColor"),
|
||||
"click .mailpoet_done_editing": "close"
|
||||
'change .mailpoet_field_spacer_background_color': _.partial(this.changeColorField, 'styles.block.backgroundColor'),
|
||||
'click .mailpoet_done_editing': 'close'
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
Module.SpacerWidgetView = base.WidgetView.extend({
|
||||
getTemplate: function() { return templates.spacerInsertion; },
|
||||
getTemplate: function () { return window.templates.spacerInsertion; },
|
||||
behaviors: {
|
||||
DraggableBehavior: {
|
||||
cloneOriginal: true,
|
||||
drop: function() {
|
||||
drop: function () {
|
||||
return new Module.SpacerBlockModel();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
App.on('before:start', function(App, options) {
|
||||
App.on('before:start', function (App) {
|
||||
App.registerBlockType('spacer', {
|
||||
blockModel: Module.SpacerBlockModel,
|
||||
blockView: Module.SpacerBlockView
|
||||
|
@ -2,18 +2,19 @@
|
||||
* Text content block
|
||||
*/
|
||||
define([
|
||||
'newsletter_editor/App',
|
||||
'newsletter_editor/blocks/base',
|
||||
'underscore'
|
||||
], function(App, BaseBlock, _) {
|
||||
'newsletter_editor/App',
|
||||
'newsletter_editor/blocks/base',
|
||||
'underscore',
|
||||
'mailpoet'
|
||||
], function (App, BaseBlock, _, MailPoet) {
|
||||
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var Module = {},
|
||||
base = BaseBlock;
|
||||
var Module = {};
|
||||
var base = BaseBlock;
|
||||
|
||||
Module.TextBlockModel = base.BlockModel.extend({
|
||||
defaults: function() {
|
||||
defaults: function () {
|
||||
return this._getDefaults({
|
||||
type: 'text',
|
||||
text: 'Edit this to insert text'
|
||||
@ -22,18 +23,18 @@ define([
|
||||
});
|
||||
|
||||
Module.TextBlockView = base.BlockView.extend({
|
||||
className: "mailpoet_block mailpoet_text_block mailpoet_droppable_block",
|
||||
getTemplate: function() { return templates.textBlock; },
|
||||
className: 'mailpoet_block mailpoet_text_block mailpoet_droppable_block',
|
||||
getTemplate: function () { return window.templates.textBlock; },
|
||||
modelEvents: _.omit(base.BlockView.prototype.modelEvents, 'change'), // Prevent rerendering on model change due to text editor redrawing
|
||||
behaviors: _.extend({}, base.BlockView.prototype.behaviors, {
|
||||
TextEditorBehavior: {
|
||||
toolbar1: "formatselect bold italic forecolor | link unlink",
|
||||
toolbar2: "alignleft aligncenter alignright alignjustify | bullist numlist blockquote | code mailpoet_shortcodes",
|
||||
validElements: "p[class|style],span[class|style],a[href|class|title|target|style],h1[class|style],h2[class|style],h3[class|style],ol[class|style],ul[class|style],li[class|style],strong[class|style],em[class|style],strike,br,blockquote[class|style],table[class|style],tr[class|style],th[class|style],td[class|style]",
|
||||
invalidElements: "script",
|
||||
toolbar1: 'formatselect bold italic forecolor | link unlink',
|
||||
toolbar2: 'alignleft aligncenter alignright alignjustify | bullist numlist blockquote | code mailpoet_shortcodes',
|
||||
validElements: 'p[class|style],span[class|style],a[href|class|title|target|style],h1[class|style],h2[class|style],h3[class|style],ol[class|style],ul[class|style],li[class|style],strong[class|style],em[class|style],strike,br,blockquote[class|style],table[class|style],tr[class|style],th[class|style],td[class|style]',
|
||||
invalidElements: 'script',
|
||||
blockFormats: 'Heading 1=h1;Heading 2=h2;Heading 3=h3;Paragraph=p',
|
||||
plugins: "link lists code textcolor colorpicker mailpoet_shortcodes paste",
|
||||
configurationFilter: function(originalSettings) {
|
||||
plugins: 'link lists code textcolor colorpicker mailpoet_shortcodes paste',
|
||||
configurationFilter: function (originalSettings) {
|
||||
return _.extend({}, originalSettings, {
|
||||
mailpoet_shortcodes: App.getConfig().get('shortcodes').toJSON(),
|
||||
mailpoet_shortcodes_window_title: MailPoet.I18n.t('shortcodesWindowTitle')
|
||||
@ -41,7 +42,7 @@ define([
|
||||
}
|
||||
}
|
||||
}),
|
||||
initialize: function(options) {
|
||||
initialize: function (options) {
|
||||
base.BlockView.prototype.initialize.apply(this, arguments);
|
||||
|
||||
this.renderOptions = _.defaults(options.renderOptions || {}, {
|
||||
@ -50,8 +51,8 @@ define([
|
||||
|
||||
this.disableTextEditor = this.renderOptions.disableTextEditor;
|
||||
},
|
||||
onDragSubstituteBy: function() { return Module.TextWidgetView; },
|
||||
onRender: function() {
|
||||
onDragSubstituteBy: function () { return Module.TextWidgetView; },
|
||||
onRender: function () {
|
||||
this.toolsView = new Module.TextBlockToolsView({
|
||||
model: this.model,
|
||||
tools: {
|
||||
@ -60,40 +61,40 @@ define([
|
||||
});
|
||||
this.showChildView('toolsRegion', this.toolsView);
|
||||
},
|
||||
onTextEditorChange: function(newContent) {
|
||||
onTextEditorChange: function (newContent) {
|
||||
this.model.set('text', newContent);
|
||||
},
|
||||
onTextEditorFocus: function() {
|
||||
onTextEditorFocus: function () {
|
||||
this.disableDragging();
|
||||
this.disableShowingTools();
|
||||
},
|
||||
onTextEditorBlur: function() {
|
||||
onTextEditorBlur: function () {
|
||||
this.enableDragging();
|
||||
this.enableShowingTools();
|
||||
}
|
||||
});
|
||||
|
||||
Module.TextBlockToolsView = base.BlockToolsView.extend({
|
||||
getSettingsView: function() { return Module.TextBlockSettingsView; }
|
||||
getSettingsView: function () { return Module.TextBlockSettingsView; }
|
||||
});
|
||||
|
||||
Module.TextBlockSettingsView = base.BlockSettingsView.extend({
|
||||
getTemplate: function() { return templates.textBlockSettings; }
|
||||
getTemplate: function () { return window.templates.textBlockSettings; }
|
||||
});
|
||||
|
||||
Module.TextWidgetView = base.WidgetView.extend({
|
||||
getTemplate: function() { return templates.textInsertion; },
|
||||
getTemplate: function () { return window.templates.textInsertion; },
|
||||
behaviors: {
|
||||
DraggableBehavior: {
|
||||
cloneOriginal: true,
|
||||
drop: function() {
|
||||
drop: function () {
|
||||
return new Module.TextBlockModel();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
App.on('before:start', function(App, options) {
|
||||
App.on('before:start', function (App) {
|
||||
App.registerBlockType('text', {
|
||||
blockModel: Module.TextBlockModel,
|
||||
blockView: Module.TextBlockView
|
||||
|
@ -6,25 +6,26 @@
|
||||
* Courtesy of https://gist.github.com/jmeas/7992474cdb1c5672d88b
|
||||
*/
|
||||
|
||||
(function(root, factory) {
|
||||
(function (root, factory) {
|
||||
var Marionette = require('backbone.marionette');
|
||||
var Radio = require('backbone.radio');
|
||||
var _ = require('underscore');
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define(['backbone.marionette', 'backbone.radio', 'underscore'], function(Marionette, Radio, _) {
|
||||
define(['backbone.marionette', 'backbone.radio', 'underscore'], function (Marionette, Radio, _) {
|
||||
return factory(Marionette, Radio, _);
|
||||
});
|
||||
}
|
||||
else if (typeof exports !== 'undefined') {
|
||||
var Marionette = require('backbone.marionette');
|
||||
var Radio = require('backbone.radio');
|
||||
var _ = require('underscore');
|
||||
module.exports = factory(Marionette, Radio, _);
|
||||
}
|
||||
else {
|
||||
factory(root.Backbone.Marionette, root.Backbone.Radio, root._);
|
||||
}
|
||||
}(this, function(Marionette, Radio, _) {
|
||||
}(this, function (Marionette, Radio, _) {
|
||||
'use strict';
|
||||
|
||||
Marionette.Application.prototype._initChannel = function () {
|
||||
var MarionetteApplication = Marionette.Application;
|
||||
MarionetteApplication.prototype._initChannel = function () {
|
||||
this.channelName = _.result(this, 'channelName') || 'global';
|
||||
this.channel = _.result(this, 'channel') || Radio.channel(this.channelName);
|
||||
};
|
||||
|
@ -1,13 +1,13 @@
|
||||
define([
|
||||
'newsletter_editor/App',
|
||||
'underscore',
|
||||
'mailpoet',
|
||||
'ajax'
|
||||
], function(App, _, MailPoet) {
|
||||
'newsletter_editor/App',
|
||||
'underscore',
|
||||
'mailpoet',
|
||||
'ajax'
|
||||
], function (App, _, MailPoet) {
|
||||
|
||||
var Module = {};
|
||||
|
||||
Module._query = function(args) {
|
||||
Module._query = function (args) {
|
||||
return MailPoet.Ajax.post({
|
||||
api_version: window.mailpoet_api_version,
|
||||
endpoint: 'automatedLatestContent',
|
||||
@ -17,70 +17,70 @@ define([
|
||||
};
|
||||
Module._cachedQuery = _.memoize(Module._query, JSON.stringify);
|
||||
|
||||
Module.getNewsletter = function(options) {
|
||||
Module.getNewsletter = function (options) {
|
||||
return Module._query({
|
||||
action: 'get',
|
||||
options: options
|
||||
});
|
||||
};
|
||||
|
||||
Module.getPostTypes = function() {
|
||||
Module.getPostTypes = function () {
|
||||
return Module._cachedQuery({
|
||||
action: 'getPostTypes',
|
||||
options: {}
|
||||
}).then(function(response) {
|
||||
}).then(function (response) {
|
||||
return _.values(response.data);
|
||||
});
|
||||
};
|
||||
|
||||
Module.getTaxonomies = function(postType) {
|
||||
Module.getTaxonomies = function (postType) {
|
||||
return Module._cachedQuery({
|
||||
action: 'getTaxonomies',
|
||||
options: {
|
||||
postType: postType
|
||||
}
|
||||
}).then(function(response) {
|
||||
}).then(function (response) {
|
||||
return response.data;
|
||||
});
|
||||
};
|
||||
|
||||
Module.getTerms = function(options) {
|
||||
Module.getTerms = function (options) {
|
||||
return Module._cachedQuery({
|
||||
action: 'getTerms',
|
||||
options: options
|
||||
}).then(function(response) {
|
||||
}).then(function (response) {
|
||||
return response.data;
|
||||
});
|
||||
};
|
||||
|
||||
Module.getPosts = function(options) {
|
||||
Module.getPosts = function (options) {
|
||||
return Module._cachedQuery({
|
||||
action: 'getPosts',
|
||||
options: options
|
||||
}).then(function(response) {
|
||||
}).then(function (response) {
|
||||
return response.data;
|
||||
});
|
||||
};
|
||||
|
||||
Module.getTransformedPosts = function(options) {
|
||||
Module.getTransformedPosts = function (options) {
|
||||
return Module._cachedQuery({
|
||||
action: 'getTransformedPosts',
|
||||
options: options
|
||||
}).then(function(response) {
|
||||
}).then(function (response) {
|
||||
return response.data;
|
||||
});
|
||||
};
|
||||
|
||||
Module.getBulkTransformedPosts = function(options) {
|
||||
Module.getBulkTransformedPosts = function (options) {
|
||||
return Module._query({
|
||||
action: 'getBulkTransformedPosts',
|
||||
options: options
|
||||
}).then(function(response) {
|
||||
}).then(function (response) {
|
||||
return response.data;
|
||||
});
|
||||
};
|
||||
|
||||
Module.saveNewsletter = function(options) {
|
||||
Module.saveNewsletter = function (options) {
|
||||
return MailPoet.Ajax.post({
|
||||
api_version: window.mailpoet_api_version,
|
||||
endpoint: 'newsletters',
|
||||
@ -89,7 +89,7 @@ define([
|
||||
});
|
||||
};
|
||||
|
||||
Module.previewNewsletter = function(options) {
|
||||
Module.previewNewsletter = function (options) {
|
||||
return MailPoet.Ajax.post({
|
||||
api_version: window.mailpoet_api_version,
|
||||
endpoint: 'newsletters',
|
||||
@ -98,7 +98,7 @@ define([
|
||||
});
|
||||
};
|
||||
|
||||
App.on('start', function(App, options) {
|
||||
App.on('start', function () {
|
||||
// Prefetch post types
|
||||
Module.getPostTypes();
|
||||
});
|
||||
|
@ -1,7 +1,7 @@
|
||||
define([
|
||||
'newsletter_editor/App',
|
||||
'backbone.supermodel'
|
||||
], function(App, SuperModel) {
|
||||
'newsletter_editor/App',
|
||||
'backbone.supermodel'
|
||||
], function (App, SuperModel) {
|
||||
|
||||
var Module = {};
|
||||
|
||||
@ -18,18 +18,19 @@ define([
|
||||
|
||||
// Global and available styles for access in blocks and their settings
|
||||
Module._config = {};
|
||||
Module.getConfig = function() { return Module._config; };
|
||||
Module.setConfig = function(options) {
|
||||
Module.getConfig = function () { return Module._config; };
|
||||
Module.setConfig = function (options) {
|
||||
Module._config = new Module.ConfigModel(options, { parse: true });
|
||||
return Module._config;
|
||||
};
|
||||
|
||||
App.on('before:start', function(App, options) {
|
||||
App.on('before:start', function (App, options) {
|
||||
var Application = App;
|
||||
// Expose config methods globally
|
||||
App.getConfig = Module.getConfig;
|
||||
App.setConfig = Module.setConfig;
|
||||
Application.getConfig = Module.getConfig;
|
||||
Application.setConfig = Module.setConfig;
|
||||
|
||||
App.setConfig(options.config);
|
||||
Application.setConfig(options.config);
|
||||
});
|
||||
|
||||
return Module;
|
||||
|
@ -1,10 +1,10 @@
|
||||
define([
|
||||
'newsletter_editor/App',
|
||||
'backbone.supermodel',
|
||||
'underscore',
|
||||
'mailpoet'
|
||||
], function(App, SuperModel, _, MailPoet) {
|
||||
"use strict";
|
||||
'newsletter_editor/App',
|
||||
'backbone.supermodel',
|
||||
'underscore',
|
||||
'mailpoet'
|
||||
], function (App, SuperModel, _, MailPoet) {
|
||||
'use strict';
|
||||
|
||||
var Module = {};
|
||||
|
||||
@ -13,12 +13,12 @@ define([
|
||||
// handled by other components.
|
||||
Module.NewsletterModel = SuperModel.extend({
|
||||
whitelisted: ['id', 'subject', 'preheader'],
|
||||
initialize: function(options) {
|
||||
this.on('change', function() {
|
||||
App.getChannel().trigger('autoSave');
|
||||
initialize: function () {
|
||||
this.on('change', function () {
|
||||
App.getChannel().trigger('autoSave');
|
||||
});
|
||||
},
|
||||
toJSON: function() {
|
||||
toJSON: function () {
|
||||
// Use only whitelisted properties to ensure properties editor
|
||||
// doesn't control don't change.
|
||||
return _.pick(SuperModel.prototype.toJSON.call(this), this.whitelisted);
|
||||
@ -27,47 +27,48 @@ define([
|
||||
|
||||
// Content block view and model handlers for different content types
|
||||
Module._blockTypes = {};
|
||||
Module.registerBlockType = function(type, data) {
|
||||
Module.registerBlockType = function (type, data) {
|
||||
Module._blockTypes[type] = data;
|
||||
};
|
||||
Module.getBlockTypeModel = function(type) {
|
||||
Module.getBlockTypeModel = function (type) {
|
||||
if (type in Module._blockTypes) {
|
||||
return Module._blockTypes[type].blockModel;
|
||||
} else {
|
||||
throw "Block type not supported: " + type;
|
||||
throw 'Block type not supported: ' + type;
|
||||
}
|
||||
};
|
||||
Module.getBlockTypeView = function(type) {
|
||||
Module.getBlockTypeView = function (type) {
|
||||
if (type in Module._blockTypes) {
|
||||
return Module._blockTypes[type].blockView;
|
||||
} else {
|
||||
throw "Block type not supported: " + type;
|
||||
throw 'Block type not supported: ' + type;
|
||||
}
|
||||
};
|
||||
|
||||
Module.getBody = function() {
|
||||
Module.getBody = function () {
|
||||
return {
|
||||
content: App._contentContainer.toJSON(),
|
||||
globalStyles: App.getGlobalStyles().toJSON()
|
||||
};
|
||||
};
|
||||
|
||||
Module.toJSON = function() {
|
||||
Module.toJSON = function () {
|
||||
return _.extend({
|
||||
body: Module.getBody()
|
||||
}, App.getNewsletter().toJSON());
|
||||
};
|
||||
|
||||
Module.getNewsletter = function() {
|
||||
return Module.newsletter;
|
||||
Module.getNewsletter = function () {
|
||||
return Module.newsletter;
|
||||
};
|
||||
|
||||
Module.findModels = function(predicate) {
|
||||
Module.findModels = function (predicate) {
|
||||
var blocks = App._contentContainer.getChildren();
|
||||
return _.filter(blocks, predicate);
|
||||
};
|
||||
|
||||
App.on('before:start', function(App, options) {
|
||||
App.on('before:start', function (Application, options) {
|
||||
var App = Application;
|
||||
// Expose block methods globally
|
||||
App.registerBlockType = Module.registerBlockType;
|
||||
App.getBlockTypeModel = Module.getBlockTypeModel;
|
||||
@ -80,7 +81,8 @@ define([
|
||||
Module.newsletter = new Module.NewsletterModel(_.omit(_.clone(options.newsletter), ['body']));
|
||||
});
|
||||
|
||||
App.on('start', function(App, options) {
|
||||
App.on('start', function (Application, options) {
|
||||
var App = Application;
|
||||
var body = options.newsletter.body;
|
||||
var content = (_.has(body, 'content')) ? body.content : {};
|
||||
|
||||
@ -91,7 +93,7 @@ define([
|
||||
);
|
||||
}
|
||||
|
||||
App._contentContainer = new (App.getBlockTypeModel('container'))(content, {parse: true});
|
||||
App._contentContainer = new (App.getBlockTypeModel('container'))(content, { parse: true });
|
||||
App._contentContainerView = new (App.getBlockTypeView('container'))({
|
||||
model: App._contentContainer,
|
||||
renderOptions: { depth: 0 }
|
||||
|
@ -1,35 +1,45 @@
|
||||
define([
|
||||
'newsletter_editor/App',
|
||||
'backbone',
|
||||
'backbone.marionette',
|
||||
'underscore',
|
||||
'jquery'
|
||||
], function(App, Backbone, Marionette, _, jQuery) {
|
||||
'newsletter_editor/App',
|
||||
'backbone',
|
||||
'backbone.marionette',
|
||||
'underscore',
|
||||
'jquery',
|
||||
'mailpoet'
|
||||
], function (App, Backbone, Marionette, _, jQuery, MailPoet) {
|
||||
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var Module = {};
|
||||
|
||||
Module.HeadingView = Marionette.View.extend({
|
||||
getTemplate: function() { return templates.heading; },
|
||||
templateContext: function() {
|
||||
getTemplate: function () { return window.templates.heading; },
|
||||
templateContext: function () {
|
||||
return {
|
||||
model: this.model.toJSON()
|
||||
};
|
||||
},
|
||||
events: function() {
|
||||
events: function () {
|
||||
return {
|
||||
'keyup .mailpoet_input_title': _.partial(this.changeField, "subject"),
|
||||
'keyup .mailpoet_input_preheader': _.partial(this.changeField, "preheader")
|
||||
'keyup .mailpoet_input_title': _.partial(this.changeField, 'subject'),
|
||||
'keyup .mailpoet_input_preheader': _.partial(this.changeField, 'preheader')
|
||||
};
|
||||
},
|
||||
changeField: function(field, event) {
|
||||
changeField: function (field, event) {
|
||||
this.model.set(field, jQuery(event.target).val());
|
||||
}
|
||||
});
|
||||
|
||||
App.on('start', function(App, options) {
|
||||
App.on('start', function (App) {
|
||||
App._appView.showChildView('headingRegion', new Module.HeadingView({ model: App.getNewsletter() }));
|
||||
MailPoet.helpTooltip.show(document.getElementById('tooltip-designer-subject-line'), {
|
||||
tooltipId: 'tooltip-designer-subject-line-ti',
|
||||
tooltip: MailPoet.I18n.t('helpTooltipDesignerSubjectLine'),
|
||||
place: 'right'
|
||||
});
|
||||
MailPoet.helpTooltip.show(document.getElementById('tooltip-designer-preheader'), {
|
||||
tooltipId: 'tooltip-designer-preheader-ti',
|
||||
tooltip: MailPoet.I18n.t('helpTooltipDesignerPreheader')
|
||||
});
|
||||
});
|
||||
|
||||
return Module;
|
||||
|
@ -1,34 +1,38 @@
|
||||
define([
|
||||
'newsletter_editor/App',
|
||||
'newsletter_editor/components/communication',
|
||||
'mailpoet',
|
||||
'notice',
|
||||
'backbone',
|
||||
'backbone.marionette',
|
||||
'jquery',
|
||||
'blob',
|
||||
'file-saver',
|
||||
'html2canvas'
|
||||
], function(
|
||||
App,
|
||||
CommunicationComponent,
|
||||
MailPoet,
|
||||
Notice,
|
||||
Backbone,
|
||||
Marionette,
|
||||
jQuery,
|
||||
Blob,
|
||||
FileSaver,
|
||||
html2canvas
|
||||
) {
|
||||
'newsletter_editor/App',
|
||||
'newsletter_editor/components/communication',
|
||||
'mailpoet',
|
||||
'notice',
|
||||
'backbone',
|
||||
'backbone.marionette',
|
||||
'jquery',
|
||||
'blob',
|
||||
'file-saver',
|
||||
'html2canvas',
|
||||
'underscore',
|
||||
'jquery'
|
||||
], function (
|
||||
App,
|
||||
CommunicationComponent,
|
||||
MailPoet,
|
||||
Notice,
|
||||
Backbone,
|
||||
Marionette,
|
||||
jQuery,
|
||||
Blob,
|
||||
FileSaver,
|
||||
html2canvas,
|
||||
_,
|
||||
$
|
||||
) {
|
||||
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var Module = {},
|
||||
saveTimeout;
|
||||
var Module = {};
|
||||
var saveTimeout;
|
||||
|
||||
// Save editor contents to server
|
||||
Module.save = function() {
|
||||
Module.save = function () {
|
||||
|
||||
var json = App.toJSON();
|
||||
|
||||
@ -40,12 +44,12 @@ define([
|
||||
App.getChannel().trigger('beforeEditorSave', json);
|
||||
|
||||
// save newsletter
|
||||
return CommunicationComponent.saveNewsletter(json).done(function(response) {
|
||||
if(response.success !== undefined && response.success === true) {
|
||||
return CommunicationComponent.saveNewsletter(json).done(function (response) {
|
||||
if (response.success !== undefined && response.success === true) {
|
||||
// TODO: Handle translations
|
||||
//MailPoet.Notice.success("<?php _e('Newsletter has been saved.'); ?>");
|
||||
} else if(response.error !== undefined) {
|
||||
if(response.error.length === 0) {
|
||||
// MailPoet.Notice.success("<?php _e('Newsletter has been saved.'); ?>");
|
||||
} else if (response.error !== undefined) {
|
||||
if (response.error.length === 0) {
|
||||
MailPoet.Notice.error(
|
||||
MailPoet.I18n.t('templateSaveFailed'),
|
||||
{
|
||||
@ -53,37 +57,28 @@ define([
|
||||
}
|
||||
);
|
||||
} else {
|
||||
$(response.error).each(function(i, error) {
|
||||
$(response.error).each(function (i, error) {
|
||||
MailPoet.Notice.error(error, { scroll: true });
|
||||
});
|
||||
}
|
||||
}
|
||||
App.getChannel().trigger('afterEditorSave', json, response);
|
||||
}).fail(function(response) {
|
||||
}).fail(function (response) {
|
||||
// TODO: Handle saving errors
|
||||
App.getChannel().trigger('afterEditorSave', {}, response);
|
||||
});
|
||||
};
|
||||
|
||||
// For getting a promise after triggering save event
|
||||
Module.saveAndProvidePromise = function(saveResult) {
|
||||
var promise = Module.save();
|
||||
if (saveResult !== undefined) {
|
||||
saveResult.promise = promise;
|
||||
}
|
||||
};
|
||||
|
||||
Module.getThumbnail = function(element, options) {
|
||||
Module.getThumbnail = function (element, options) {
|
||||
var promise = html2canvas(element, options || {});
|
||||
|
||||
return promise.then(function(oldCanvas) {
|
||||
return promise.then(function (oldCanvas) {
|
||||
// Temporary workaround for html2canvas-alpha2.
|
||||
// Removes 1px left transparent border from resulting canvas.
|
||||
|
||||
var oldContext = oldCanvas.getContext('2d'),
|
||||
newCanvas = document.createElement("canvas"),
|
||||
newContext = newCanvas.getContext("2d"),
|
||||
leftBorderWidth = 1;
|
||||
var newCanvas = document.createElement('canvas');
|
||||
var newContext = newCanvas.getContext('2d');
|
||||
var leftBorderWidth = 1;
|
||||
|
||||
newCanvas.width = oldCanvas.width;
|
||||
newCanvas.height = oldCanvas.height;
|
||||
@ -98,11 +93,10 @@ define([
|
||||
});
|
||||
};
|
||||
|
||||
Module.saveTemplate = function(options) {
|
||||
var that = this,
|
||||
promise = jQuery.Deferred();
|
||||
Module.saveTemplate = function (options) {
|
||||
var promise = jQuery.Deferred();
|
||||
|
||||
promise.then(function(thumbnail) {
|
||||
promise.then(function (thumbnail) {
|
||||
var data = _.extend(options || {}, {
|
||||
thumbnail: thumbnail.toDataURL('image/jpeg'),
|
||||
body: JSON.stringify(App.getBody())
|
||||
@ -118,18 +112,17 @@ define([
|
||||
|
||||
Module.getThumbnail(
|
||||
jQuery('#mailpoet_editor_content > .mailpoet_block').get(0)
|
||||
).then(function(thumbnail) {
|
||||
).then(function (thumbnail) {
|
||||
promise.resolve(thumbnail);
|
||||
});
|
||||
|
||||
return promise;
|
||||
};
|
||||
|
||||
Module.exportTemplate = function(options) {
|
||||
var that = this;
|
||||
Module.exportTemplate = function (options) {
|
||||
return Module.getThumbnail(
|
||||
jQuery('#mailpoet_editor_content > .mailpoet_block').get(0)
|
||||
).then(function(thumbnail) {
|
||||
).then(function (thumbnail) {
|
||||
var data = _.extend(options || {}, {
|
||||
thumbnail: thumbnail.toDataURL('image/jpeg'),
|
||||
body: App.getBody()
|
||||
@ -140,11 +133,14 @@ define([
|
||||
);
|
||||
|
||||
FileSaver.saveAs(blob, 'template.json');
|
||||
MailPoet.trackEvent('Editor > Template exported', {
|
||||
'MailPoet Free version': window.mailpoet_version
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Module.SaveView = Marionette.View.extend({
|
||||
getTemplate: function() { return templates.save; },
|
||||
getTemplate: function () { return window.templates.save; },
|
||||
events: {
|
||||
'click .mailpoet_save_button': 'save',
|
||||
'click .mailpoet_save_show_options': 'toggleSaveOptions',
|
||||
@ -156,46 +152,46 @@ define([
|
||||
'click .mailpoet_save_export': 'toggleExportTemplate',
|
||||
'click .mailpoet_export_template': 'exportTemplate'
|
||||
},
|
||||
initialize: function(options) {
|
||||
initialize: function () {
|
||||
App.getChannel().on('beforeEditorSave', this.beforeSave, this);
|
||||
App.getChannel().on('afterEditorSave', this.afterSave, this);
|
||||
},
|
||||
onRender: function() {
|
||||
onRender: function () {
|
||||
this.validateNewsletter(App.toJSON());
|
||||
},
|
||||
save: function() {
|
||||
save: function () {
|
||||
this.hideOptionContents();
|
||||
App.getChannel().trigger('save');
|
||||
App.getChannel().request('save');
|
||||
},
|
||||
beforeSave: function() {
|
||||
beforeSave: function () {
|
||||
// TODO: Add a loading animation instead
|
||||
this.$('.mailpoet_autosaved_at').text(MailPoet.I18n.t('saving'));
|
||||
},
|
||||
afterSave: function(json, response) {
|
||||
afterSave: function (json) {
|
||||
this.validateNewsletter(json);
|
||||
// Update 'Last saved timer'
|
||||
this.$('.mailpoet_editor_last_saved').removeClass('mailpoet_hidden');
|
||||
this.$('.mailpoet_autosaved_at').text('');
|
||||
},
|
||||
toggleSaveOptions: function() {
|
||||
toggleSaveOptions: function () {
|
||||
this.$('.mailpoet_save_options').toggleClass('mailpoet_hidden');
|
||||
this.$('.mailpoet_save_show_options').toggleClass('mailpoet_save_show_options_active');
|
||||
},
|
||||
toggleSaveAsTemplate: function() {
|
||||
toggleSaveAsTemplate: function () {
|
||||
this.$('.mailpoet_save_as_template_container').toggleClass('mailpoet_hidden');
|
||||
this.toggleSaveOptions();
|
||||
},
|
||||
showSaveAsTemplate: function() {
|
||||
showSaveAsTemplate: function () {
|
||||
this.$('.mailpoet_save_as_template_container').removeClass('mailpoet_hidden');
|
||||
this.toggleSaveOptions();
|
||||
},
|
||||
hideSaveAsTemplate: function() {
|
||||
hideSaveAsTemplate: function () {
|
||||
this.$('.mailpoet_save_as_template_container').addClass('mailpoet_hidden');
|
||||
},
|
||||
saveAsTemplate: function() {
|
||||
var templateName = this.$('.mailpoet_save_as_template_name').val(),
|
||||
templateDescription = this.$('.mailpoet_save_as_template_description').val(),
|
||||
that = this;
|
||||
saveAsTemplate: function () {
|
||||
var templateName = this.$('.mailpoet_save_as_template_name').val();
|
||||
var templateDescription = this.$('.mailpoet_save_as_template_description').val();
|
||||
var that = this;
|
||||
|
||||
if (templateName === '') {
|
||||
MailPoet.Notice.error(
|
||||
@ -217,7 +213,7 @@ define([
|
||||
Module.saveTemplate({
|
||||
name: templateName,
|
||||
description: templateDescription
|
||||
}).done(function() {
|
||||
}).done(function () {
|
||||
MailPoet.Notice.success(
|
||||
MailPoet.I18n.t('templateSaved'),
|
||||
{
|
||||
@ -225,7 +221,10 @@ define([
|
||||
scroll: true
|
||||
}
|
||||
);
|
||||
}).fail(function() {
|
||||
MailPoet.trackEvent('Editor > Template saved', {
|
||||
'MailPoet Free version': window.mailpoet_version
|
||||
});
|
||||
}).fail(function () {
|
||||
MailPoet.Notice.error(
|
||||
MailPoet.I18n.t('templateSaveFailed'),
|
||||
{
|
||||
@ -238,17 +237,17 @@ define([
|
||||
}
|
||||
|
||||
},
|
||||
toggleExportTemplate: function() {
|
||||
toggleExportTemplate: function () {
|
||||
this.$('.mailpoet_export_template_container').toggleClass('mailpoet_hidden');
|
||||
this.toggleSaveOptions();
|
||||
},
|
||||
hideExportTemplate: function() {
|
||||
hideExportTemplate: function () {
|
||||
this.$('.mailpoet_export_template_container').addClass('mailpoet_hidden');
|
||||
},
|
||||
exportTemplate: function() {
|
||||
var templateName = this.$('.mailpoet_export_template_name').val(),
|
||||
templateDescription = this.$('.mailpoet_export_template_description').val(),
|
||||
that = this;
|
||||
exportTemplate: function () {
|
||||
var templateName = this.$('.mailpoet_export_template_name').val();
|
||||
var templateDescription = this.$('.mailpoet_export_template_description').val();
|
||||
var that = this;
|
||||
|
||||
if (templateName === '') {
|
||||
MailPoet.Notice.error(
|
||||
@ -274,83 +273,96 @@ define([
|
||||
this.hideExportTemplate();
|
||||
}
|
||||
},
|
||||
hideOptionContents: function() {
|
||||
hideOptionContents: function () {
|
||||
this.hideSaveAsTemplate();
|
||||
this.hideExportTemplate();
|
||||
this.$('.mailpoet_save_options').addClass('mailpoet_hidden');
|
||||
},
|
||||
next: function() {
|
||||
next: function () {
|
||||
this.hideOptionContents();
|
||||
if(!this.$('.mailpoet_save_next').hasClass('button-disabled')) {
|
||||
window.location.href = App.getConfig().get('urls.send');
|
||||
if (!this.$('.mailpoet_save_next').hasClass('button-disabled')) {
|
||||
Module._cancelAutosave();
|
||||
Module.save().done(function () {
|
||||
window.location.href = App.getConfig().get('urls.send');
|
||||
});
|
||||
}
|
||||
},
|
||||
validateNewsletter: function(jsonObject) {
|
||||
validateNewsletter: function (jsonObject) {
|
||||
var contents;
|
||||
if (!App._contentContainer.isValid()) {
|
||||
this.showValidationError(App._contentContainer.validationError);
|
||||
return;
|
||||
}
|
||||
|
||||
var contents = JSON.stringify(jsonObject);
|
||||
contents = JSON.stringify(jsonObject);
|
||||
if (App.getConfig().get('validation.validateUnsubscribeLinkPresent') &&
|
||||
contents.indexOf("[link:subscription_unsubscribe_url]") < 0 &&
|
||||
contents.indexOf("[link:subscription_unsubscribe]") < 0) {
|
||||
contents.indexOf('[link:subscription_unsubscribe_url]') < 0 &&
|
||||
contents.indexOf('[link:subscription_unsubscribe]') < 0) {
|
||||
this.showValidationError(MailPoet.I18n.t('unsubscribeLinkMissing'));
|
||||
return;
|
||||
}
|
||||
|
||||
this.hideValidationError();
|
||||
},
|
||||
showValidationError: function(message) {
|
||||
showValidationError: function (message) {
|
||||
var $el = this.$('.mailpoet_save_error');
|
||||
$el.text(message);
|
||||
$el.removeClass('mailpoet_hidden');
|
||||
|
||||
this.$('.mailpoet_save_next').addClass('button-disabled');
|
||||
},
|
||||
hideValidationError: function() {
|
||||
hideValidationError: function () {
|
||||
this.$('.mailpoet_save_error').addClass('mailpoet_hidden');
|
||||
this.$('.mailpoet_save_next').removeClass('button-disabled');
|
||||
}
|
||||
});
|
||||
|
||||
Module.autoSave = function() {
|
||||
Module.autoSave = function () {
|
||||
// Delay in saving editor contents, during which a new autosave
|
||||
// may be requested
|
||||
var AUTOSAVE_DELAY_DURATION = 1000;
|
||||
|
||||
// Cancel save timer if another change happens before it completes
|
||||
if (saveTimeout) clearTimeout(saveTimeout);
|
||||
saveTimeout = setTimeout(function() {
|
||||
App.getChannel().trigger('save');
|
||||
clearTimeout(saveTimeout);
|
||||
saveTimeout = undefined;
|
||||
Module._cancelAutosave();
|
||||
saveTimeout = setTimeout(function () {
|
||||
App.getChannel().request('save').always(function () {
|
||||
Module._cancelAutosave();
|
||||
});
|
||||
}, AUTOSAVE_DELAY_DURATION);
|
||||
};
|
||||
|
||||
Module.beforeExitWithUnsavedChanges = function(e) {
|
||||
if (saveTimeout) {
|
||||
var message = MailPoet.I18n.t('unsavedChangesWillBeLost');
|
||||
e = e || window.event;
|
||||
Module._cancelAutosave = function () {
|
||||
if (!saveTimeout) return;
|
||||
|
||||
if (e) {
|
||||
e.returnValue = message;
|
||||
clearTimeout(saveTimeout);
|
||||
saveTimeout = undefined;
|
||||
};
|
||||
|
||||
Module.beforeExitWithUnsavedChanges = function (e) {
|
||||
var message;
|
||||
var event;
|
||||
if (saveTimeout) {
|
||||
message = MailPoet.I18n.t('unsavedChangesWillBeLost');
|
||||
event = e || window.event;
|
||||
|
||||
if (event) {
|
||||
event.returnValue = message;
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
};
|
||||
|
||||
App.on('before:start', function(App, options) {
|
||||
App.save = Module.saveAndProvidePromise;
|
||||
App.getChannel().on('autoSave', Module.autoSave);
|
||||
App.on('before:start', function (App) {
|
||||
var Application = App;
|
||||
Application.save = Module.save;
|
||||
Application.getChannel().on('autoSave', Module.autoSave);
|
||||
|
||||
window.onbeforeunload = Module.beforeExitWithUnsavedChanges;
|
||||
|
||||
App.getChannel().on('save', function(saveResult) { App.save(saveResult); });
|
||||
Application.getChannel().reply('save', Application.save);
|
||||
});
|
||||
|
||||
App.on('start', function(App, options) {
|
||||
App.on('start', function (App) {
|
||||
var saveView = new Module.SaveView();
|
||||
App._appView.showChildView('bottomRegion', saveView);
|
||||
});
|
||||
|
@ -1,29 +1,27 @@
|
||||
define([
|
||||
'newsletter_editor/App',
|
||||
'newsletter_editor/components/communication',
|
||||
'mailpoet',
|
||||
'backbone',
|
||||
'backbone.marionette',
|
||||
'backbone.supermodel',
|
||||
'underscore',
|
||||
'jquery',
|
||||
'sticky-kit'
|
||||
], function(
|
||||
App,
|
||||
CommunicationComponent,
|
||||
MailPoet,
|
||||
Backbone,
|
||||
Marionette,
|
||||
SuperModel,
|
||||
_,
|
||||
jQuery,
|
||||
StickyKit
|
||||
'newsletter_editor/App',
|
||||
'newsletter_editor/components/communication',
|
||||
'mailpoet',
|
||||
'backbone',
|
||||
'backbone.marionette',
|
||||
'backbone.supermodel',
|
||||
'underscore',
|
||||
'jquery'
|
||||
], function (
|
||||
App,
|
||||
CommunicationComponent,
|
||||
MailPoet,
|
||||
Backbone,
|
||||
Marionette,
|
||||
SuperModel,
|
||||
_,
|
||||
jQuery
|
||||
) {
|
||||
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var Module = {};
|
||||
|
||||
var SidebarView;
|
||||
// Widget handlers for use to create new content blocks via drag&drop
|
||||
Module._contentWidgets = new (Backbone.Collection.extend({
|
||||
model: SuperModel.extend({
|
||||
@ -35,8 +33,8 @@ define([
|
||||
}),
|
||||
comparator: 'priority'
|
||||
}))();
|
||||
Module.registerWidget = function(widget) { return Module._contentWidgets.add(widget); };
|
||||
Module.getWidgets = function() { return Module._contentWidgets; };
|
||||
Module.registerWidget = function (widget) { return Module._contentWidgets.add(widget); };
|
||||
Module.getWidgets = function () { return Module._contentWidgets; };
|
||||
|
||||
// Layout widget handlers for use to create new layout blocks via drag&drop
|
||||
Module._layoutWidgets = new (Backbone.Collection.extend({
|
||||
@ -49,11 +47,11 @@ define([
|
||||
}),
|
||||
comparator: 'priority'
|
||||
}))();
|
||||
Module.registerLayoutWidget = function(widget) { return Module._layoutWidgets.add(widget); };
|
||||
Module.getLayoutWidgets = function() { return Module._layoutWidgets; };
|
||||
Module.registerLayoutWidget = function (widget) { return Module._layoutWidgets.add(widget); };
|
||||
Module.getLayoutWidgets = function () { return Module._layoutWidgets; };
|
||||
|
||||
var SidebarView = Marionette.View.extend({
|
||||
getTemplate: function() { return templates.sidebar; },
|
||||
SidebarView = Marionette.View.extend({
|
||||
getTemplate: function () { return window.templates.sidebar; },
|
||||
regions: {
|
||||
contentRegion: '.mailpoet_content_region',
|
||||
layoutRegion: '.mailpoet_layout_region',
|
||||
@ -61,16 +59,16 @@ define([
|
||||
previewRegion: '.mailpoet_preview_region'
|
||||
},
|
||||
events: {
|
||||
'click .mailpoet_sidebar_region h3, .mailpoet_sidebar_region .handlediv': function(event) {
|
||||
var $openRegion = this.$el.find('.mailpoet_sidebar_region:not(.closed)'),
|
||||
$targetRegion = this.$el.find(event.target).closest('.mailpoet_sidebar_region');
|
||||
'click .mailpoet_sidebar_region h3, .mailpoet_sidebar_region .handlediv': function (event) {
|
||||
var $openRegion = this.$el.find('.mailpoet_sidebar_region:not(.closed)');
|
||||
var $targetRegion = this.$el.find(event.target).closest('.mailpoet_sidebar_region');
|
||||
|
||||
$openRegion.find('.mailpoet_region_content').velocity(
|
||||
'slideUp',
|
||||
{
|
||||
duration: 250,
|
||||
easing: "easeOut",
|
||||
complete: function() {
|
||||
easing: 'easeOut',
|
||||
complete: function () {
|
||||
$openRegion.addClass('closed');
|
||||
}.bind(this)
|
||||
}
|
||||
@ -81,8 +79,8 @@ define([
|
||||
'slideDown',
|
||||
{
|
||||
duration: 250,
|
||||
easing: "easeIn",
|
||||
complete: function() {
|
||||
easing: 'easeIn',
|
||||
complete: function () {
|
||||
$targetRegion.removeClass('closed');
|
||||
}
|
||||
}
|
||||
@ -90,12 +88,12 @@ define([
|
||||
}
|
||||
}
|
||||
},
|
||||
initialize: function(options) {
|
||||
initialize: function () {
|
||||
jQuery(window)
|
||||
.on('resize', this.updateHorizontalScroll.bind(this))
|
||||
.on('scroll', this.updateHorizontalScroll.bind(this));
|
||||
},
|
||||
onRender: function() {
|
||||
onRender: function () {
|
||||
this.showChildView('contentRegion', new Module.SidebarWidgetsView(
|
||||
App.getWidgets()
|
||||
));
|
||||
@ -108,14 +106,13 @@ define([
|
||||
}));
|
||||
this.showChildView('previewRegion', new Module.SidebarPreviewView());
|
||||
},
|
||||
updateHorizontalScroll: function() {
|
||||
updateHorizontalScroll: function () {
|
||||
// Fixes the sidebar so that on narrower screens the horizontal
|
||||
// position of the sidebar would be scrollable and not fixed
|
||||
// partially out of visible screen
|
||||
this.$el.parent().each(function () {
|
||||
var calculated_left, self;
|
||||
|
||||
self = jQuery(this);
|
||||
var calculated_left;
|
||||
var self = jQuery(this);
|
||||
|
||||
if (self.css('position') === 'fixed') {
|
||||
calculated_left = self.parent().offset().left - jQuery(window).scrollLeft();
|
||||
@ -125,7 +122,7 @@ define([
|
||||
}
|
||||
});
|
||||
},
|
||||
onDomRefresh: function() {
|
||||
onDomRefresh: function () {
|
||||
this.$el.parent().stick_in_parent({
|
||||
offset_top: 32
|
||||
});
|
||||
@ -140,23 +137,23 @@ define([
|
||||
* Draggable widget collection view
|
||||
*/
|
||||
Module.SidebarWidgetsCollectionView = Marionette.CollectionView.extend({
|
||||
childView: function(item) { return item.get('widgetView'); }
|
||||
childView: function (item) { return item.get('widgetView'); }
|
||||
});
|
||||
|
||||
/**
|
||||
* Responsible for rendering draggable content widgets
|
||||
*/
|
||||
Module.SidebarWidgetsView = Marionette.View.extend({
|
||||
getTemplate: function() { return templates.sidebarContent; },
|
||||
getTemplate: function () { return window.templates.sidebarContent; },
|
||||
regions: {
|
||||
widgets: '.mailpoet_region_content'
|
||||
},
|
||||
|
||||
initialize: function(widgets) {
|
||||
initialize: function (widgets) {
|
||||
this.widgets = widgets;
|
||||
},
|
||||
|
||||
onRender: function() {
|
||||
onRender: function () {
|
||||
this.showChildView('widgets', new Module.SidebarWidgetsCollectionView({
|
||||
collection: this.widgets
|
||||
}));
|
||||
@ -167,68 +164,68 @@ define([
|
||||
* Responsible for rendering draggable layout widgets
|
||||
*/
|
||||
Module.SidebarLayoutWidgetsView = Module.SidebarWidgetsView.extend({
|
||||
getTemplate: function() { return templates.sidebarLayout; }
|
||||
getTemplate: function () { return window.templates.sidebarLayout; }
|
||||
});
|
||||
|
||||
/**
|
||||
* Responsible for managing global styles
|
||||
*/
|
||||
Module.SidebarStylesView = Marionette.View.extend({
|
||||
getTemplate: function() { return templates.sidebarStyles; },
|
||||
getTemplate: function () { return window.templates.sidebarStyles; },
|
||||
behaviors: {
|
||||
ColorPickerBehavior: {}
|
||||
},
|
||||
events: function() {
|
||||
events: function () {
|
||||
return {
|
||||
"change #mailpoet_text_font_color": _.partial(this.changeColorField, 'text.fontColor'),
|
||||
"change #mailpoet_text_font_family": function(event) {
|
||||
'change #mailpoet_text_font_color': _.partial(this.changeColorField, 'text.fontColor'),
|
||||
'change #mailpoet_text_font_family': function (event) {
|
||||
this.model.set('text.fontFamily', event.target.value);
|
||||
},
|
||||
"change #mailpoet_text_font_size": function(event) {
|
||||
'change #mailpoet_text_font_size': function (event) {
|
||||
this.model.set('text.fontSize', event.target.value);
|
||||
},
|
||||
"change #mailpoet_h1_font_color": _.partial(this.changeColorField, 'h1.fontColor'),
|
||||
"change #mailpoet_h1_font_family": function(event) {
|
||||
'change #mailpoet_h1_font_color': _.partial(this.changeColorField, 'h1.fontColor'),
|
||||
'change #mailpoet_h1_font_family': function (event) {
|
||||
this.model.set('h1.fontFamily', event.target.value);
|
||||
},
|
||||
"change #mailpoet_h1_font_size": function(event) {
|
||||
'change #mailpoet_h1_font_size': function (event) {
|
||||
this.model.set('h1.fontSize', event.target.value);
|
||||
},
|
||||
"change #mailpoet_h2_font_color": _.partial(this.changeColorField, 'h2.fontColor'),
|
||||
"change #mailpoet_h2_font_family": function(event) {
|
||||
'change #mailpoet_h2_font_color': _.partial(this.changeColorField, 'h2.fontColor'),
|
||||
'change #mailpoet_h2_font_family': function (event) {
|
||||
this.model.set('h2.fontFamily', event.target.value);
|
||||
},
|
||||
"change #mailpoet_h2_font_size": function(event) {
|
||||
'change #mailpoet_h2_font_size': function (event) {
|
||||
this.model.set('h2.fontSize', event.target.value);
|
||||
},
|
||||
"change #mailpoet_h3_font_color": _.partial(this.changeColorField, 'h3.fontColor'),
|
||||
"change #mailpoet_h3_font_family": function(event) {
|
||||
'change #mailpoet_h3_font_color': _.partial(this.changeColorField, 'h3.fontColor'),
|
||||
'change #mailpoet_h3_font_family': function (event) {
|
||||
this.model.set('h3.fontFamily', event.target.value);
|
||||
},
|
||||
"change #mailpoet_h3_font_size": function(event) {
|
||||
'change #mailpoet_h3_font_size': function (event) {
|
||||
this.model.set('h3.fontSize', event.target.value);
|
||||
},
|
||||
"change #mailpoet_a_font_color": _.partial(this.changeColorField, 'link.fontColor'),
|
||||
"change #mailpoet_a_font_underline": function(event) {
|
||||
'change #mailpoet_a_font_color': _.partial(this.changeColorField, 'link.fontColor'),
|
||||
'change #mailpoet_a_font_underline': function (event) {
|
||||
this.model.set('link.textDecoration', (event.target.checked) ? event.target.value : 'none');
|
||||
},
|
||||
"change #mailpoet_newsletter_background_color": _.partial(this.changeColorField, 'wrapper.backgroundColor'),
|
||||
"change #mailpoet_background_color": _.partial(this.changeColorField, 'body.backgroundColor')
|
||||
'change #mailpoet_newsletter_background_color': _.partial(this.changeColorField, 'wrapper.backgroundColor'),
|
||||
'change #mailpoet_background_color': _.partial(this.changeColorField, 'body.backgroundColor')
|
||||
};
|
||||
},
|
||||
templateContext: function() {
|
||||
templateContext: function () {
|
||||
return {
|
||||
model: this.model.toJSON(),
|
||||
availableStyles: this.availableStyles.toJSON()
|
||||
};
|
||||
},
|
||||
initialize: function(options) {
|
||||
initialize: function (options) {
|
||||
this.availableStyles = options.availableStyles;
|
||||
},
|
||||
changeField: function(field, event) {
|
||||
changeField: function (field, event) {
|
||||
this.model.set(field, jQuery(event.target).val());
|
||||
},
|
||||
changeColorField: function(field, event) {
|
||||
changeColorField: function (field, event) {
|
||||
var value = jQuery(event.target).val();
|
||||
if (value === '') {
|
||||
value = 'transparent';
|
||||
@ -238,18 +235,18 @@ define([
|
||||
});
|
||||
|
||||
Module.SidebarPreviewView = Marionette.View.extend({
|
||||
getTemplate: function() { return templates.sidebarPreview; },
|
||||
getTemplate: function () { return window.templates.sidebarPreview; },
|
||||
events: {
|
||||
'click .mailpoet_show_preview': 'showPreview',
|
||||
'click #mailpoet_send_preview': 'sendPreview'
|
||||
},
|
||||
onBeforeDestroy: function() {
|
||||
onBeforeDestroy: function () {
|
||||
if (this.previewView) {
|
||||
this.previewView.destroy();
|
||||
this.previewView = null;
|
||||
}
|
||||
},
|
||||
showPreview: function() {
|
||||
showPreview: function () {
|
||||
var json = App.toJSON();
|
||||
|
||||
// Stringify to enable transmission of primitive non-string value types
|
||||
@ -264,34 +261,41 @@ define([
|
||||
endpoint: 'newsletters',
|
||||
action: 'showPreview',
|
||||
data: json
|
||||
}).always(function() {
|
||||
}).always(function () {
|
||||
MailPoet.Modal.loading(false);
|
||||
}).done(function(response) {
|
||||
}).done(function (response) {
|
||||
this.previewView = new Module.NewsletterPreviewView({
|
||||
previewUrl: response.meta.preview_url
|
||||
});
|
||||
|
||||
var view = this.previewView.render();
|
||||
this.previewView.render();
|
||||
this.previewView.$el.css('height', '100%');
|
||||
|
||||
MailPoet.Modal.popup({
|
||||
template: '',
|
||||
element: this.previewView.$el,
|
||||
width: '95%',
|
||||
height: '94%',
|
||||
title: MailPoet.I18n.t('newsletterPreview'),
|
||||
onCancel: function() {
|
||||
onCancel: function () {
|
||||
this.previewView.destroy();
|
||||
this.previewView = null;
|
||||
}.bind(this)
|
||||
});
|
||||
}.bind(this)).fail(function(response) {
|
||||
|
||||
MailPoet.trackEvent('Editor > Browser Preview', {
|
||||
'MailPoet Free version': window.mailpoet_version
|
||||
});
|
||||
}.bind(this)).fail(function (response) {
|
||||
if (response.errors.length > 0) {
|
||||
MailPoet.Notice.error(
|
||||
response.errors.map(function(error) { return error.message; }),
|
||||
response.errors.map(function (error) { return error.message; }),
|
||||
{ scroll: true }
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
sendPreview: function() {
|
||||
sendPreview: function () {
|
||||
// get form data
|
||||
var $emailField = this.$('#mailpoet_preview_to_email');
|
||||
var data = {
|
||||
@ -314,20 +318,22 @@ define([
|
||||
MailPoet.Modal.loading(true);
|
||||
|
||||
// save before sending
|
||||
var saveResult = {promise: null};
|
||||
App.getChannel().trigger('save', saveResult);
|
||||
|
||||
saveResult.promise.always(function() {
|
||||
CommunicationComponent.previewNewsletter(data).always(function() {
|
||||
App.getChannel().request('save').always(function () {
|
||||
CommunicationComponent.previewNewsletter(data).always(function () {
|
||||
MailPoet.Modal.loading(false);
|
||||
}).done(function(response) {
|
||||
}).done(function () {
|
||||
MailPoet.Notice.success(
|
||||
MailPoet.I18n.t('newsletterPreviewSent'),
|
||||
{ scroll: true });
|
||||
}).fail(function(response) {
|
||||
{ scroll: true }
|
||||
);
|
||||
MailPoet.trackEvent('Editor > Preview sent', {
|
||||
'MailPoet Free version': window.mailpoet_version,
|
||||
'Domain name': data.subscriber.substring(data.subscriber.indexOf('@') + 1)
|
||||
});
|
||||
}).fail(function (response) {
|
||||
if (response.errors.length > 0) {
|
||||
MailPoet.Notice.error(
|
||||
response.errors.map(function(error) { return error.message; }),
|
||||
response.errors.map(function (error) { return error.message; }),
|
||||
{ scroll: true, static: true }
|
||||
);
|
||||
}
|
||||
@ -337,13 +343,15 @@ define([
|
||||
});
|
||||
|
||||
Module.NewsletterPreviewView = Marionette.View.extend({
|
||||
getTemplate: function() { return templates.newsletterPreview; },
|
||||
initialize: function(options) {
|
||||
getTemplate: function () { return window.templates.newsletterPreview; },
|
||||
initialize: function (options) {
|
||||
this.previewUrl = options.previewUrl;
|
||||
this.width = App.getConfig().get('newsletterPreview.width');
|
||||
this.height = App.getConfig().get('newsletterPreview.height')
|
||||
this.width = '100%';
|
||||
this.height = '100%';
|
||||
// this.width = App.getConfig().get('newsletterPreview.width');
|
||||
// this.height = App.getConfig().get('newsletterPreview.height')
|
||||
},
|
||||
templateContext: function() {
|
||||
templateContext: function () {
|
||||
return {
|
||||
previewUrl: this.previewUrl,
|
||||
width: this.width,
|
||||
@ -352,18 +360,28 @@ define([
|
||||
}
|
||||
});
|
||||
|
||||
App.on('before:start', function(App, options) {
|
||||
App.registerWidget = Module.registerWidget;
|
||||
App.getWidgets = Module.getWidgets;
|
||||
App.registerLayoutWidget = Module.registerLayoutWidget;
|
||||
App.getLayoutWidgets = Module.getLayoutWidgets;
|
||||
App.on('before:start', function (App) {
|
||||
var Application = App;
|
||||
Application.registerWidget = Module.registerWidget;
|
||||
Application.getWidgets = Module.getWidgets;
|
||||
Application.registerLayoutWidget = Module.registerLayoutWidget;
|
||||
Application.getLayoutWidgets = Module.getLayoutWidgets;
|
||||
});
|
||||
|
||||
App.on('start', function(App, options) {
|
||||
var stylesModel = App.getGlobalStyles(),
|
||||
sidebarView = new SidebarView();
|
||||
App.on('start', function (App) {
|
||||
var sidebarView = new SidebarView();
|
||||
|
||||
App._appView.showChildView('sidebarRegion', sidebarView);
|
||||
|
||||
MailPoet.helpTooltip.show(document.getElementById('tooltip-send-preview'), {
|
||||
tooltipId: 'tooltip-editor-send-preview',
|
||||
tooltip: MailPoet.I18n.t('helpTooltipSendPreview')
|
||||
});
|
||||
|
||||
MailPoet.helpTooltip.show(document.getElementById('tooltip-designer-styles'), {
|
||||
tooltipId: 'tooltip-editor-designer-styles',
|
||||
tooltip: MailPoet.I18n.t('helpTooltipDesignerStyles')
|
||||
});
|
||||
});
|
||||
|
||||
return Module;
|
||||
|
@ -1,10 +1,11 @@
|
||||
define([
|
||||
'newsletter_editor/App',
|
||||
'backbone.marionette',
|
||||
'backbone.supermodel'
|
||||
], function(App, Marionette, SuperModel) {
|
||||
'newsletter_editor/App',
|
||||
'backbone.marionette',
|
||||
'backbone.supermodel',
|
||||
'underscore'
|
||||
], function (App, Marionette, SuperModel, _) {
|
||||
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var Module = {};
|
||||
|
||||
@ -41,45 +42,48 @@ define([
|
||||
backgroundColor: '#cccccc'
|
||||
}
|
||||
},
|
||||
initialize: function() {
|
||||
this.on('change', function() { App.getChannel().trigger('autoSave'); });
|
||||
initialize: function () {
|
||||
this.on('change', function () { App.getChannel().trigger('autoSave'); });
|
||||
}
|
||||
});
|
||||
|
||||
Module.StylesView = Marionette.View.extend({
|
||||
getTemplate: function() { return templates.styles; },
|
||||
getTemplate: function () { return window.templates.styles; },
|
||||
modelEvents: {
|
||||
'change': 'render'
|
||||
change: 'render'
|
||||
},
|
||||
serializeData: function() {
|
||||
serializeData: function () {
|
||||
return this.model.toJSON();
|
||||
}
|
||||
});
|
||||
|
||||
Module._globalStyles = new SuperModel();
|
||||
Module.getGlobalStyles = function() {
|
||||
Module.getGlobalStyles = function () {
|
||||
return Module._globalStyles;
|
||||
};
|
||||
Module.setGlobalStyles = function(options) {
|
||||
Module.setGlobalStyles = function (options) {
|
||||
Module._globalStyles = new Module.StylesModel(options);
|
||||
return Module._globalStyles;
|
||||
};
|
||||
Module.getAvailableStyles = function() {
|
||||
Module.getAvailableStyles = function () {
|
||||
return App.getConfig().get('availableStyles');
|
||||
};
|
||||
|
||||
App.on('before:start', function(App, options) {
|
||||
App.on('before:start', function (App, options) {
|
||||
var Application = App;
|
||||
var body;
|
||||
var globalStyles;
|
||||
// Expose style methods to global application
|
||||
App.getGlobalStyles = Module.getGlobalStyles;
|
||||
App.setGlobalStyles = Module.setGlobalStyles;
|
||||
App.getAvailableStyles = Module.getAvailableStyles;
|
||||
Application.getGlobalStyles = Module.getGlobalStyles;
|
||||
Application.setGlobalStyles = Module.setGlobalStyles;
|
||||
Application.getAvailableStyles = Module.getAvailableStyles;
|
||||
|
||||
var body = options.newsletter.body;
|
||||
var globalStyles = (_.has(body, 'globalStyles')) ? body.globalStyles : {};
|
||||
body = options.newsletter.body;
|
||||
globalStyles = (_.has(body, 'globalStyles')) ? body.globalStyles : {};
|
||||
this.setGlobalStyles(globalStyles);
|
||||
});
|
||||
|
||||
App.on('start', function(App, options) {
|
||||
App.on('start', function (App) {
|
||||
var stylesView = new Module.StylesView({ model: App.getGlobalStyles() });
|
||||
App._appView.showChildView('stylesRegion', stylesView);
|
||||
});
|
||||
|
@ -8,33 +8,35 @@
|
||||
* its placeholder into editor text.
|
||||
*/
|
||||
|
||||
/*jshint unused:false */
|
||||
/*global tinymce:true */
|
||||
tinymce.PluginManager.add('mailpoet_shortcodes', function(editor, url) {
|
||||
var appendLabelAndClose = function(shortcode) {
|
||||
editor.insertContent(shortcode);
|
||||
editor.windowManager.close();
|
||||
},
|
||||
generateOnClickFunc = function(shortcode) {
|
||||
return function() {
|
||||
appendLabelAndClose(shortcode);
|
||||
};
|
||||
/* jshint unused:false */
|
||||
/* global tinymce:true */
|
||||
tinymce.PluginManager.add('mailpoet_shortcodes', function (editor) {
|
||||
var appendLabelAndClose = function (shortcode) {
|
||||
editor.insertContent(shortcode);
|
||||
editor.windowManager.close();
|
||||
};
|
||||
var generateOnClickFunc = function (shortcode) {
|
||||
return function () {
|
||||
appendLabelAndClose(shortcode);
|
||||
};
|
||||
};
|
||||
|
||||
editor.addButton('mailpoet_shortcodes', {
|
||||
icon: 'mailpoet_shortcodes',
|
||||
onclick: function() {
|
||||
var shortcodes = [],
|
||||
configShortcodes = editor.settings.mailpoet_shortcodes;
|
||||
onclick: function () {
|
||||
var shortcodes = [];
|
||||
var configShortcodes = editor.settings.mailpoet_shortcodes;
|
||||
var segment;
|
||||
var i;
|
||||
|
||||
for (var segment in configShortcodes) {
|
||||
for (segment in configShortcodes) {
|
||||
if (configShortcodes.hasOwnProperty(segment)) {
|
||||
shortcodes.push({
|
||||
type: 'label',
|
||||
text: segment
|
||||
});
|
||||
|
||||
for (var i = 0; i < configShortcodes[segment].length; i += 1) {
|
||||
for (i = 0; i < configShortcodes[segment].length; i += 1) {
|
||||
shortcodes.push({
|
||||
type: 'button',
|
||||
text: configShortcodes[segment][i].text,
|
||||
@ -46,8 +48,8 @@ tinymce.PluginManager.add('mailpoet_shortcodes', function(editor, url) {
|
||||
|
||||
// Open window
|
||||
editor.windowManager.open({
|
||||
height: parseInt(editor.getParam("plugin_mailpoet_shortcodes_height", 400)),
|
||||
width: parseInt(editor.getParam("plugin_mailpoet_shortcodes_width", 450)),
|
||||
height: parseInt(editor.getParam('plugin_mailpoet_shortcodes_height', 400)),
|
||||
width: parseInt(editor.getParam('plugin_mailpoet_shortcodes_width', 450)),
|
||||
autoScroll: true,
|
||||
title: editor.settings.mailpoet_shortcodes_window_title,
|
||||
body: shortcodes,
|
||||
|
@ -1,27 +0,0 @@
|
||||
/**
|
||||
* A sample implementation of template widgets.
|
||||
* A draggable widget, on drop creates a container with (image|text) block.
|
||||
*/
|
||||
ImageAndTextTemplateWidgetView = EditorApplication.module('blocks.base').WidgetView.extend({
|
||||
getTemplate: function() { return templates.imageAndTextInsertion; },
|
||||
className: 'mailpoet_droppable_block mailpoet_droppable_widget',
|
||||
behaviors: {
|
||||
DraggableBehavior: {
|
||||
drop: function() {
|
||||
return new (EditorApplication.getBlockTypeModel('container'))({
|
||||
type: 'container',
|
||||
orientation: 'horizontal',
|
||||
blocks: [
|
||||
{
|
||||
type: 'image'
|
||||
},
|
||||
{
|
||||
type: 'text',
|
||||
text: 'Some random text'
|
||||
}
|
||||
]
|
||||
}, {parse: true});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
@ -41,23 +41,23 @@ define(
|
||||
render: function () {
|
||||
const steps = this.state.steps.map((step, index) => {
|
||||
const stepClasses = classNames(
|
||||
{ 'mailpoet_current': (this.props.step === step.name) }
|
||||
{ mailpoet_current: (this.props.step === step.name) }
|
||||
);
|
||||
|
||||
let label = step.label;
|
||||
|
||||
if(step['link'] !== undefined && this.props.step !== step.name) {
|
||||
if (step['link'] !== undefined && this.props.step !== step.name) {
|
||||
label = (
|
||||
<Link to={ step.link }>{ step.label }</Link>
|
||||
<Link to={step.link}>{ step.label }</Link>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<span key={ 'step-'+index }>
|
||||
<span className={ stepClasses }>
|
||||
<span key={'step-' + index}>
|
||||
<span className={stepClasses}>
|
||||
{ label }
|
||||
</span>
|
||||
{ (index < (this.state.steps.length - 1) ) ? ' > ' : '' }
|
||||
{ (index < (this.state.steps.length - 1)) ? ' > ' : '' }
|
||||
</span>
|
||||
);
|
||||
});
|
||||
|
@ -19,8 +19,8 @@ const _QueueMixin = {
|
||||
newsletter_id: newsletter.id,
|
||||
},
|
||||
}).done(() => {
|
||||
jQuery('#resume_'+newsletter.id).show();
|
||||
jQuery('#pause_'+newsletter.id).hide();
|
||||
jQuery('#resume_' + newsletter.id).show();
|
||||
jQuery('#pause_' + newsletter.id).hide();
|
||||
}).fail((response) => {
|
||||
if (response.errors.length > 0) {
|
||||
MailPoet.Notice.error(
|
||||
@ -39,8 +39,8 @@ const _QueueMixin = {
|
||||
newsletter_id: newsletter.id,
|
||||
},
|
||||
}).done(() => {
|
||||
jQuery('#pause_'+newsletter.id).show();
|
||||
jQuery('#resume_'+newsletter.id).hide();
|
||||
jQuery('#pause_' + newsletter.id).show();
|
||||
jQuery('#resume_' + newsletter.id).hide();
|
||||
}).fail((response) => {
|
||||
if (response.errors.length > 0) {
|
||||
MailPoet.Notice.error(
|
||||
@ -69,7 +69,7 @@ const _QueueMixin = {
|
||||
}
|
||||
const progressClasses = classNames(
|
||||
'mailpoet_progress',
|
||||
{ 'mailpoet_progress_complete': newsletter.queue.status === 'completed' }
|
||||
{ mailpoet_progress_complete: newsletter.queue.status === 'completed' }
|
||||
);
|
||||
|
||||
// calculate percentage done
|
||||
@ -84,8 +84,8 @@ const _QueueMixin = {
|
||||
<span>
|
||||
{
|
||||
MailPoet.I18n.t('newsletterQueueCompleted')
|
||||
.replace("%$1d", newsletter.queue.count_processed)
|
||||
.replace("%$2d", newsletter.queue.count_total)
|
||||
.replace('%$1d', parseInt(newsletter.queue.count_processed, 10).toLocaleString())
|
||||
.replace('%$2d', parseInt(newsletter.queue.count_total, 10).toLocaleString())
|
||||
}
|
||||
</span>
|
||||
);
|
||||
@ -95,20 +95,20 @@ const _QueueMixin = {
|
||||
{ newsletter.queue.count_processed } / { newsletter.queue.count_total }
|
||||
|
||||
<a
|
||||
id={ 'resume_'+newsletter.id }
|
||||
id={'resume_' + newsletter.id}
|
||||
className="button"
|
||||
style={{ display: (newsletter.queue.status === 'paused')
|
||||
? 'inline-block': 'none' }}
|
||||
? 'inline-block' : 'none' }}
|
||||
href="javascript:;"
|
||||
onClick={ this.resumeSending.bind(null, newsletter) }
|
||||
onClick={this.resumeSending.bind(null, newsletter)}
|
||||
>{MailPoet.I18n.t('resume')}</a>
|
||||
<a
|
||||
id={ 'pause_'+newsletter.id }
|
||||
id={'pause_' + newsletter.id}
|
||||
className="button mailpoet_pause"
|
||||
style={{ display: (newsletter.queue.status === null)
|
||||
? 'inline-block': 'none' }}
|
||||
? 'inline-block' : 'none' }}
|
||||
href="javascript:;"
|
||||
onClick={ this.pauseSending.bind(null, newsletter) }
|
||||
onClick={this.pauseSending.bind(null, newsletter)}
|
||||
>{MailPoet.I18n.t('pause')}</a>
|
||||
</span>
|
||||
);
|
||||
@ -120,21 +120,21 @@ const _QueueMixin = {
|
||||
percentage = MailPoet.I18n.t('noSubscribers');
|
||||
} else {
|
||||
progress_bar_width = percentage;
|
||||
percentage += "%";
|
||||
percentage += '%';
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className={ progressClasses }>
|
||||
<span
|
||||
className="mailpoet_progress_bar"
|
||||
style={ { width: progress_bar_width + "%" } }
|
||||
<div className={progressClasses}>
|
||||
<span
|
||||
className="mailpoet_progress_bar"
|
||||
style={{ width: progress_bar_width + '%' }}
|
||||
></span>
|
||||
<span className="mailpoet_progress_label">
|
||||
{ percentage }
|
||||
</span>
|
||||
<span className="mailpoet_progress_label">
|
||||
{ percentage }
|
||||
</span>
|
||||
</div>
|
||||
<p style={{ textAlign:'center' }}>
|
||||
<p style={{ textAlign: 'center' }}>
|
||||
{ label }
|
||||
</p>
|
||||
</div>
|
||||
@ -143,21 +143,30 @@ const _QueueMixin = {
|
||||
},
|
||||
};
|
||||
|
||||
const trackStatsCTAClicked = function () {
|
||||
MailPoet.trackEvent(
|
||||
'User has clicked a CTA to view detailed stats',
|
||||
{ 'MailPoet Free version': window.mailpoet_version }
|
||||
);
|
||||
};
|
||||
|
||||
const _StatisticsMixin = {
|
||||
renderStatistics: function (newsletter, is_sent, current_time) {
|
||||
if (is_sent === undefined) {
|
||||
let sent = is_sent;
|
||||
if (sent === undefined) {
|
||||
// condition for standard and post notification listings
|
||||
is_sent = newsletter.statistics
|
||||
sent = newsletter.statistics
|
||||
&& newsletter.queue
|
||||
&& newsletter.queue.status !== 'scheduled';
|
||||
}
|
||||
if (!is_sent) {
|
||||
if (!sent) {
|
||||
return (
|
||||
<span>{MailPoet.I18n.t('notSentYet')}</span>
|
||||
);
|
||||
}
|
||||
|
||||
let params = {};
|
||||
Hooks.addFilter('mailpoet_newsletters_listing_stats_before', this.addStatsCTALink);
|
||||
params = Hooks.applyFilters('mailpoet_newsletters_listing_stats_before', params, newsletter);
|
||||
|
||||
// welcome emails provide explicit total_sent value
|
||||
@ -178,11 +187,11 @@ const _StatisticsMixin = {
|
||||
const percentage_opened_display = MailPoet.Num.toLocaleFixed(percentage_opened, 1);
|
||||
const percentage_unsubscribed_display = MailPoet.Num.toLocaleFixed(percentage_unsubscribed, 1);
|
||||
|
||||
let show_stats_timeout,
|
||||
newsletter_date,
|
||||
sent_hours_ago,
|
||||
too_early_for_stats,
|
||||
show_kb_link;
|
||||
let show_stats_timeout;
|
||||
let newsletter_date;
|
||||
let sent_hours_ago;
|
||||
let too_early_for_stats;
|
||||
let show_kb_link;
|
||||
if (current_time !== undefined) {
|
||||
// standard emails and post notifications:
|
||||
// display green box for newsletters that were just sent
|
||||
@ -238,7 +247,7 @@ const _StatisticsMixin = {
|
||||
<div>
|
||||
<span className="mailpoet_stats_text">
|
||||
{ percentage_opened_display }%,
|
||||
{ " " }
|
||||
{ ' ' }
|
||||
{ percentage_clicked_display }%
|
||||
<span className="mailpoet_stat_hidden">
|
||||
, { percentage_unsubscribed_display }%
|
||||
@ -281,18 +290,33 @@ const _StatisticsMixin = {
|
||||
|
||||
if (total_sent > 0 && params.link) {
|
||||
// wrap content in a link
|
||||
return (
|
||||
<div>
|
||||
<Link
|
||||
key={ `stats-${newsletter.id}` }
|
||||
to={ params.link }
|
||||
onClick={ params.onClick || null }
|
||||
>
|
||||
{content}
|
||||
</Link>
|
||||
{after_content}
|
||||
</div>
|
||||
);
|
||||
if (params.externalLink) {
|
||||
return (
|
||||
<div>
|
||||
<a
|
||||
key={`stats-${newsletter.id}`}
|
||||
href={params.link}
|
||||
onClick={params.onClick || null}
|
||||
>
|
||||
{content}
|
||||
</a>
|
||||
{after_content}
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<div>
|
||||
<Link
|
||||
key={`stats-${newsletter.id}`}
|
||||
to={params.link}
|
||||
onClick={params.onClick || null}
|
||||
>
|
||||
{content}
|
||||
</Link>
|
||||
{after_content}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
@ -302,6 +326,37 @@ const _StatisticsMixin = {
|
||||
</div>
|
||||
);
|
||||
},
|
||||
addStatsCTAAction: function (actions) {
|
||||
if (window.mailpoet_premium_active) {
|
||||
return actions;
|
||||
}
|
||||
actions.unshift({
|
||||
name: 'stats',
|
||||
link: function () {
|
||||
return (
|
||||
<a href={'admin.php?page=mailpoet-premium'} onClick={trackStatsCTAClicked}>
|
||||
{MailPoet.I18n.t('statsListingActionTitle')}
|
||||
</a>
|
||||
);
|
||||
},
|
||||
display: function (newsletter) {
|
||||
// welcome emails provide explicit total_sent value
|
||||
const count_processed = newsletter.queue && newsletter.queue.count_processed;
|
||||
return ~~(newsletter.total_sent || count_processed) > 0;
|
||||
},
|
||||
});
|
||||
return actions;
|
||||
},
|
||||
addStatsCTALink: function (params) {
|
||||
if (window.mailpoet_premium_active) {
|
||||
return params;
|
||||
}
|
||||
const newParams = params;
|
||||
newParams.link = 'admin.php?page=mailpoet-premium';
|
||||
newParams.externalLink = true;
|
||||
newParams.onClick = trackStatsCTAClicked;
|
||||
return newParams;
|
||||
},
|
||||
};
|
||||
|
||||
const _MailerMixin = {
|
||||
@ -326,7 +381,7 @@ const _MailerMixin = {
|
||||
MailPoet.I18n.t('mailerCheckSettingsNotice'),
|
||||
/\[link\](.*?)\[\/link\]/g,
|
||||
match => (
|
||||
<a href={`?page=mailpoet-settings#mta`}>{ match }</a>
|
||||
<a href={'?page=mailpoet-settings#mta'} key="check-sending">{ match }</a>
|
||||
)
|
||||
);
|
||||
if (state.meta.mta_log.error.operation === 'send') {
|
||||
@ -345,8 +400,8 @@ const _MailerMixin = {
|
||||
<p>{ mailer_check_settings_notice }</p>
|
||||
<p>
|
||||
<a href="javascript:;"
|
||||
className="button"
|
||||
onClick={ this.resumeMailerSending }
|
||||
className="button"
|
||||
onClick={this.resumeMailerSending}
|
||||
>{ MailPoet.I18n.t('mailerResumeSendingButton') }</a>
|
||||
</p>
|
||||
</div>
|
||||
@ -373,8 +428,6 @@ const _MailerMixin = {
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
export { _QueueMixin as QueueMixin };
|
||||
export { _StatisticsMixin as StatisticsMixin };
|
||||
export { _MailerMixin as MailerMixin };
|
||||
|
@ -104,7 +104,7 @@ const newsletter_actions = [
|
||||
name: 'view',
|
||||
link: function (newsletter) {
|
||||
return (
|
||||
<a href={ newsletter.preview_url } target="_blank">
|
||||
<a href={newsletter.preview_url} target="_blank">
|
||||
{MailPoet.I18n.t('preview')}
|
||||
</a>
|
||||
);
|
||||
@ -114,7 +114,7 @@ const newsletter_actions = [
|
||||
name: 'edit',
|
||||
link: function (newsletter) {
|
||||
return (
|
||||
<a href={ `?page=mailpoet-newsletter-editor&id=${ newsletter.id }` }>
|
||||
<a href={`?page=mailpoet-newsletter-editor&id=${newsletter.id}`}>
|
||||
{MailPoet.I18n.t('edit')}
|
||||
</a>
|
||||
);
|
||||
@ -154,7 +154,7 @@ const newsletter_actions = [
|
||||
];
|
||||
|
||||
const NewsletterListNotification = React.createClass({
|
||||
mixins: [ MailerMixin ],
|
||||
mixins: [MailerMixin],
|
||||
updateStatus: function (e) {
|
||||
// make the event persist so that we can still override the selected value
|
||||
// in the ajax callback
|
||||
@ -184,9 +184,9 @@ const NewsletterListNotification = React.createClass({
|
||||
renderStatus: function (newsletter) {
|
||||
return (
|
||||
<select
|
||||
data-id={ newsletter.id }
|
||||
defaultValue={ newsletter.status }
|
||||
onChange={ this.updateStatus }
|
||||
data-id={newsletter.id}
|
||||
defaultValue={newsletter.status}
|
||||
onChange={this.updateStatus}
|
||||
>
|
||||
<option value="active">{ MailPoet.I18n.t('active') }</option>
|
||||
<option value="draft">{ MailPoet.I18n.t('inactive') }</option>
|
||||
@ -203,7 +203,7 @@ const NewsletterListNotification = React.createClass({
|
||||
});
|
||||
|
||||
// check if the user has specified segments to send to
|
||||
if(segments.length === 0) {
|
||||
if (segments.length === 0) {
|
||||
return (
|
||||
<span className="mailpoet_error">
|
||||
{ MailPoet.I18n.t('sendingToSegmentsNotSpecified') }
|
||||
@ -269,7 +269,7 @@ const NewsletterListNotification = React.createClass({
|
||||
} else {
|
||||
return (
|
||||
<Link
|
||||
to={ `/notification/history/${ newsletter.id }` }
|
||||
to={`/notification/history/${newsletter.id}`}
|
||||
>{ MailPoet.I18n.t('viewHistory') }</Link>
|
||||
);
|
||||
}
|
||||
@ -283,25 +283,25 @@ const NewsletterListNotification = React.createClass({
|
||||
|
||||
return (
|
||||
<div>
|
||||
<td className={ rowClasses }>
|
||||
<td className={rowClasses}>
|
||||
<strong>
|
||||
<a
|
||||
className="row-title"
|
||||
href={ `?page=mailpoet-newsletter-editor&id=${ newsletter.id }` }
|
||||
href={`?page=mailpoet-newsletter-editor&id=${newsletter.id}`}
|
||||
>{ newsletter.subject }</a>
|
||||
</strong>
|
||||
{ actions }
|
||||
</td>
|
||||
<td className="column" data-colname={ MailPoet.I18n.t('status') }>
|
||||
<td className="column" data-colname={MailPoet.I18n.t('status')}>
|
||||
{ this.renderStatus(newsletter) }
|
||||
</td>
|
||||
<td className="column" data-colname={ MailPoet.I18n.t('settings') }>
|
||||
<td className="column" data-colname={MailPoet.I18n.t('settings')}>
|
||||
{ this.renderSettings(newsletter) }
|
||||
</td>
|
||||
<td className="column" data-colname={ MailPoet.I18n.t('history') }>
|
||||
<td className="column" data-colname={MailPoet.I18n.t('history')}>
|
||||
{ this.renderHistoryLink(newsletter) }
|
||||
</td>
|
||||
<td className="column-date" data-colname={ MailPoet.I18n.t('lastModifiedOn') }>
|
||||
<td className="column-date" data-colname={MailPoet.I18n.t('lastModifiedOn')}>
|
||||
<abbr>{ MailPoet.Date.format(newsletter.updated_at) }</abbr>
|
||||
</td>
|
||||
</div>
|
||||
@ -317,21 +317,21 @@ const NewsletterListNotification = React.createClass({
|
||||
<ListingTabs tab="notification" />
|
||||
|
||||
<Listing
|
||||
limit={ mailpoet_listing_per_page }
|
||||
location={ this.props.location }
|
||||
params={ this.props.params }
|
||||
limit={window.mailpoet_listing_per_page}
|
||||
location={this.props.location}
|
||||
params={this.props.params}
|
||||
endpoint="newsletters"
|
||||
type="notification"
|
||||
base_url="notification"
|
||||
onRenderItem={ this.renderItem }
|
||||
columns={ columns }
|
||||
bulk_actions={ bulk_actions }
|
||||
item_actions={ newsletter_actions }
|
||||
messages={ messages }
|
||||
auto_refresh={ true }
|
||||
onRenderItem={this.renderItem}
|
||||
columns={columns}
|
||||
bulk_actions={bulk_actions}
|
||||
item_actions={newsletter_actions}
|
||||
messages={messages}
|
||||
auto_refresh={true}
|
||||
sort_by="updated_at"
|
||||
sort_order="desc"
|
||||
afterGetItems={ this.checkMailerStatus }
|
||||
afterGetItems={this.checkMailerStatus}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
@ -44,7 +44,7 @@ let newsletter_actions = [
|
||||
name: 'view',
|
||||
link: function (newsletter) {
|
||||
return (
|
||||
<a href={ newsletter.preview_url } target="_blank">
|
||||
<a href={newsletter.preview_url} target="_blank">
|
||||
{MailPoet.I18n.t('preview')}
|
||||
</a>
|
||||
);
|
||||
@ -52,10 +52,11 @@ let newsletter_actions = [
|
||||
},
|
||||
];
|
||||
|
||||
Hooks.addFilter('mailpoet_newsletters_listings_notification_history_actions', StatisticsMixin.addStatsCTAAction);
|
||||
newsletter_actions = Hooks.applyFilters('mailpoet_newsletters_listings_notification_history_actions', newsletter_actions);
|
||||
|
||||
const NewsletterListNotificationHistory = React.createClass({
|
||||
mixins: [ QueueMixin, StatisticsMixin, MailerMixin ],
|
||||
mixins: [QueueMixin, StatisticsMixin, MailerMixin],
|
||||
renderItem: function (newsletter, actions, meta) {
|
||||
const rowClasses = classNames(
|
||||
'manage-column',
|
||||
@ -69,27 +70,27 @@ const NewsletterListNotificationHistory = React.createClass({
|
||||
|
||||
return (
|
||||
<div>
|
||||
<td className={ rowClasses }>
|
||||
<td className={rowClasses}>
|
||||
<strong>
|
||||
<a
|
||||
href={ newsletter.preview_url }
|
||||
href={newsletter.preview_url}
|
||||
target="_blank"
|
||||
>{ newsletter.queue.newsletter_rendered_subject || newsletter.subject }</a>
|
||||
</strong>
|
||||
{ actions }
|
||||
</td>
|
||||
<td className="column" data-colname={ MailPoet.I18n.t('status') }>
|
||||
<td className="column" data-colname={MailPoet.I18n.t('status')}>
|
||||
{ this.renderQueueStatus(newsletter, meta.mta_log) }
|
||||
</td>
|
||||
<td className="column" data-colname={ MailPoet.I18n.t('lists') }>
|
||||
<td className="column" data-colname={MailPoet.I18n.t('lists')}>
|
||||
{ segments }
|
||||
</td>
|
||||
{ (mailpoet_tracking_enabled === true) ? (
|
||||
<td className="column" data-colname={ MailPoet.I18n.t('statistics') }>
|
||||
<td className="column" data-colname={MailPoet.I18n.t('statistics')}>
|
||||
{ this.renderStatistics(newsletter, undefined, meta.current_time) }
|
||||
</td>
|
||||
) : null }
|
||||
<td className="column-date" data-colname={ MailPoet.I18n.t('sentOn') }>
|
||||
<td className="column-date" data-colname={MailPoet.I18n.t('sentOn')}>
|
||||
{ (newsletter.sent_at) ? MailPoet.Date.format(newsletter.sent_at) : MailPoet.I18n.t('notSentYet') }
|
||||
</td>
|
||||
</div>
|
||||
@ -110,19 +111,19 @@ const NewsletterListNotificationHistory = React.createClass({
|
||||
>{MailPoet.I18n.t('backToPostNotifications')}</Link>
|
||||
|
||||
<Listing
|
||||
limit={ mailpoet_listing_per_page }
|
||||
location={ this.props.location }
|
||||
params={ this.props.params }
|
||||
limit={window.mailpoet_listing_per_page}
|
||||
location={this.props.location}
|
||||
params={this.props.params}
|
||||
endpoint="newsletters"
|
||||
type="notification_history"
|
||||
base_url="notification/history/:parent_id"
|
||||
onRenderItem={ this.renderItem }
|
||||
onRenderItem={this.renderItem}
|
||||
columns={columns}
|
||||
item_actions={ newsletter_actions }
|
||||
auto_refresh={ true }
|
||||
item_actions={newsletter_actions}
|
||||
auto_refresh={true}
|
||||
sort_by="sent_at"
|
||||
sort_order="desc"
|
||||
afterGetItems={ this.checkMailerStatus }
|
||||
afterGetItems={this.checkMailerStatus}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
@ -97,12 +97,23 @@ const bulk_actions = [
|
||||
},
|
||||
];
|
||||
|
||||
const confirmEdit = (newsletter) => {
|
||||
if (
|
||||
!newsletter.queue
|
||||
|| newsletter.status != 'sending'
|
||||
|| newsletter.queue.status !== null
|
||||
|| window.confirm(MailPoet.I18n.t('confirmEdit'))
|
||||
) {
|
||||
window.location.href = `?page=mailpoet-newsletter-editor&id=${newsletter.id}`;
|
||||
}
|
||||
};
|
||||
|
||||
let newsletter_actions = [
|
||||
{
|
||||
name: 'view',
|
||||
link: function (newsletter) {
|
||||
return (
|
||||
<a href={ newsletter.preview_url } target="_blank">
|
||||
<a href={newsletter.preview_url} target="_blank">
|
||||
{MailPoet.I18n.t('preview')}
|
||||
</a>
|
||||
);
|
||||
@ -110,13 +121,8 @@ let newsletter_actions = [
|
||||
},
|
||||
{
|
||||
name: 'edit',
|
||||
link: function (newsletter) {
|
||||
return (
|
||||
<a href={ `?page=mailpoet-newsletter-editor&id=${ newsletter.id }` }>
|
||||
{MailPoet.I18n.t('edit')}
|
||||
</a>
|
||||
);
|
||||
},
|
||||
label: MailPoet.I18n.t('edit'),
|
||||
onClick: confirmEdit,
|
||||
},
|
||||
{
|
||||
name: 'duplicate',
|
||||
@ -151,10 +157,11 @@ let newsletter_actions = [
|
||||
},
|
||||
];
|
||||
|
||||
Hooks.addFilter('mailpoet_newsletters_listings_standard_actions', StatisticsMixin.addStatsCTAAction);
|
||||
newsletter_actions = Hooks.applyFilters('mailpoet_newsletters_listings_standard_actions', newsletter_actions);
|
||||
|
||||
const NewsletterListStandard = React.createClass({
|
||||
mixins: [ QueueMixin, StatisticsMixin, MailerMixin ],
|
||||
mixins: [QueueMixin, StatisticsMixin, MailerMixin],
|
||||
renderItem: function (newsletter, actions, meta) {
|
||||
const rowClasses = classNames(
|
||||
'manage-column',
|
||||
@ -168,27 +175,28 @@ const NewsletterListStandard = React.createClass({
|
||||
|
||||
return (
|
||||
<div>
|
||||
<td className={ rowClasses }>
|
||||
<td className={rowClasses}>
|
||||
<strong>
|
||||
<a
|
||||
className="row-title"
|
||||
href={ `?page=mailpoet-newsletter-editor&id=${ newsletter.id }` }
|
||||
href="javascript:;"
|
||||
onClick={() => confirmEdit(newsletter)}
|
||||
>{ newsletter.queue.newsletter_rendered_subject || newsletter.subject }</a>
|
||||
</strong>
|
||||
{ actions }
|
||||
</td>
|
||||
<td className="column" data-colname={ MailPoet.I18n.t('status') }>
|
||||
<td className="column" data-colname={MailPoet.I18n.t('status')}>
|
||||
{ this.renderQueueStatus(newsletter, meta.mta_log) }
|
||||
</td>
|
||||
<td className="column" data-colname={ MailPoet.I18n.t('lists') }>
|
||||
<td className="column" data-colname={MailPoet.I18n.t('lists')}>
|
||||
{ segments }
|
||||
</td>
|
||||
{ (mailpoet_tracking_enabled === true) ? (
|
||||
<td className="column" data-colname={ MailPoet.I18n.t('statistics') }>
|
||||
<td className="column" data-colname={MailPoet.I18n.t('statistics')}>
|
||||
{ this.renderStatistics(newsletter, undefined, meta.current_time) }
|
||||
</td>
|
||||
) : null }
|
||||
<td className="column-date" data-colname={ MailPoet.I18n.t('sentOn') }>
|
||||
<td className="column-date" data-colname={MailPoet.I18n.t('sentOn')}>
|
||||
<abbr>{ (newsletter.sent_at) ? MailPoet.Date.format(newsletter.sent_at) : MailPoet.I18n.t('notSentYet') }</abbr>
|
||||
</td>
|
||||
</div>
|
||||
@ -198,27 +206,34 @@ const NewsletterListStandard = React.createClass({
|
||||
return (
|
||||
<div>
|
||||
<h1 className="title">
|
||||
{MailPoet.I18n.t('pageTitle')} <Link className="page-title-action" to="/new">{MailPoet.I18n.t('new')}</Link>
|
||||
{MailPoet.I18n.t('pageTitle')}
|
||||
<Link className="page-title-action" to="/new"
|
||||
onClick={() => MailPoet.trackEvent('Emails > Add New',
|
||||
{ 'MailPoet Free version': window.mailpoet_version }
|
||||
)}
|
||||
>
|
||||
{MailPoet.I18n.t('new')}
|
||||
</Link>
|
||||
</h1>
|
||||
|
||||
<ListingTabs tab="standard" />
|
||||
|
||||
<Listing
|
||||
limit={ mailpoet_listing_per_page }
|
||||
location={ this.props.location }
|
||||
params={ this.props.params }
|
||||
limit={window.mailpoet_listing_per_page}
|
||||
location={this.props.location}
|
||||
params={this.props.params}
|
||||
endpoint="newsletters"
|
||||
type="standard"
|
||||
base_url="standard"
|
||||
onRenderItem={this.renderItem}
|
||||
columns={columns}
|
||||
bulk_actions={ bulk_actions }
|
||||
item_actions={ newsletter_actions }
|
||||
messages={ messages }
|
||||
auto_refresh={ true }
|
||||
bulk_actions={bulk_actions}
|
||||
item_actions={newsletter_actions}
|
||||
messages={messages}
|
||||
auto_refresh={true}
|
||||
sort_by="sent_at"
|
||||
sort_order="desc"
|
||||
afterGetItems={ this.checkMailerStatus }
|
||||
afterGetItems={this.checkMailerStatus}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
@ -35,9 +35,12 @@ const ListingTabs = React.createClass({
|
||||
|
||||
return (
|
||||
<Link
|
||||
key={ 'tab-'+index }
|
||||
className={ tabClasses }
|
||||
to={ tab.link }
|
||||
key={'tab-' + index}
|
||||
className={tabClasses}
|
||||
to={tab.link}
|
||||
onClick={() => MailPoet.trackEvent(`Tab Emails > ${tab.name} clicked`,
|
||||
{ 'MailPoet Free version': window.mailpoet_version }
|
||||
)}
|
||||
>{ tab.label }</Link>
|
||||
);
|
||||
});
|
||||
|
@ -103,7 +103,7 @@ let newsletter_actions = [
|
||||
name: 'view',
|
||||
link: function (newsletter) {
|
||||
return (
|
||||
<a href={ newsletter.preview_url } target="_blank">
|
||||
<a href={newsletter.preview_url} target="_blank">
|
||||
{MailPoet.I18n.t('preview')}
|
||||
</a>
|
||||
);
|
||||
@ -113,7 +113,7 @@ let newsletter_actions = [
|
||||
name: 'edit',
|
||||
link: function (newsletter) {
|
||||
return (
|
||||
<a href={ `?page=mailpoet-newsletter-editor&id=${ newsletter.id }` }>
|
||||
<a href={`?page=mailpoet-newsletter-editor&id=${newsletter.id}`}>
|
||||
{MailPoet.I18n.t('edit')}
|
||||
</a>
|
||||
);
|
||||
@ -124,10 +124,11 @@ let newsletter_actions = [
|
||||
},
|
||||
];
|
||||
|
||||
Hooks.addFilter('mailpoet_newsletters_listings_welcome_notification_actions', StatisticsMixin.addStatsCTAAction);
|
||||
newsletter_actions = Hooks.applyFilters('mailpoet_newsletters_listings_welcome_notification_actions', newsletter_actions);
|
||||
|
||||
const NewsletterListWelcome = React.createClass({
|
||||
mixins: [ StatisticsMixin, MailerMixin ],
|
||||
mixins: [StatisticsMixin, MailerMixin],
|
||||
updateStatus: function (e) {
|
||||
// make the event persist so that we can still override the selected value
|
||||
// in the ajax callback
|
||||
@ -164,9 +165,9 @@ const NewsletterListWelcome = React.createClass({
|
||||
<div>
|
||||
<p>
|
||||
<select
|
||||
data-id={ newsletter.id }
|
||||
defaultValue={ newsletter.status }
|
||||
onChange={ this.updateStatus }
|
||||
data-id={newsletter.id}
|
||||
defaultValue={newsletter.status}
|
||||
onChange={this.updateStatus}
|
||||
>
|
||||
<option value="active">{ MailPoet.I18n.t('active') }</option>
|
||||
<option value="draft">{ MailPoet.I18n.t('inactive') }</option>
|
||||
@ -256,30 +257,30 @@ const NewsletterListWelcome = React.createClass({
|
||||
|
||||
return (
|
||||
<div>
|
||||
<td className={ rowClasses }>
|
||||
<td className={rowClasses}>
|
||||
<strong>
|
||||
<a
|
||||
className="row-title"
|
||||
href={ `?page=mailpoet-newsletter-editor&id=${ newsletter.id }` }
|
||||
href={`?page=mailpoet-newsletter-editor&id=${newsletter.id}`}
|
||||
>{ newsletter.subject }</a>
|
||||
</strong>
|
||||
{ actions }
|
||||
</td>
|
||||
<td className="column" data-colname={ MailPoet.I18n.t('status') }>
|
||||
<td className="column" data-colname={MailPoet.I18n.t('status')}>
|
||||
{ this.renderStatus(newsletter) }
|
||||
</td>
|
||||
<td className="column" data-colname={ MailPoet.I18n.t('settings') }>
|
||||
<td className="column" data-colname={MailPoet.I18n.t('settings')}>
|
||||
{ this.renderSettings(newsletter) }
|
||||
</td>
|
||||
{ (mailpoet_tracking_enabled === true) ? (
|
||||
<td className="column" data-colname={ MailPoet.I18n.t('statistics') }>
|
||||
<td className="column" data-colname={MailPoet.I18n.t('statistics')}>
|
||||
{ this.renderStatistics(
|
||||
newsletter,
|
||||
newsletter.total_sent > 0 && newsletter.statistics
|
||||
) }
|
||||
</td>
|
||||
) : null }
|
||||
<td className="column-date" data-colname={ MailPoet.I18n.t('lastModifiedOn') }>
|
||||
<td className="column-date" data-colname={MailPoet.I18n.t('lastModifiedOn')}>
|
||||
<abbr>{ MailPoet.Date.format(newsletter.updated_at) }</abbr>
|
||||
</td>
|
||||
</div>
|
||||
@ -295,21 +296,21 @@ const NewsletterListWelcome = React.createClass({
|
||||
<ListingTabs tab="welcome" />
|
||||
|
||||
<Listing
|
||||
limit={ mailpoet_listing_per_page }
|
||||
location={ this.props.location }
|
||||
params={ this.props.params }
|
||||
limit={window.mailpoet_listing_per_page}
|
||||
location={this.props.location}
|
||||
params={this.props.params}
|
||||
endpoint="newsletters"
|
||||
type="welcome"
|
||||
base_url="welcome"
|
||||
onRenderItem={ this.renderItem }
|
||||
columns={ columns }
|
||||
bulk_actions={ bulk_actions }
|
||||
item_actions={ newsletter_actions }
|
||||
messages={ messages }
|
||||
auto_refresh={ true }
|
||||
onRenderItem={this.renderItem}
|
||||
columns={columns}
|
||||
bulk_actions={bulk_actions}
|
||||
item_actions={newsletter_actions}
|
||||
messages={messages}
|
||||
auto_refresh={true}
|
||||
sort_by="updated_at"
|
||||
sort_order="desc"
|
||||
afterGetItems={ this.checkMailerStatus }
|
||||
afterGetItems={this.checkMailerStatus}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user