Skip to content

Instantly share code, notes, and snippets.

@lukrizal
Last active August 31, 2015 02:13
Show Gist options
  • Save lukrizal/09a93cd02aa58bbcc9e2 to your computer and use it in GitHub Desktop.
Save lukrizal/09a93cd02aa58bbcc9e2 to your computer and use it in GitHub Desktop.
web
app.directive 'paymentMethod', ()->
restrict: "AE"
templateUrl: 'directive-payment'
scope:
onImage : '=on'
offImage : '=off'
value : '=value'
text : '=text'
require: 'ngModel'
link: ($scope, $elem, $attrs, ngModel)->
checkStatus = ($elem, ngModel, $scope)->
console.log "%s, %s", ngModel.$viewValue, $scope.value
img = if ngModel.$viewValue is $scope.value then $scope.onImage else $scope.offImage
$elem.find('img').attr('src', img)
$elem.find('img').attr('src', $scope.offImage)
if ngModel
$elem.on 'click', ()->
x = if ngModel.$viewValue isnt $scope.value then $scope.value else ''
ngModel.$setViewValue(x)
$scope.$apply()
checkStatus($elem, ngModel, $scope)
originRender = ngModel.$render
ngModel.$render = ()->
x = originRender()
checkStatus($elem, ngModel, $scope)
x
// HTML
<payment-method text="'Agent'" on="$root.image.on" off="$root.image.off" value="{{$paymentAgent}}" ng-model="form.payment_method"></payment-method>
// TEMPLATE
<a style="cursor:pointer;" title="{[ text ]}">
<img class="img-radio" alt="img"> {[ text ]}
</a>
app.service 'DataRepo', ['$http', '$timeout', ($http, $timeout)->
...
body.get = (callback)->
url = "/api/resource/custom-orders?#{$.param({userid:body.user.user_uid,per_page:body.listing.per_page,page:body.listing.page, search: body.listing.search_key})}&callback=JSON_CALLBACK"
body.events.fetching = true
$http.jsonp(url).then (response)->
body.events.fetching = false
if not angular.equals(body.listing.items, response.data.data)
body.events.updating = true
body.listing.items = response.data.data
body.listing.current_page = response.data.current_page
body.listing.total = response.data.total
if angular.isFunction(callback)
$timeout(callback, 2500)
app.run ($rootScope, DataRepo)->
fn = ()->
DataRepo.get(fn)
fn()
App::after(function($request, $response)
...
if (method_exists($request, 'query') AND !empty($request->query('callback'))) {
$content = $response->getContent();
$response->setContent(sprintf("%s(%s);", $request->query('callback'), $content));
}
if (Auth::guest()) return Redirect::route('pex.shopping.login', ['redir'=>Request::fullUrl()]);
server {
listen 80;
server_name pa.laravel.local;
root "/home/vagrant/Code/pa.laravel.local/public";
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~* ^(.+)\.(\d+)\.(bmp|css|cur|gif|ico|jpe?g|js|png|svgz?|webp|webmanifest)$ {
rewrite ^/(.+)\.(\d+)\.(bmp|css|cur|gif|ico|jpe?g|js|png|svgz?|webp|webmanifest)$ /$1.$3 break;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/pa.laravel.local-error.log error;
sendfile off;
client_max_body_size 100m;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
}
location ~ /\.ht {
deny all;
}
}
server {
listen 443;
server_name pa.laravel.local;
root "/home/vagrant/Code/pa.laravel.local/public";
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# For cache busting
location ~* ^(.+)\.(\d+)\.(bmp|css|cur|gif|ico|jpe?g|js|png|svgz?|webp|webmanifest)$ {
rewrite ^/(.+)\.(\d+)\.(bmp|css|cur|gif|ico|jpe?g|js|png|svgz?|webp|webmanifest)$ /$1.$3 break;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/pa.laravel.local-ssl-error.log error;
sendfile off;
client_max_body_size 100m;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
}
location ~ /\.ht {
deny all;
}
ssl on;
ssl_certificate /etc/nginx/ssl/pa.laravel.local.crt;
ssl_certificate_key /etc/nginx/ssl/pa.laravel.local.key;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment