Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.config(function($routeProvider){
- $routeProvider
- .when('/',{ templateUrl : "admin/template" })
- .when('/account',{ templateUrl : "admin/account/edit" })
- });
- <h1>Page 1</h1>
- <h1>Page 2</h1>
- var app = angular.module('memeApp',['ngRoute','ui.bootstrap','blockUI','ngFileUpload'],function($interpolateProvider) {
- $interpolateProvider.startSymbol('<%');
- $interpolateProvider.endSymbol('%>');
- });
- <div class="row" ng-controller="DefaultController" ng-init="getTemplatesUrl='{{ url('admin/templates') }}';init();">
- <div class="col-md-12">
- <div class="row">
- <div class="col-md-12">
- <form name="createTemplateForm">
- <fieldset>
- <legend>Create new template</legend>
- <div>
- <label>Priortized </label>
- <input type="checkbox" ng-model="prioritized">
- </div>
- <input type="file" ngf-select ng-model="picFile" name="file"
- accept="image/*" ngf-max-size="2MB" required
- ngf-model-invalid="errorFile">
- <i ng-show="createTemplateForm.file.$error.required">*required</i><br>
- <i ng-show="createTemplateForm.file.$error.maxSize">File too large
- <span ng-bind="errorFile.size / 1000000|number:1"></span>MB: max 2M</i>
- <img ng-show="myForm.file.$valid" ngf-thumbnail="picFile" class="thumb">
- <br>
- <button ng-disabled="!createTemplateForm.$valid"
- ng-click="uploadPic(picFile,'{{ url('admin/template/create') }}')">Submit</button>
- <span ng-show="createResult">Upload Successful</span>
- </fieldset>
- <br>
- </form>
- </div>
- </div>
- <div class="row">
- <div class="col-md-12">
- <div class="row">
- <div ng-repeat="x in templates" class="col-md-2">
- <div>
- <img style="width:100px;" src="<% x.image_path %>">
- </div>
- </div>
- </div>
- </div>
- </div>
- <div class="row">
- <div class="col-md-12">
- <ul uib-pagination total-items="totalItems" ng-model="currentPage" ng-change="pageChanged()"></ul>
- </div>
- </div>
- </div>
- </div>
- app.controller('DefaultController', ['$scope', 'Upload', '$timeout', '$http', function ($scope, Upload, $timeout , $http) {
- $scope.init = function()
- {
- $scope.getTemplates(1);
- }
- $scope.templates = new Array();
- $scope.totalItems = 0;
- $scope.currentPage = 0;
- $scope.createResult = false;
- $scope.uploadPic = function(file,uploadUrl) {
- file.upload = Upload.upload({
- url: uploadUrl,
- data: { prioritized : $scope.prioritized , file: file},
- });
- file.upload.then(function (response) {
- $timeout(function () {
- $scope.createResult = response.data.status;
- if(response.data.status)
- {
- $scope.clearForm();
- $scope.getTemplates(1);
- }
- else{
- $scope.createResult = false;
- }
- });
- }, function (response) {
- if (response.status > 0)
- $scope.errorMsg = response.status + ': ' + response.data;
- }, function (evt) {
- // Math.min is to fix IE which reports 200% sometimes
- //file.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total));
- });
- }
- $scope.clearForm = function()
- {
- $scope.picFile = null;
- $scope.prioritized = false;
- }
- $scope.pageChanged = function()
- {
- $scope.getTemplates($scope.currentPage);
- }
- $scope.getTemplates = function(page)
- {
- $http.get($scope.getTemplatesUrl+"?page="+page).then(function(response){
- var list_data = response.data.list_data;
- $scope.templates = list_data.data;
- $scope.totalItems = list_data.total;
- $scope.currentPage = page;
- });
- }
- }]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement