Snippets

Foreach Selligent translations namespace copying

Created by Andy Somers

File SP_COPY_LABELS.sql Added

  • Ignore whitespace
  • Hide word diff
+CREATE PROCEDURE SP_COPY_LABELS
+(
+    @NAMESPACESOURCE int,
+    @NAMESPACETARGET int,
+    @FORCEOVERWRITE varchar(1)
+)
+AS
+BEGIN
+
+	DECLARE @LBL_NAME nvarchar(50)
+	DECLARE @LBL_LANGUAGE nvarchar(50)
+	DECLARE @LBL_VALUE nvarchar(max)
+	DECLARE @LBL_MODIFIED_DT datetime
+	DECLARE @LBL_MODIFIED_DT_TARGET datetime
+	DECLARE @MyCursor CURSOR
+	
+	SET @MyCursor = CURSOR FAST_FORWARD 
+	FOR 
+		SELECT NAME, LANGUAGE, VALUE, MODIFIED_DT
+		FROM LABELS WHERE NAMESPACEID=@NAMESPACESOURCE
+	OPEN @MyCursor 
+	FETCH NEXT FROM @MyCursor 
+	INTO @LBL_NAME, @LBL_LANGUAGE, @LBL_VALUE, @LBL_MODIFIED_DT 
+
+	WHILE @@FETCH_STATUS = 0 
+	BEGIN 
+		IF EXISTS (SELECT 1 FROM LABELS
+			WHERE NAME=@LBL_NAME
+				and LANGUAGE=@LBL_LANGUAGE
+				and NAMESPACEID=@NAMESPACETARGET 
+		)
+			BEGIN
+				SELECT @LBL_MODIFIED_DT_TARGET = MODIFIED_DT FROM LABELS WHERE NAME=@LBL_NAME and LANGUAGE=@LBL_LANGUAGE and NAMESPACEID=@NAMESPACETARGET
+				IF @LBL_MODIFIED_DT < @LBL_MODIFIED_DT_TARGET OR @FORCEOVERWRITE='1'
+				BEGIN
+					UPDATE LABELS set VALUE=@LBL_VALUE, MODIFIED_DT=getdate()
+					WHERE NAME=@LBL_NAME
+						and LANGUAGE=@LBL_LANGUAGE
+						and NAMESPACEID=@NAMESPACETARGET 
+				END
+			END
+		ELSE
+			BEGIN
+				INSERT into LABELS ( NAME, LANGUAGE, VALUE, NAMESPACEID, CREATED_DT) Values ( @LBL_NAME, @LBL_LANGUAGE, @LBL_VALUE, @NAMESPACETARGET, getdate() )
+			END
+
+	FETCH NEXT FROM @MyCursor 
+	INTO @LBL_NAME, @LBL_LANGUAGE, @LBL_VALUE, @LBL_MODIFIED_DT
+	END 
+
+	CLOSE @MyCursor 
+	DEALLOCATE @MyCursor 
+
+END

File SP_DROP_LABELS.sql Added

  • Ignore whitespace
  • Hide word diff
+CREATE PROCEDURE SP_DROP_LABELS
+(
+    @NAMESPACETARGET int
+)
+AS
+BEGIN
+
+DELETE FROM LABELS WHERE NAMESPACEID=@NAMESPACETARGET
+
+END

File label list Added

  • Ignore whitespace
  • Hide word diff
+<script src="//code.jquery.com/jquery-2.1.4.min.js"></script>
+<form action="~PROBE(100)~" method="POST" class="js-form">
+<p>&nbsp;</p>
+<p>Default functionality: the value of a label will be copied if values are different and the modified date of the source is before the modified date of the target
+</p>
+<p>
+Source: <select name="NAMESPACESOURCE" id="NAMESPACESOURCE" class="js-namespace-source">
+	<option value="">Select</option>
+	<DIV CONTENTEDITABLE=FALSE ID=MACONTAINER MACONSTRAINT="" MAPARAMETER="NAMESPACES\ALL" MAHIDEDIV="true">
+		<DIV CONTENTEDITABLE=TRUE ID=MAITEM MAHIDEDIV="true"><option value="~ITEM.ID~">~ITEM.ID~. ~ITEM.NAME~</option></DIV>
+	</DIV>
+</select>
+
+Target: <select name="NAMESPACETARGET" id="NAMESPACETARGET" class="js-namespace-target">
+	<option value="">Select</option>
+	<DIV CONTENTEDITABLE=FALSE ID=MACONTAINER MACONSTRAINT="" MAPARAMETER="NAMESPACES\ALL" MAHIDEDIV="true">
+		<DIV CONTENTEDITABLE=TRUE ID=MAITEM MAHIDEDIV="true"><option value="~ITEM.ID~">~ITEM.ID~. ~ITEM.NAME~</option></DIV>
+	</DIV>
+</select>
+</p>
+<p>
+	<input type="checkbox" name="DROPANDREPLACE" class="js-dropandreplace" value="1" /> Drop and replace (beware!!)<br />
+      <input type="checkbox" name="DROPANDREPLACE_UNCHECKED" value="0" style="display:none" checked>
+	<input type="checkbox" name="FORCEOVERWRITE" class="js-forceoverwritechanges" value="1" /> Force overwrite changes - ignores modified date<br />
+      <input type="checkbox" name="FORCEOVERWRITE_UNCHECKED" value="0" style="display:none" checked>
+</p>
+<p>
+	<input type="submit" />
+</p>
+</form>
+
+<script>
+(function() {
+    'use strict';
+
+
+    $('document').ready(function() {
+	$('.js-form').on('submit', function(e) {
+		e.preventDefault();
+		var source = $('.js-namespace-source').val();
+		var target = $('.js-namespace-target').val();
+		if (source !== '' && target !== '' && source !== target) {
+			$('.js-form').eq(0).off('submit').submit();
+		}
+		return false;
+	});
+    });
+
+}());
+</script>