Skip to content
Browse files

Merge branch 'master' of github.com:jrowny/formdrop

  • Loading branch information...
2 parents d939a07 + efedd7f commit 149d75939d55c4f44a7e5acb39ce0bcf3f5bde7e = committed Mar 2, 2012
Showing with 61 additions and 64 deletions.
  1. +22 −24 js/controllers.js
  2. +29 −30 js/services.js
  3. +10 −10 js/util.js
View
46 js/controllers.js
@@ -5,19 +5,19 @@ function AppCtrl($route, $scope, $browser, FormService, ElementService) {
//vars
var elements = $scope.elements = ElementService.query({elementId:'elements'}),
code = $scope.code = "",
- tree = $scope.tree = "";
+ tree = $scope.tree = "";
$scope.$on("render",function(){
- code = ""
- tree = "";
+ code = ""
+ tree = "";
if(FormService.drupalForm.length){
code += _.map(FormService.drupalForm, function(value){return toPHP(value,[]);}).join("\n\n");
- tree += "<ol class=\"sortable\">" + _.map(FormService.drupalForm, function(value){return toEditList(value);}).join("\n") + "</ol>";
+ tree += "<ol class=\"sortable\">" + _.map(FormService.drupalForm, function(value){return toEditList(value);}).join("\n") + "</ol>";
}else{
code = "//Empty form :(";
- tree = "<ul></ul>";
+ tree = "<ul></ul>";
}
- $('#code').html("");
+ $('#code').html("");
$('#code').text("<?php\n\n" + code + "\n\n?>");
$('#tree').html(tree)
$('#tree ol').nestedSortable({
@@ -44,11 +44,11 @@ function AppCtrl($route, $scope, $browser, FormService, ElementService) {
* Remove Form Controller (Confirmation)
*/
function RemoveFormCtrl($scope, $route, $location, $rootScope, FormService){
- $scope.confirmRemove = function(){
- FormService.remove($route.current.params.elementId);
- $rootScope.$broadcast("render");
+ $scope.confirmRemove = function(){
+ FormService.remove($route.current.params.elementId);
+ $rootScope.$broadcast("render");
$location.path("/");
- };
+ };
}
/**
@@ -60,23 +60,21 @@ function ElementFormCtrl(ElementService, FormService, $routeParams, $location, $
var element = $scope.element = {},
mode = $scope.mode = $location.$$path.split("/")[1];
- if(mode == "edit"){
- $scope.form = form = FormService.getById($routeParams.elementId);
- $scope.element = element = form.element;
- }else if(mode == "add"){
- //When adding a new element, initialize the form
- $scope.element = element = ElementService.get({elementId: $routeParams.elementId}, function(element) {
- $scope.form = form = FormService.newForm(element);
- //add default attributes
- for(var i = 0; i < element.attributes.length; i++){
- if(element.attributes[i].typical){
+ if(mode == "edit"){
+ $scope.form = form = FormService.getById($routeParams.elementId);
+ $scope.element = element = form.element;
+ }else if(mode == "add"){
+ //When adding a new element, initialize the form
+ $scope.element = element = ElementService.get({elementId: $routeParams.elementId}, function(element) {
+ $scope.form = form = FormService.newForm(element);
+ //add default attributes
+ for(var i = 0; i < element.attributes.length; i++){
+ if(element.attributes[i].typical){
form.attributes.push({"attribute":element.attributes[i],"value":element.attributes[i].value});
}
}
- });
- }
-
-
+ });
+ }
$scope.addAttribute = function(){
form.attributes.push({"attribute":element.attributes[0],"value":""});
View
59 js/services.js
@@ -9,35 +9,36 @@ angular.module('formDrop.services', [], function($provide) {
return res('data/7/attributes.json', {}, {});
}]);
- /**
- * if Angular's nextUid() was exposed to the API, we'd use that. But since we probably won't
- * have enough form elements for an overrun, I think a simple int counter will do
- */
- var seed = 0;
+ /**
+ * if Angular's nextUid() was exposed to the API, we'd use that. But since we probably won't
+ * have enough form elements for an overrun, I think a simple int counter will do
+ */
+ var seed = 0;
- //FormService provider
- var formServiceProvider = function() {
- this.$get = ['$rootScope', function ($rootScope) {
- var drupalForm = [],
- service = {drupalForm : drupalForm,
- save : function(formElement){
- var toSave = findFormElementById(formElement.id, drupalForm);
- if(toSave){
- toSave = formElement;
- }else{
- drupalForm.push(formElement);
- }
- },
- remove : function(id){
- removeFormElementById(id, drupalForm);
- },
- newForm : function(element){
- seed++;
- return {id:seed, element: element, label: element.id, attributes: [], children: []};
- },
- getById : function(id){
- return findFormElementById(id, drupalForm);
- },};
+ //FormService provider
+ var formServiceProvider = function() {
+ this.$get = ['$rootScope', function ($rootScope) {
+ var drupalForm = [],
+ service = {drupalForm : drupalForm,
+ save : function(formElement){
+ var toSave = findFormElementById(formElement.id, drupalForm);
+ if(toSave){
+ toSave = formElement;
+ }else{
+ drupalForm.push(formElement);
+ }
+ },
+ remove : function(id){
+ removeFormElementById(id, drupalForm);
+ },
+ newForm : function(element){
+ seed++;
+ return {id:seed, element: element, label: element.id, attributes: [], children: []};
+ },
+ getById : function(id){
+ return findFormElementById(id, drupalForm);
+ },
+ };
return service;
}];
}
@@ -77,7 +78,5 @@ angular.module('formDrop.services', [], function($provide) {
//provide a service to store/manage the form
$provide.service('FormService', formServiceProvider);
-
-
});
View
20 js/util.js
@@ -10,14 +10,14 @@ function toPHP(value,parents){
function toEditList(value){
- var html = '<li id="item-' + value.id + '"><div><strong>' + value.label + '</strong> : <em>' + value.element.id + '</em>';
- html += '<div class="btn-group">';
- html += '<a href="#/edit/' + value.id + '" class="btn" title="Edit"><i class="icon-pencil"></i></a>';
- html += '<a href="#/remove/' + value.id + '" class="btn" title="Remove"><i class="icon-trash"></i></a>';
- html += '</div></div>';
- if(value.children.length){
- html += "<ol>" + _.map(value.children, function(childVal){return toEditList(childVal);}).join("\n") + "</ol>";
- }
- html += "</li>";
- return html;
+ var html = '<li id="item-' + value.id + '"><div><strong>' + value.label + '</strong> : <em>' + value.element.id + '</em>';
+ html += '<div class="btn-group">';
+ html += '<a href="#/edit/' + value.id + '" class="btn" title="Edit"><i class="icon-pencil"></i></a>';
+ html += '<a href="#/remove/' + value.id + '" class="btn" title="Remove"><i class="icon-trash"></i></a>';
+ html += '</div></div>';
+ if(value.children.length){
+ html += "<ol>" + _.map(value.children, function(childVal){return toEditList(childVal);}).join("\n") + "</ol>";
+ }
+ html += "</li>";
+ return html;
}

0 comments on commit 149d759

Please sign in to comment.
Something went wrong with that request. Please try again.